本文整理汇总了C#中Scope.ContainsVarInstance方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.ContainsVarInstance方法的具体用法?C# Scope.ContainsVarInstance怎么用?C# Scope.ContainsVarInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.ContainsVarInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckSemantics
public override void CheckSemantics(Scope scope, List<SemanticError> errors)
{
//check the existence and the semantic of the left value.
Identifier.CheckSemantics(scope, errors);
//check the semantick of the expression.
this.Expr.CheckSemantics(scope, errors);
if (Identifier is IdNode)
if (scope.ContainsVarInstance(Identifier.Text) && scope.GetVarInstance(Identifier.Text).ReadOnly)
errors.Add(SemanticError.ReadOnlyAssing(Identifier.Text,this));
if (Expr.ExpressionType.Type == TypesEnumeration.Nil)
{
if (!scope.GetType(Identifier.ExpressionType.Name).Nilable)
errors.Add(SemanticError.InvalidNilAssignation(Identifier.ExpressionType.Name, this));
}
else if (Expr.ExpressionType.Type == TypesEnumeration.Void || scope.GetType(Identifier.ExpressionType.Name).Name != scope.GetType(Expr.ExpressionType.Name).Name)
errors.Add(SemanticError.WrongType(Identifier.ExpressionType.Name, Expr.ExpressionType.Name, this));
}
示例2: CheckSemantics
public override void CheckSemantics(Scope scope, List<SemanticError> errors)
{
Value.CheckSemantics(scope, errors);
if (scope.ContainsVarInstance(Identifier.Text, true) || scope.ContainsRoutine(Identifier.Text, true))
errors.Add(SemanticError.DefinedVariable(Identifier.Text, this));
if (Scope.standard_functions.Contains(Identifier.Text))
errors.Add(SemanticError.HidingAnStandardFunc("Function", Identifier.Text, this));
if (VariableType != null)
{
if (!scope.ContainsType(this.VariableType.Text))
{
errors.Add(SemanticError.TypeNotDefined(this.VariableType.Text, this));
return;
}
//check if the value of the variable has the same type that the defined
else if (Value.ExpressionType.Type == TypesEnumeration.Nil)
{
if (!scope.GetType(VariableType.Text).Nilable)
errors.Add(SemanticError.InvalidNilAssignation(VariableType.Text, this));
}
else if (scope.GetType(this.Value.ExpressionType.Name).Name != scope.GetType(this.VariableType.Text).Name)
errors.Add(SemanticError.WrongType(this.VariableType.Text, this.Value.ExpressionType.Name, this));
}
else
{
switch (Value.ExpressionType.Type)
{
case TypesEnumeration.Nil:
errors.Add(SemanticError.InvalidNilAssignation(Identifier.Text, this));
return;
case TypesEnumeration.Void:
errors.Add(SemanticError.NonValuedAssignation(this));
return;
}
}
Identifier.ExpressionType = VariableType != null ? scope.GetType(VariableType.Text) : Value.ExpressionType;
Identifier.ILName = string.Format("{0}Scope{1}", Identifier.Text, scope.CurrentScope);
Value.ExpressionType.ILName = scope.GetILTypeName(Value.ExpressionType.Name);
}