Documentation ¶
Overview ¶
Package errcode提供在语义检查完成前的错误处理
标准处理流程 ¶
错误处理上下文 ErrCtx 保存错误处理需要的信息
错误处理围绕这个错误处理上下文进行,处理没有关联的错误推荐使用不同错误处理上下文
报错通过 ErrCtx.Panic 进行
在一个单独的goroutin调用 ErrCtx.Handle 处理一个报错
代码如下: var errctx = NewErrCtx() //创建错误处理上下文 ctx,cancel:=context.WithCancel(context.Background()) defer cancel() //在执行完毕时结束错误处理 go errctx.Handle(ctx,errfn func(ErrInfo){fmt.Println(err.String())},func(){}) //错误处理方式是将报错信息打印 //...词法分析,构建抽象语法树,语义检查,其中包含可能调用 [ErrCtx.Panic]的代码
默认错误上下文 ¶
默认错误上下文 DefaultErrCtx 是由于 ErrCtx 出现晚于 Panic Handle Errbol 而诞生的产物
使用 默认错误上下文 的错误意味着报错和处理报错的状态是全局,不推荐在测试以外的情况使用
Index ¶
- Variables
- func ErrEnumStr(code ...ErrCode) string
- func Errbol() bool
- func Handle(ctx context.Context, errfn func(ErrInfo), retfn func())
- func Panic(file string, line int, addInfo Msg, err ...ErrCode)
- type ErrCode
- type ErrCtx
- type ErrInfo
- type Msg
- type MsgAssignToConst
- type MsgAssignTypeIsNotEqual
- type MsgBracesNoEqual
- type MsgBracketsNoEqual
- type MsgCallTypeIsNotEqual
- type MsgDiffFileHavaDiffPackageDecl
- type MsgExpectedAndFound
- type MsgLabelNoExist
- type MsgNumberOfParameNoMatch
- type MsgNumberOfSemicolons
- type MsgOpexprTypeIsNotEqual
- type MsgPackageNameNoEqualDirName
- type MsgRecursiveTypeErr
- type MsgReturnTypeIsNotEqual
- type MsgSelectorLNoSelectorR
- type MsgSwitchAndCaseTypNoEqual
- type MsgSymbol
- type MsgSymbolRepeat
- type MsgUnexpected
- type MsgUnexpected2
- type MsgUnknownSymbol
Constants ¶
This section is empty.
Variables ¶
var (
Aoldad = "出现在%s的第%d行 和 %s的第%d行" //Appears on line% d of% s and line% d of% s
)
var Debug = false
var (
DefaultErrCtx = NewErrCtx()
)
var (
ErrCodeStrMap = [...]string{}/* 121 elements not displayed */
)
Functions ¶
Types ¶
type ErrCode ¶
type ErrCode int
错误码,指定某一个错误
const ( NoErr ErrCode = iota VARErr FUNCErr OneNoNumber EmptyLPAREN EmptyRPAREN OPbug NameRetain TypeIsNotEqual ASSIGNErr EmptyRbrace UnknownSymbol EmptyLBRACE NoName SymbolUseBeforeDeclaration IfErr NdSotf // Non-declaration statement outside the function ExprNoBool ElseErr AFIOE //Assignment found in operation expression StringNoEnd ForErr MLCNoEnd //multiline comment no end ForInitNoDeclVarStmt //Is not a declaration variable statement ForEndStmt SymbolRepeat UnexpectedComma CallErr InsuParame //Insufficient parameters CallNoFunc //Calling non functions FuncNoRetValue //Function does not return a value BoolOpOnlyCmpOrLogic //Boolean type operations can only be comparative equality, inequality, or logical operations DeclFuncNoInFunc //Cannot declare a function in a function at this time ReturnErr GotoErr NoLabel LabelErr BreakErr ContinueErr MainNoRetValue //The main function does not return a value BreakStmtInForOrSwitch //The break statement should be in the for code block ContinueStmtInFor //The continue statement should be in the for code block ConstErr TManyParame //too many parameters StructErr FieldErr NoIdent //Not an identifier UnknownType NoOSelectorL //Not an optional selector lvalue SelectorLNoSelectorR //The selector left value does not have a selector right value UnexpectedRPAREN MallocReqParame //Malloc requires a parameter ParameOfMallocAType //One parameter of malloc should be a type symbol StringNoSelfOpStmt //String cannot use self operating statements SelfOpStmtErr FirstParameOfPrinfASting //The first parameter of printf should be a string PtrOpOnlyCmp //Pointer type operations can only be comparative equal or unequal UnexpectedNil LeftOrRightValueSelectorEmpty //The left or right value of the selector is empty SelectorLeftAndRightValueMustSymbol //The left and right value of the selector must be a symbol ProhibitCallInitFunc //Prohibit calling init function ProhibitCallMainFunc //Prohibit calling the main function UnexpectedLPAREN PackageDeclMustName //The package declaration statement must include the package name PackageDeclOnlyName //The package declaration should only contain the package name PackageDeclMustFirstLine //The package declaration must appear on the first line DiffFileHavaDiffPackageDecl //Different file declarations have different package declarations SwitchErr CaseErr ExpectColonAtEnd //Expected a colon at the end CaseStmtInSwitch //The case statement should be in the switch DefaultErr ParameDeclHasNoType //Parameter declaration has no type DeclMethodInFunc //Method cannot be declared in a function at this time MethodErr LbraceEndOfLine //Left brace should be at the end of the same line FirstParameTypeOfMethodACustomType //The first parameter type of the method should be a custom type SecondParameOfUnsafeAddAnInt //The second parameter of unsafeAdd should be an integer FirstParameOfUnsafeAddAPtr //The first parameter of unsafeAdd should be a pointer FirstParameOfUnsafeConvertAPtr //The first parameter of unsafeConvert should be a pointer SecondParameOfUnsafeConvertAPtrType //The second parameter of unsafeConvert should be a pointer type FirstParameOfUnsafeSizeAType //The first parameter of unsafeSize should be a type AutoFreeErr ExprForAutoFreeShouldExprInt //The expression for autofree should express integers CannotUseTypeAsRetValue //Cannot use type as return value RecursiveTypeErr //Recursive type error ImportShouldBeOutSideOfTheFunc //Import should be outside of the function ImportPathMustString //The import path must be a string ImportErr CircularImportErr //Circular import error NotAnExportSymbol //Not an export symbol EnumErr EnumValueShouldHaveOneOnEachLine //Enumeration values should have one on each line EnumValueShouldBeASymbol //The enumeration value should be a symbol PackageNameNoEqualDirName //Package name does not equal directory name ParameForMallocSizeMustInt //The parameter for mallocSize must be an integer EmptyEnum // empty enumeration CanOnlyConvertPointerTypeToUnsafePointer //Can only convert pointer type to unsafe__Pointer CanOnlyConvertFloatToInt //Can only convert float to int CanOnlyConvertIntToFloat //Can only convert int to float FieldDupName //Field duplicate name TheNumOfLeftRightBracketsNoMatch //The number of left and right brackets does not match EnumValueDup //Enumeration value duplication IndexExprElemTypeErr //Index expression element type error TypeParameSyntaxErr //Type parameter Syntax error TypeParamrConstraintErr //Type parameter constraint error GenericInstantiationEmpty //The generic instantiation list is empty UnequlaNumOfGen //Unequal number of generics OnlyTypePtrCanDeref //Only type pointers can be dereferenced UnrefNoVarAndConst //Unreferencing non variables and constants AdjacentOp //Adjacent Operators PackageNameCannotBeEqualUnsafe //Package name cannot be equal to unsafe MainPackageMustHaveMainFunc //The main package must have a main function NoMainPackageMustHaveNoMainFunc //Non main packages must have no main function NameCannotStartWithGenerate //The name cannot start with 'generate' EndOfNameCannot_mempool //The end of the name cannot be _mempool RetWithValueInFuncWithoutValue //Returns with a return value in functions without a return value NoType NoConstInit NoBoolExpr NoExpr )
type ErrCtx ¶
type ErrCtx struct {
// contains filtered or unexported fields
}
ErrCtx 错误处理的上下文 保存了错误处理需要的信息
ErrCtx 不能被重用
type ErrInfo ¶
type ErrInfo struct { //附加信息 AddInfo Msg //文件名 File string //错误提示 Message string //行数 Line int // contains filtered or unexported fields }
错误信息
type MsgAssignToConst ¶
type MsgAssignToConst struct {
Name string
}
缩写: Assign values to constants 缩写成 AssignToConst MsgAssignToConst 表示一个对常量赋值错误
func NewMsgAssignToConst ¶
func NewMsgAssignToConst(name string) MsgAssignToConst
创建MsgAssignToConst
type MsgAssignTypeIsNotEqual ¶
type MsgAssignTypeIsNotEqual struct { //目的操作数的类型 DestType string //源操作数的类型 SrcType string // contains filtered or unexported fields }
MsgAssignTypeIsNotEqual 表示一个赋值类型不相等错误
func NewMsgAssignTypeIsNotEqual ¶
func NewMsgAssignTypeIsNotEqual(DestType string, SrcType string) MsgAssignTypeIsNotEqual
创建MsgAssignTypeIsNotEqual
func (MsgAssignTypeIsNotEqual) Is ¶
func (msg MsgAssignTypeIsNotEqual) Is(b Msg) bool
type MsgBracesNoEqual ¶
MsgBracesNoEqual 表示左大括号和右大括号数量不匹配
func NewMsgBracesNoEqual ¶
func NewMsgBracesNoEqual(Left int, Right int) MsgBracesNoEqual
type MsgBracketsNoEqual ¶
MsgBracketsNoEqual 表示左中括号和右中括号数量不匹配
func NewMsgBracketsNoEqual ¶
func NewMsgBracketsNoEqual(Left int, Right int) MsgBracketsNoEqual
type MsgCallTypeIsNotEqual ¶
type MsgCallTypeIsNotEqual struct {
// contains filtered or unexported fields
}
MsgCallTypeIsNotEqual 表示一个函数调用类型不相等错误
func NewMsgCallTypeIsNotEqual ¶
func NewMsgCallTypeIsNotEqual(src1Type string, src2Type string, num int) MsgCallTypeIsNotEqual
创建MsgCallTypeIsNotEqual
type MsgDiffFileHavaDiffPackageDecl ¶
type MsgDiffFileHavaDiffPackageDecl struct {
Decl1, Decl2 string
}
缩写:Different file declarations have different package declarations 缩写成 DiffFileHavaDiffPackageDecl MsgDiffFileHavaDiffPackageDecl 表示一个不同文件声明的包声明不同附加错误
func NewMsgDiffFileHavaDiffPackageDecl ¶
func NewMsgDiffFileHavaDiffPackageDecl(Decl1, Decl2 string) MsgDiffFileHavaDiffPackageDecl
创建MsgDiffFileHavaDiffPackageDecl
func (MsgDiffFileHavaDiffPackageDecl) Msg ¶
func (msg MsgDiffFileHavaDiffPackageDecl) Msg() string
Msg 返回提示信息
type MsgExpectedAndFound ¶
type MsgExpectedAndFound struct {
Expected, Found string
}
MsgExpectedAndFound 表示一个 需要 x 找到 y 的错误
func NewMsgExpectedAndFound ¶
func NewMsgExpectedAndFound(Expected, Found string) MsgExpectedAndFound
type MsgLabelNoExist ¶
type MsgLabelNoExist struct { //不存在的标签名 Label string }
MsgLabelNoExist 表示一个不存在的标签错误 缩写:Label that does not exist 缩写成 LabelNoExist
type MsgNumberOfParameNoMatch ¶
type MsgNumberOfParameNoMatch struct { FuncName string //调用(实际传递的参数)数量 CallerNum int //被调者(函数声明的参数)数量 CalleeNum int }
缩写:Number of parameters does not match 缩写成 NumberOfParameNoMatch MsgNumberOfParameNoMatch 表示一个参数数量不匹配错误
func NewMsgNumberOfParameNoMatch ¶
func NewMsgNumberOfParameNoMatch(CallerNum int, CalleeNum int, FuncName string) MsgNumberOfParameNoMatch
创建MsgNumberOfParameNoMatch
type MsgNumberOfSemicolons ¶
type MsgNumberOfSemicolons struct {
Num int
}
MsgNumberOfSemicolons 表示分号数量错误,目前用于for语句
func NewMsgNumberOfSemicolons ¶
func NewMsgNumberOfSemicolons(Num int) MsgNumberOfSemicolons
type MsgOpexprTypeIsNotEqual ¶
type MsgOpexprTypeIsNotEqual struct {
// contains filtered or unexported fields
}
MsgOpexprTypeIsNotEqual 表示一个运算表达式类型不相等错误
func NewMsgOpexprTypeIsNotEqual ¶
func NewMsgOpexprTypeIsNotEqual(src1Type string, src2Type string) MsgOpexprTypeIsNotEqual
创建MsgOpexprTypeIsNotEqual
type MsgPackageNameNoEqualDirName ¶
MsgPackageNameNoEqualDirName 表示一个包名不等于目录名附加错误
func NewMsgPackageNameNoEqualDirName ¶
func NewMsgPackageNameNoEqualDirName(PackageName string, DirName string) MsgPackageNameNoEqualDirName
创建 MsgPackageNameNoEqualDirName
func (MsgPackageNameNoEqualDirName) Msg ¶
func (msg MsgPackageNameNoEqualDirName) Msg() string
Msg 返回提示信息
type MsgRecursiveTypeErr ¶
type MsgRecursiveTypeErr struct {
Dep []string
}
MsgRecursiveTypeErr 表示一个递归类型附加错误
func NewMsgRecursiveTypeErr ¶
func NewMsgRecursiveTypeErr(finaldep string) MsgRecursiveTypeErr
创建MsgRecursiveTypeErr
type MsgReturnTypeIsNotEqual ¶
MsgreturnTypeIsNotEqual 表示一个返回语句类型不相等错误
func NewMsgReturnTypeIsNotEqual ¶
func NewMsgReturnTypeIsNotEqual(DeclType string, RetType string) MsgReturnTypeIsNotEqual
创建MsgReturnTypeIsNotEqual
type MsgSelectorLNoSelectorR ¶
type MsgSelectorLNoSelectorR struct { LeftValue string RightValue string // contains filtered or unexported fields }
缩写: The selector left value does not have a selector right value 缩写成SelectorLNoSelectorR MsgSelectorLNoSelectorR 代表一个选择器左值没有选择器右值的错误
func NewMsgSelectorLNoSelectorR ¶
func NewMsgSelectorLNoSelectorR(LeftValue string, RightValue string) MsgSelectorLNoSelectorR
func (MsgSelectorLNoSelectorR) Is ¶
func (msg MsgSelectorLNoSelectorR) Is(eq Msg) bool
type MsgSwitchAndCaseTypNoEqual ¶
type MsgSwitchAndCaseTypNoEqual struct {
SwitchTyp, CaseTyp string
}
缩写:Switch and case types are not equal 缩写成 SwitchAndCaseTypNoEqual MsgSwitchAndCaseTypNoEqual 表示一个switch和case类型不相等
func NewMsgSwitchAndCaseTypNoEqual ¶
func NewMsgSwitchAndCaseTypNoEqual(SwitchTyp, CaseTyp string) MsgSwitchAndCaseTypNoEqual
创建MsgSwitchAndCaseTypNoEqual
func (MsgSwitchAndCaseTypNoEqual) Msg ¶
func (msg MsgSwitchAndCaseTypNoEqual) Msg() string
Msg 返回提示信息
type MsgSymbolRepeat ¶
type MsgSymbolRepeat struct { //未知的符号名 Name string FileName1, FileName2 string LineNum1, LineNum2 int }
MsgSymbolRepeat 表示一个重复的符号名
func NewMsgSymbolRepeat ¶
func NewMsgSymbolRepeat(Name string, FileName1, FileName2 string, LineNum1, LineNum2 int) MsgSymbolRepeat
创建MsgSymbolRepeat
type MsgUnexpected ¶
type MsgUnexpected struct {
Str string
}
MsgUnexpected 表示一个意外的字符串
func NewMsgUnexpected ¶
func NewMsgUnexpected(str string) MsgUnexpected
type MsgUnexpected2 ¶
MsgUnexpected2 表示一个意外的两个字符串
func NewMsgUnexpected2 ¶
func NewMsgUnexpected2(str1, str2 string) MsgUnexpected2
type MsgUnknownSymbol ¶
type MsgUnknownSymbol struct { //未知的符号名 Name string // contains filtered or unexported fields }
MsgUnknownSymbol 表示一个未知的符号错误
func NewMsgUnknownSymbol ¶
func NewMsgUnknownSymbol(Name string) MsgUnknownSymbol
创建MsgUnknownSymbol
func (MsgUnknownSymbol) Is ¶
func (msg MsgUnknownSymbol) Is(eq Msg) bool