当前位置: 首页>>代码示例>>C#>>正文


C# Scope.GetType方法代码示例

本文整理汇总了C#中Scope.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.GetType方法的具体用法?C# Scope.GetType怎么用?C# Scope.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scope的用法示例。


在下文中一共展示了Scope.GetType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:29,代码来源:RelationalNode.cs

示例2: 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));
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:18,代码来源:AssignNode.cs

示例3: CheckSemantics

        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            CheckIdentifier(scope, errors);
            if (scope.GetType(Identifier.Text).Type != TypesEnumeration.Array)
                errors.Add(SemanticError.WrongType(Identifier.Text, "Array", this));

            Identifier.ILName = string.Format("{0}Scope{1}", Identifier.Text, scope.CurrentScope);
            DefinedType.ILName = scope.GetILTypeName(DefinedType.Text);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:9,代码来源:ArrayDeclarationNode.cs

示例4: 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);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:42,代码来源:VariableDeclarationNode.cs

示例5: CheckSemantics

        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            RecordIdentifier.ILName = scope.GetILTypeName(RecordIdentifier.Text);

            var typeInfo = scope.GetType(this.RecordIdentifier.Text);
            //check if the record type is defined
            if (typeInfo == null || typeInfo.Type != TypesEnumeration.Record || scope.GetType(typeInfo.Name).Name != scope.GetType(this.RecordIdentifier.Text).Name)
            {
                errors.Add(SemanticError.TypeNotDefined(this.RecordIdentifier.Text, this));
                return;
            }

            var recordInfo = (RecordInfo) typeInfo;
            //the count of parameters used to define and to initialice a record must match.
            if (recordInfo.FieldsCount != this.FieldInitialicer.Count)
            {
                errors.Add(SemanticError.WrongParameterNumber("Record", this.RecordIdentifier.Text, recordInfo.FieldsCount, this.FieldInitialicer.Count, this));
                return;
            }

            for (int i = 0; i < recordInfo.FieldsCount; i++)
            {
                var assignNode = this.FieldInitialicer[i];
                assignNode.CheckSemantics(scope, errors);

                //check the field name and order
                if (assignNode.Field.Text != recordInfo.Parameters[i].Identifier)
                    errors.Add(SemanticError.WrongFieldInit(this.RecordIdentifier.Text, recordInfo.Parameters[i].Identifier, this));
                //check the field type
                if (assignNode.Value.ExpressionType.Type == TypesEnumeration.Nil)
                {
                    if (!scope.GetType(recordInfo.Parameters[i].Type).Nilable)
                        errors.Add(SemanticError.InvalidNilAssignation(recordInfo.Parameters[i].Identifier, this));
                }
                else if (scope.GetType(assignNode.Value.ExpressionType.Name).Name != scope.GetType(recordInfo.Parameters[i].Type).Name)
                    errors.Add(SemanticError.WrongType(assignNode.Value.ExpressionType.Name, recordInfo.Parameters[i].Type, this));

                FieldInitialicer[i].ILName = RecordIdentifier.ILName + string.Format(".{0}", assignNode.Field.Text);
            }
            ExpressionType = recordInfo;
            ExpressionType.ILName = scope.GetILTypeName(ExpressionType.Name);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:42,代码来源:InstanceRecordNode.cs

示例6: CheckSemantics

        public void CheckSemantics(string identifier, Scope scope, List<SemanticError> errors)
        {
            NestedNode curreNode = this;
            do
            {
                //check the field access
                var typeInfo = scope.GetType(identifier);
                if (curreNode is FieldNestedNode)
                {
                    //check if the type is record
                    if (typeInfo.Type != TypesEnumeration.Record)
                    {
                        errors.Add(SemanticError.WrongType("Record", typeInfo.Type.ToString(), this));
                        return;
                    }
                    var recordInfo = (RecordInfo)typeInfo;
                    var fieldNested  = (FieldNestedNode) curreNode;

                    var currentField = recordInfo.Parameters.FirstOrDefault(x => x.Identifier == fieldNested.FieldIdentifier.Text);
                    if (currentField == null)
                        errors.Add(SemanticError.InvalidFieldAccess(identifier,
                                                                    fieldNested.FieldIdentifier.Text, this));
                    else
                    {
                        fieldNested.FieldIdentifier.ILName = scope.GetILTypeName(identifier) + "." + fieldNested.FieldIdentifier.Text;
                        identifier = currentField.Type;
                    }
                }
                else
                {
                    //check if the type is an array
                    if (typeInfo.Type != TypesEnumeration.Array)
                    {
                        errors.Add(SemanticError.WrongType("Array", typeInfo.Type.ToString(), this));
                        return;
                    }
                    var arrayInfo = (ArrayInfo) typeInfo;
                    var arrayIndex = (IndexNestedNode) curreNode;
                    arrayIndex.CheckSemantics(scope, errors);
                    if (((IndexNestedNode)curreNode).Index.ExpressionType.Type != TypesEnumeration.Integer)
                        errors.Add(SemanticError.WrongType(((IndexNestedNode)curreNode).Index.ExpressionType.Name,"int",this));
                    else
                    {
                        identifier = arrayInfo.ItemsType;
                        //arrayIndex.Index.ILName = scope.GetILTypeName(identifier);
                    }

                    curreNode.ILName = scope.GetILTypeName(identifier);
                    //curreNode.ILName = scope.GetILTypeName(identifier) + "." + fieldNested.FieldIdentifier.Text;
                }
                curreNode = curreNode.NextNested;
            } while (curreNode != null);
            ExpressionType = scope.GetType(identifier);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:54,代码来源:NestedNode.cs

示例7: CheckSemantics

 public override void CheckSemantics(Scope scope, List<SemanticError> errors)
 {
     var varInfo = scope.GetVarInstance(Text);
     if (varInfo == null)
         errors.Add(SemanticError.UndefinedVariableUsed(Text, this));
     else
     {
         ExpressionType = scope.GetType(varInfo.VariableType);
         VariableILName = scope.GetILVarNames(Text);
         ILName = VariableILName;
     }
 }
开发者ID:hansel0691,项目名称:Tiger,代码行数:12,代码来源:IdNode.cs

示例8: 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);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:24,代码来源:FunctionDeclarationNode.cs

示例9: CheckSemantics

        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            //Verify if the array exist
            var varInfo = scope.GetVarInstance(this.ArrayIdentifier.Text);
            if (varInfo == null)
            {
                errors.Add(SemanticError.UndefinedVariableUsed(this.ArrayIdentifier.Text, this));
                return;
            }
            this.NextNested.CheckSemantics(varInfo.VariableType, scope, errors);
            ExpressionType = this.NextNested.ExpressionType;
            ArrayIdentifier.ILName = scope.GetILVarNames(ArrayIdentifier.Text);
            var arrayInfo = (ArrayInfo) scope.GetType(varInfo.VariableType);

            NextNested.Index.ILName = scope.GetILTypeName(arrayInfo.ItemsType);
            ILName = scope.GetILVarNames(ArrayIdentifier.Text);
            ExpressionType.ILName = scope.GetILTypeName(ExpressionType.Name);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:18,代码来源:ArrayItemNode.cs

