📄 symbolerrors.cs
字号:
return new SymbolErrorException(
Code.cSymbolNotInType,
idMissingSymbol.Location,
"'" + idMissingSymbol.Text + "' is not defined in the type '" +
t.FullName + "'.");
}
//-----------------------------------------------------------------------------
// The class must be abstract.
//-----------------------------------------------------------------------------
public static SymbolErrorException ClassMustBeAbstract(
ClassDecl node)
{
return new SymbolErrorException(
Code.cClassMustBeAbstract,
node.Location,
"The class '"+node.Symbol.FullName +
"' must be abstract because it contains abstract members.");
}
//-----------------------------------------------------------------------------
// No suitable method to override.
//-----------------------------------------------------------------------------
public static SymbolErrorException NoMethodToOverride(
MethodExpEntry m
)
{
return new SymbolErrorException(
Code.cNoMethodToOverload,
m.Node.Location,
"There is no possible method in '" + m.SymbolClass.Super.FullName +
"' for the method '" + m.PrettyDecoratedName + "' to override."
);
}
//-----------------------------------------------------------------------------
// Can't override anything marked 'final'
//-----------------------------------------------------------------------------
public static SymbolErrorException CantOverrideFinal(
MethodExpEntry m,
MethodExpEntry mSuper
)
{
return new SymbolErrorException(
Code.cCantOverrideFinal,
m.Node.Location,
"'" + m.PrettyDecoratedName + "' can't override the method '" +
mSuper.PrettyDecoratedName + "'."
);
}
//-----------------------------------------------------------------------------
// Can't override a non-virtual method.
//-----------------------------------------------------------------------------
public static SymbolErrorException CantOverrideNonVirtual(
MethodExpEntry m,
MethodExpEntry mSuper)
{
return new SymbolErrorException(
Code.cCantOverrideNonVirtual,
m.Node.Location,
"'" + m.PrettyDecoratedName + "' can't override the non-virtual method '" +
mSuper.PrettyDecoratedName + "'."
);
}
//-----------------------------------------------------------------------------
// Can't change visibility when overriding
//-----------------------------------------------------------------------------
public static SymbolErrorException VisibilityMismatch(
MethodExpEntry m
)
{
return new SymbolErrorException(
Code.cVisibilityMismatch,
m.Node.Location,
"'" +m.PrettyDecoratedName + "' changes visibility when overriding.");
}
//-----------------------------------------------------------------------------
// This construct must be inside a loop
//-----------------------------------------------------------------------------
public static SymbolErrorException MustBeInsideLoop(AST.Node node)
{
string stHint = "?";
if (node is AST.BreakStatement)
{
stHint = "break";
} else if (node is AST.ContinueStatement)
{
stHint = "continue";
} else {
Debug.Assert(false, "Illegal type:"+ node.GetType());
}
return new SymbolErrorException(
Code.cMustBeInsideLoop,
node.Location,
"'" + stHint + "' must occur inside a control block (do, while, for)"
);
}
//-----------------------------------------------------------------------------
// This label is already defined
//-----------------------------------------------------------------------------
public static SymbolErrorException LabelAlreadyDefined(string stName, FileRange lNew, FileRange lOld)
{
return new SymbolErrorException(
Code.cLabelAlreadyDefined,
lNew,
"Label '" + stName + "' is already defined at '"+
lOld + "' in the current scope");
}
//-----------------------------------------------------------------------------
// There is a circular reference.
//-----------------------------------------------------------------------------
public static SymbolErrorException CircularReference(TypeEntry t)
{
return new SymbolErrorException(
Code.cCircularReference,
t.Node.Location,
"Type '" + t.FullName + "' is in a circular reference"
);
}
//-----------------------------------------------------------------------------
// C# only supports single inheritence.
//-----------------------------------------------------------------------------
public static SymbolErrorException OnlySingleInheritence(ClassDecl c)
{
return new SymbolErrorException(
Code.cOnlySingleInheritence,
c.Location,
"Can only derive from a single class (For multiple inheritence, use interfaces)"
);
}
//-----------------------------------------------------------------------------
// A return statement can't have an expression when in a non-void function.
//-----------------------------------------------------------------------------
public static SymbolErrorException NoReturnTypeExpected(AST.ReturnStatement s)
{
return new SymbolErrorException(
Code.cNoReturnTypeExpected,
s.Location,
"Functions with void return type can't return an expression"
);
}
//-----------------------------------------------------------------------------
// The method is unambiguous.
//-----------------------------------------------------------------------------
public static SymbolErrorException AmbiguousMethod(
Identifier idName,
System.Type [] alParamTypes,
string stOverloadList
)
{
string stDecorated = TypeEntry.GetDecoratedParams(idName.Text, alParamTypes);
return new SymbolErrorException(
Code.cAmbiguousMethod,
idName.Location,
"The call to '" + stDecorated + "'is ambiguous between:\n" + stOverloadList
);
}
//-----------------------------------------------------------------------------
// The method is not defined.
//-----------------------------------------------------------------------------
public static SymbolErrorException MethodNotDefined(
FileRange location,
string stFullyQualifiedName
)
{
return new SymbolErrorException(
Code.cMethodNotDefined,
location,
"The method '" + stFullyQualifiedName + "' is not defined."
);
}
//-----------------------------------------------------------------------------
// There is no suitable overload
//-----------------------------------------------------------------------------
public static SymbolErrorException NoAcceptableOverload(
FileRange location,
string stFullyQualifiedName
)
{
return new SymbolErrorException(
Code.cNoAcceptableOverload,
location,
"No acceptable overload for '" + stFullyQualifiedName + "' exists"
);
}
//-----------------------------------------------------------------------------
// The symbol is of the wrong type.
//-----------------------------------------------------------------------------
public static SymbolErrorException BadSymbolType(SymEntry sym, System.Type tExpected, FileRange location)
{
return new SymbolErrorException(
Code.cBadSymbolType,
location,
"Symbol '" + sym.Name + "' must be of type '" + tExpected.ToString() + "', not '" +
sym.GetType().ToString() + "'"
);
}
//-----------------------------------------------------------------------------
// Structs & Interfaces can only derive from interfaces
//-----------------------------------------------------------------------------
public static SymbolErrorException MustDeriveFromInterface(ClassDecl nodeThis, TypeEntry tBase)
{
return new SymbolErrorException(
Code.cMustDeriveFromInterface,
nodeThis.Location,
"'" + tBase.FullName + "' is not an interface and so it can't be in the base-list for '" + nodeThis.Name +"'");
}
//-----------------------------------------------------------------------------
// No events allowed in RHS.
//-----------------------------------------------------------------------------
public static SymbolErrorException NoEventOnRHS(AST.EventExp e)
{
return new SymbolErrorException(
Code.cNoEventOnRHS,
e.Location,
"Event '" + e.Symbol.Name + "' can not appear in a right-hand-side expression.");
}
//-----------------------------------------------------------------------------
// The expression must resolve to a compile time constant.
//-----------------------------------------------------------------------------
public static SymbolErrorException MustBeCompileTimeConstant(Exp e)
{
return new SymbolErrorException(
Code.cMustBeCompileTimeConstant,
e.Location,
"The expression must be a compile time constant.");
}
//-----------------------------------------------------------------------------
// Array init list length must match size
//-----------------------------------------------------------------------------
public static SymbolErrorException NewArrayBoundsMismatch(AST.NewArrayObjExp e)
{
int cList = e.ArrayInit.Length;
return new SymbolErrorException(
Code.cNewArrayBoundsMismatch,
e.Location,
"The length of the array-initializer-list (" + cList + ")does not match the rank.");
}
//-----------------------------------------------------------------------------
// No acceptable indexer (matched by parameter types)
//-----------------------------------------------------------------------------
public static SymbolErrorException NoAcceptableIndexer(FileRange location, System.Type [] alTypes, bool fIsLeft)
{
StringBuilder sb = new StringBuilder();
sb.Append("No acceptable '");
sb.Append(fIsLeft ? "get" : "set");
sb.Append("' indexer has signature: (");
bool fComma = false;
foreach(Type t in alTypes)
{
if (fComma)
sb.Append(",");
sb.Append(t.FullName);
fComma = true;
}
sb.Append(").");
return new SymbolErrorException(
Code.cNoAcceptableIndexer,
location,
sb.ToString());
}
//-----------------------------------------------------------------------------
// When doing 'base.X(.....)', X must not be static.
// If it was, we should have done 'T.X(.....)'
//-----------------------------------------------------------------------------
public static SymbolErrorException BaseAccessCantBeStatic(FileRange location, MethodExpEntry m)
{
return new SymbolErrorException(
Code.cBaseAccessCantBeStatic,
location,
"Can't access static member '"+m.PrettyDecoratedName+"' via a 'base' accessor.");
}
} // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -