本文整理汇总了C#中Scope.ContainsType方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.ContainsType方法的具体用法?C# Scope.ContainsType怎么用?C# Scope.ContainsType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.ContainsType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckSemantics
public override void CheckSemantics(Scope scope, List<SemanticError> errors)
{
LeftOperand.CheckSemantics(scope, errors);
RightOperand.CheckSemantics(scope, errors);
if (LeftOperand.ExpressionType.Type == TypesEnumeration.Void || RightOperand.ExpressionType.Type == TypesEnumeration.Void)
{
errors.Add(SemanticError.InvalidUseOfOperator(this));
return;
}
if (!scope.ContainsType(RightOperand.ExpressionType.Name))
errors.Add(SemanticError.TypeNotDefined(RightOperand.ExpressionType.Name, this));
if (!scope.ContainsType(LeftOperand.ExpressionType.Name))
errors.Add(SemanticError.TypeNotDefined(LeftOperand.ExpressionType.Name, this));
if (LeftOperand.ExpressionType.Type == TypesEnumeration.Nil )
{
if (!scope.GetType(RightOperand.ExpressionType.Name).Nilable)
errors.Add(SemanticError.InvalidNilAssignation(RightOperand.ExpressionType.Name, this));
}
else if (RightOperand.ExpressionType.Type == TypesEnumeration.Nil)
{
if (!scope.GetType(LeftOperand.ExpressionType.Name).Nilable)
errors.Add(SemanticError.InvalidNilAssignation(LeftOperand.ExpressionType.Name, this));
}
else if (LeftOperand.ExpressionType.Name != RightOperand.ExpressionType.Name )
errors.Add(SemanticError.WrongType(LeftOperand.ExpressionType.Name, RightOperand.ExpressionType.Name, this));
}
示例2: CheckSemantics
public override void CheckSemantics(Scope scope, List<SemanticError> errors)
{
var newScope = new Scope(scope);
DeclarationBlock.CheckSemantics(newScope, errors);
if (InstructionsBlock != null)
InstructionsBlock.CheckSemantics(newScope, errors);
//check the visibility of the returned type.
ExpressionType = InstructionsBlock == null ? TypeInfo.GenerateVoidInfo() : this.InstructionsBlock.ExpressionType;
if (ExpressionType != null && ExpressionType.Type != TypesEnumeration.Void && !scope.ContainsType(ExpressionType.Name))
errors.Add(SemanticError.TypeNotVisible(ExpressionType.Name, this));
ExpressionType.ILName = scope.GetILTypeName(ExpressionType.Name);
}
示例3: 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);
}
示例4: CheckSemantics
public override void CheckSemantics(Scope scope, List<SemanticError> errors)
{
this.LowerValue.CheckSemantics(scope, errors);
this.HighestValue.CheckSemantics(scope, errors);
if (scope.ContainsType(IteratorName.Text, true))
errors.Add(SemanticError.DefinedVariable(IteratorName.Text, this));
if (this.LowerValue.ExpressionType.Type != TypesEnumeration.Integer)
errors.Add(SemanticError.InvalidForExpression("lower", this));
if (this.HighestValue.ExpressionType.Type != TypesEnumeration.Integer)
errors.Add(SemanticError.InvalidForExpression("upper", this));
var newScope = new Scope(scope);
newScope.AddVar(this.IteratorName.Text, new VariableInfo(this.IteratorName.Text, "int"){ReadOnly = true});
this.Loop.CheckSemantics(newScope, errors);
//loop may not return a value
if (Loop.ExpressionType.Type != TypesEnumeration.Void)
errors.Add(SemanticError.DontReturnExpression("For body", this));
IteratorName.ILName = newScope.GetILVarNames(IteratorName.Text);
}
示例5: CheckSemantics
public override void CheckSemantics(Scope scope, List<SemanticError> errors)
{
CheckFunctionId(scope,errors);
//check the return type is defined already
if (!scope.ContainsType(ReturnType.Text))
{
errors.Add(SemanticError.TypeNotDefined(ReturnType.Text, this));
return;
}
var newScope = CreateFunctionScope(scope, errors);
Body.CheckSemantics(newScope, errors);
if (Body.ExpressionType.Type == TypesEnumeration.Nil)
{
if (!scope.GetType(ReturnType.Text).Nilable)
errors.Add(SemanticError.InvalidNilAssignation(ReturnType.Text,this));
}
else if (Body.ExpressionType.Name != scope.GetType(ReturnType.Text).Name)
errors.Add(SemanticError.WrongType(ReturnType.Text, Body.ExpressionType.Name, this));
ReturnType.ILName = ReturnType != null ? scope.GetILTypeName(ReturnType.Text) : "voidScope0";
Identifier.ILName = string.Format("{0}Scope{1}", Identifier, scope.CurrentScope);
}