示例10: CheckSemantics

        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            this.Length.CheckSemantics(scope, errors);
            this.DefaultValue.CheckSemantics(scope, errors);

            //check if the array identifier is defined
            var typeInfo = scope.GetType(this.ArrayIdentifier.Text);
            if (typeInfo == null)
            {
                errors.Add(SemanticError.TypeNotDefined(this.ArrayIdentifier.Text, this));
                return;
            }
            /*if (scope.GetType(typeInfo.Name).Name != scope.GetType(ArrayIdentifier.Text).Name)
            {
                errors.Add(SemanticError.WrongType(ExpressionType.Name, typeInfo.Name, this));
                return;
            }*/
            if (typeInfo.Type != TypesEnumeration.Array)
            {
                errors.Add(SemanticError.WrongType("Array", typeInfo.Name, this));
                return;
            }

            var arrayInfo = (ArrayInfo) typeInfo;
            //check if lenght is int
            if (this.Length.ExpressionType.Type != TypesEnumeration.Integer)
                errors.Add(SemanticError.InvalidNumber("The length", this));
            //default value must be the same type of the defined
            if (DefaultValue.ExpressionType.Type == TypesEnumeration.Nil)
            {
                if (!scope.GetType(arrayInfo.ItemsType).Nilable)
                    errors.Add(SemanticError.InvalidNilAssignation(arrayInfo.ItemsType, this));
            }
            else if (arrayInfo.ItemsType != scope.GetType(DefaultValue.ExpressionType.Name).Name)
                errors.Add(SemanticError.WrongType(arrayInfo.ItemsType, this.DefaultValue.ExpressionType.Name, this));

            this.ExpressionType = scope.GetType(ArrayIdentifier.Text);
            ArrayIdentifier.ILName = string.Format("{0}Scope{1}", ArrayIdentifier, scope.CurrentScope);
            DefaultValue.ILName = scope.GetILTypeName(arrayInfo.ItemsType);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:40,代码来源:InstanceTypeArrayNode.cs

示例11: CheckSemantics

        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            if (Arguments != null)
                Arguments.CheckSemantics(scope, errors);
            var functionInfo = scope.GetRoutine(FunctionId.Text);
            //check if the function exist
            if (functionInfo == null)
            {
                errors.Add(SemanticError.FunctionDoesNotExist(FunctionId.Text, this));
                return;
            }

            if (functionInfo.ParameterCount != 0 && Arguments == null)
            {
                errors.Add(SemanticError.WrongParameterNumber("Function", FunctionId.Text, functionInfo.ParameterCount, 0, this));
                return;
            }
            if (Arguments != null && Arguments.Count != functionInfo.ParameterCount)
            {
                errors.Add(SemanticError.WrongParameterNumber("Function", FunctionId.Text, functionInfo.ParameterCount, this.Arguments.Count, this));
                return;
            }

            //var newScope = new Scope(scope);
            for (int i = 0; Arguments != null && i < Arguments.Count; i++)
            {
                //check the type of the parameters passed
                var expressionType = Arguments[i].ExpressionType;

                if (expressionType.Type == TypesEnumeration.Nil)
                {
                    if (!scope.GetType(functionInfo.ParametersType[i].Type).Nilable)
                        errors.Add(SemanticError.InvalidNilAssignation(functionInfo.ParametersType[i].Type, this));
                }
                else if (expressionType.Type == TypesEnumeration.Void ||  scope.GetType(expressionType.Name).Name != functionInfo.ParametersType[i].Type)
                    errors.Add(SemanticError.WrongType(functionInfo.ParametersType[i].Type, expressionType.Name, this));
            }
            ExpressionType = functionInfo.ReturnType != "void" ? scope.GetType(functionInfo.ReturnType) : TypeInfo.GenerateVoidInfo();
            ILName = scope.GetILRoutineName(FunctionId.Text);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:40,代码来源:CallRoutineNode.cs

示例12: GetScopeHash

        /// <summary>
        /// Get the hash of a scope
        /// </summary>
        /// <param name="scope"></param>
        /// <returns></returns>
        private static string GetScopeHash(Scope scope)
        {
            // Get scope name
            string scopeName = Enum.GetName(scope.GetType(), scope);

            switch (scope)
            {
                case Scope.Page:
                    scopeName = HttpContext.Current.Request.Url.AbsoluteUri;
                    if (HttpContext.Current.Request.Url.Query != string.Empty)
                    {
                        scopeName = scopeName.Replace(
                           HttpContext.Current.Request.Url.Query, "");
                    }
                    break;
                case Scope.PageAndQuery:
                    scopeName = HttpUtility.UrlDecode(
                       HttpContext.Current.Request.Url.AbsoluteUri);
                    break;
            }

            return GetHash(scopeName);
        }
开发者ID:mrG7,项目名称:PTS,代码行数:28,代码来源:SessionHelper.cs


注:本文中的Scope.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。