Beispiel #1
0
        void createForeachSymbols(AnalyStmtContext context, SymbolTable symbols, int foreachIndex)
        {
            var listSymbolName    = "@everyone_list_" + foreachIndex;
            var count_symbol_name = "@everyone_count_" + foreachIndex;
            var indexName         = "@everyone_index_" + foreachIndex;
            var elementName       = "@everyone_element_" + foreachIndex;

            listSymbol = new SymbolVar(listSymbolName, ToExp.ListExp.RetType);
            listSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(listSymbol.SymbolName);
            symbols.Add(listSymbol);

            Type[] genericTypes = GenericUtil.GetInstanceGenriceType(ToExp.ListExp.RetType, typeof(列表 <>));
            Type   ElementType  = genericTypes[0];

            elementSymbol = new SymbolVar(elementName, ElementType);
            elementSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(elementName);
            elementSymbol.IsInBlock      = true;
            symbols.Add(elementSymbol);

            countSymbol = new SymbolVar(count_symbol_name, typeof(int));
            countSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(count_symbol_name);
            countSymbol.IsInBlock      = true;
            symbols.Add(countSymbol);

            indexSymbol = new SymbolVar(indexName, typeof(int));
            indexSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(indexName);
            indexSymbol.IsInBlock      = true;
            symbols.Add(indexSymbol);
        }
Beispiel #2
0
        public override void Analy(AnalyStmtContext context)
        {
            base.Analy(context);

            foreach (var stmt in Body)
            {
                stmt.Method = this.Method;
                stmt.Analy(context);
            }
            //处理catch
            List <int> catchIndex = new List <int>();

            for (int i = 0; i < Body.Count; i++)
            {
                if (Body[i] is CatchStmt)
                {
                    catchIndex.Add(i);
                }
            }

            if (catchIndex.Count > 0)
            {
                List <Stmt> Body2 = new List <Stmt>();
                catchIndex.Insert(0, -1);
                for (int i = 0; i < catchIndex.Count - 1; i++)
                {
                    Body2.Add(new TryStmt());
                    List <Stmt> subList = ListHelper.SubList <Stmt>(Body, catchIndex[i] + 1, catchIndex[i + 1]);
                    Body2.AddRange(subList);
                }
                List <Stmt> subList2 = ListHelper.SubList <Stmt>(Body, ListHelper.Last(catchIndex) + 1, Body.Count);
                Body2.AddRange(subList2);
                Body = Body2;
            }
        }
Beispiel #3
0
 public override void Analy(AnalyStmtContext context)
 {
     base.Analy(context);
     resultExp = AnalyExp(CallExpr);
     if (resultExp == null)
     {
         TrueAnalyed = false;
     }
 }
Beispiel #4
0
        void createContext(AnalyExpContext context)
        {
            string className = context.StmtContext.MethodContext.ClassContext.CreateNestedClassName();

            NestedClassContext             = context.StmtContext.MethodContext.ClassContext.CreateNested(className);
            NestedClassContext.ClassSymbol = new SymbolDefClass(context.StmtContext.MethodContext.ClassContext.ClassSymbol, className);
            NestedMethodContext            = new MethodContext(NestedClassContext, "NestedMethod");
            NestedMethodContext.EmitContext.SetBuilder(NestedClassContext.EmitContext.CurrentTypeBuilder.DefineMethod("$$CALL", MethodAttributes.Public, RetType, new Type[] { }));
            nestedStmtContext    = new AnalyStmtContext(NestedMethodContext, "NestedStmt");
            nestedExpContext     = new AnalyExpContext(nestedStmtContext);
            this.AnalyExpContext = nestedExpContext;
        }
Beispiel #5
0
 public override void Analy(AnalyStmtContext context)
 {
     base.Analy(context);
     Condition = AnalyExp(Condition);
     if (Condition == null)
     {
         TrueAnalyed = false;
     }
     else if (Condition.RetType == null || Condition.RetType != logicType)
     {
         error(Condition.Postion, "如果语句的条件表达式不是判断表达式");
     }
     analySubStmt(Body);
 }
Beispiel #6
0
        public void AnalyBody(ClassContext classContext)
        {
            if (ValueExp != null)
            {
                MethodContext methodContext = new MethodContext(ClassContext, PropertyName);
                var           symbols       = ClassContext.Symbols;

                AnalyStmtContext stmtContext = new AnalyStmtContext(methodContext, PropertyName);
                AnalyExpContext  expContext  = new AnalyExpContext(stmtContext);
                ValueExp = ValueExp.Analy(expContext);

                if (ValueExp == null)
                {
                    return;
                }
                if (!ReflectionUtil.IsExtends(ValueExp.RetType, PropertyType))
                {
                    error("属性值的类型不正确");
                }
            }
            else
            {
                if (PropertyType.IsValueType)
                {
                    newCode = 4;
                }
                else
                {
                    List <TKTProcArg> args = new List <TKTProcArg>();
                    ProcDesc = new TKTProcDesc();
                    ProcDesc.Add(PropertyGcl.ShowName);
                    ProcDesc.Add(args);
                    TKTProcDesc newProcDesc = searchNewProc(classContext, ProcDesc);
                    if (newProcDesc != null)
                    {
                        newCode = 3;
                    }
                    else
                    {
                        ConstructorDesc = new TKTConstructorDesc(args);
                        TKTConstructorDesc realDesc = PropertyGcl.SearchConstructor(ConstructorDesc);
                        if (realDesc != null)
                        {
                            ConstructorDesc.Constructor = realDesc.Constructor;
                            newCode = 2;
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public override void Analy(AnalyStmtContext context)
        {
            base.Analy(context);
            var symbols      = this.AnalyStmtContext.Symbols;
            int foreachIndex = context.MethodContext.CreateForeachIndex();
            var propertyName = "Item";
            var subjType     = ToExp.ListExp.RetType;

            ExProperty = GclUtil.SearchExProperty(propertyName, subjType);//subjType.GetExProperty(propertyName);
            PropertyInfo countProperty = subjType.GetProperty("Count");

            getCountMethod = countProperty.GetGetMethod();
            createForeachSymbols(context, symbols, foreachIndex);
            setMethod = ExProperty.Property.GetSetMethod();
        }
Beispiel #8
0
        public override void Analy(AnalyStmtContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyStmtContext.Symbols;

            foreach (var elseif in Parts)
            {
                analySubStmt(elseif);
            }

            if (ElsePart != null)
            {
                ElsePart.Analy(this.AnalyStmtContext);
            }
        }
Beispiel #9
0
        public override void Analy(AnalyStmtContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyStmtContext.Symbols;

            exTypeName = ExceptionTypeToken.GetText();
            exName     = ExceptionNameToken.GetText();
            exType     = context.MethodContext.ClassContext.SearchType(exTypeName).ForType;
            if (exType == null)
            {
                errorf(ExceptionTypeToken.Postion, "类型'{0}'不存在", exTypeName);
            }
            var exSymbol2 = symbols.Get(exName);

            if (exSymbol2 == null)
            {
                exSymbol = new SymbolVar(exName, exType);
                exSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(exName);
            }
            else
            {
                if (exSymbol2 is SymbolVar)
                {
                    exSymbol = exSymbol2 as SymbolVar;
                    if (exSymbol.DimType != exType)
                    {
                        errorf(ExceptionNameToken.Postion, "变量'{0}'的类型与异常的类型不一致", exName);
                    }
                }
                else
                {
                    errorf(ExceptionNameToken.Postion, "变量名称'{0}'已经使用过", exName);
                }
            }
            symbols.Add(exSymbol);
            analySubStmt(CatchBody);
        }
Beispiel #10
0
        public override void Analy(AnalyStmtContext context)
        {
            //base.LoadRefTypes(context);
            int foreachIndex = context.MethodContext.CreateForeachIndex();

            if (ListExp == null)
            {
                error("'循环每一个语句'不存在要循环的列表");
            }
            if (ElementToken == null)
            {
                error("'循环每一个语句'不存在成员名称");
            }
            if (ListExp == null || ElementToken == null)
            {
                return;
            }

            this.AnalyStmtContext = context;
            var symbols = context.Symbols;

            ListExp = AnalyExp(ListExp);

            if (ListExp == null)
            {
                TrueAnalyed = false;
                return;
            }
            if (ListExp.RetType == null)
            {
                TrueAnalyed = false;
                return;
            }
            else if (!canForeach(ListExp.RetType))
            {
                error(ListExp.Postion, "该结果不能用作循环每一个");
                return;
            }

            if (ReflectionUtil.IsExtends(ListExp.RetType, typeof(列表 <>)))
            {
                startIndex    = 1;
                compareMethod = typeof(Calculater).GetMethod("LEInt", new Type[] { typeof(int), typeof(int) });
            }
            else
            {
                startIndex    = 0;
                compareMethod = typeof(Calculater).GetMethod("LTInt", new Type[] { typeof(int), typeof(int) });
            }

            //PropertyInfo countProperty = ListExp.RetType.GetProperty("Count");
            ExPropertyInfo countProperty = GclUtil.SearchExProperty("Count", ListExp.RetType);

            getCountMethod = new ExMethodInfo(countProperty.Property.GetGetMethod(), countProperty.IsSelf);
            //PropertyInfo itemProperty = ListExp.RetType.GetProperty("Item");
            ExPropertyInfo itemProperty = GclUtil.SearchExProperty("Item", ListExp.RetType);

            diMethod = new ExMethodInfo(itemProperty.Property.GetGetMethod(), itemProperty.IsSelf);

            elementName = ElementToken.GetText();

            if (IndexToken != null)
            {
                indexName = IndexToken.GetText();
            }
            else
            {
                indexName = "$$$foreach_" + foreachIndex + "_index";
            }
            createForeachSymbols(context, symbols, foreachIndex, ListExp.RetType);
            analySubStmt(Body);
        }
Beispiel #11
0
        void createForeachSymbols(AnalyStmtContext context, SymbolTable symbols, int foreachIndex, Type listType)
        {
            var listSymbolName = "$$$foreach_" + foreachIndex + "_list";
            var symbol         = symbols.Get(listSymbolName);

            if (symbol == null)
            {
                listSymbol = new SymbolVar(listSymbolName, listType);
                listSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(listSymbol.SymbolName);
                symbols.Add(listSymbol);
            }
            else
            {
                listSymbol = symbol as SymbolVar;
                if (listSymbol == null)
                {
                    errorf("'{0}'不是变量", listSymbolName);
                }
                else
                {
                    if (listSymbol.DimType != ListExp.RetType)
                    {
                        errorf("'{0}'类型不一致", listSymbolName);
                    }
                }
            }

            Type[] genericTypes = GenericUtil.GetInstanceGenriceType(listType, typeof(列表 <>));
            if (genericTypes.Length == 0)
            {
                genericTypes = GenericUtil.GetInstanceGenriceType(listType, typeof(IList <>));
            }

            Type ElementType = genericTypes[0];

            symbol = symbols.Get(elementName);
            if (symbol == null)
            {
                elementSymbol = new SymbolVar(elementName, ElementType);
                elementSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(elementName);
                elementSymbol.IsInBlock      = true;
                symbols.Add(elementSymbol);
            }
            else
            {
                elementSymbol = symbol as SymbolVar;
                if (elementSymbol == null)
                {
                    errorf(ElementToken.Postion, "'{0}'不是变量", elementName);
                }
                else
                {
                    if (elementSymbol.DimType != ElementType)
                    {
                        errorf(ElementToken.Postion, "'{0}'类型不一致", listSymbolName);
                    }
                }
            }

            symbol = symbols.Get(indexName);
            if (symbol == null)
            {
                indexSymbol = new SymbolVar(indexName, typeof(int));
                indexSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(indexName);
                indexSymbol.IsInBlock      = true;
                symbols.Add(indexSymbol);
            }
            else
            {
                indexSymbol = symbol as SymbolVar;
                if (elementSymbol == null)
                {
                    errorf("'{0}'不是变量", indexName);
                }
                else
                {
                    if (elementSymbol.DimType != typeof(int))
                    {
                        errorf("'{0}'不是整数类型", indexName);
                    }
                }
            }

            //int foreachIndex = context.MethodContext.CreateLocalVarIndex("$$$foreach_count");
            var count_symbol_name = "$$$foreach_" + foreachIndex + "_count";

            countSymbol = new SymbolVar(count_symbol_name, typeof(int));
            countSymbol.LoacalVarIndex = context.MethodContext.CreateLocalVarIndex(count_symbol_name);
            countSymbol.IsInBlock      = true;
            symbols.Add(countSymbol);
        }
Beispiel #12
0
 public override void Analy(AnalyStmtContext context)
 {
     //base.LoadRefTypes(context);
     //var symbols = this.AnalyStmtContext.Symbols;
 }
Beispiel #13
0
        public void Analy(MethodContext methodContext)
        {
            var stmtContext = new AnalyStmtContext(methodContext, "BlockStmt");

            Analy(stmtContext);
        }
Beispiel #14
0
 public virtual void Analy(AnalyStmtContext context)
 {
     this.AnalyStmtContext = context;
 }
Beispiel #15
0
        public override void Analy(AnalyStmtContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyStmtContext.Symbols;

            RightValueExp.IsAssignedValue = true;
            LeftToExp.IsAssignedBy        = true;
            RightValueExp = AnalyExp(RightValueExp);
            LeftToExp     = AnalyExp(LeftToExp);

            if (LeftToExp == null || !LeftToExp.TrueAnalyed || RightValueExp == null || !RightValueExp.TrueAnalyed)
            {
                TrueAnalyed = false;
                return;
            }
            else
            {
                RightValueExp.RequireType = LeftToExp.RetType;
            }

            if (LeftToExp is VarExp)
            {
                var        identExpr = LeftToExp as VarExp;
                string     idname    = identExpr.VarName;
                SymbolInfo symbol    = identExpr.VarSymbol;
                if (symbol != null)
                {
                    if (symbol is InstanceSymbol)
                    {
                        InstanceSymbol varSymbol = (symbol as InstanceSymbol);
                        if (varSymbol.DimType == null)
                        {
                            varSymbol.DimType    = RightValueExp.RetType;
                            varSymbol.IsAssigned = true;
                        }
                    }
                }
                else
                {
                    throw new CompileException(idname + "没有分析出正确类型");
                }
            }
            if (!(LeftToExp is IGenerateSet))
            {
                error("不能赋值");
            }
            else
            {
                var gs = (LeftToExp as IGenerateSet);
                if (gs.CanWrite == false)
                {
                    errorf("'{0}'是只读的,不能赋值", gs.ToString());
                }
            }

            if (TKTLambda.IsFn(LeftToExp.RetType))// (!isFn())
            {
                analyArgLanmbda(_AnalyExpContext);
            }
            else
            {
                if (RightValueExp.RetType != null && LeftToExp.RetType != null)
                {
                    if (!ReflectionUtil.IsExtends(RightValueExp.RetType, LeftToExp.RetType))
                    {
                        error(LeftToExp.Postion, "左右赋值类型不匹配,不能赋值");
                    }
                }
            }

            if (LeftToExp is EveryOneExp)
            {
                isEveryOneAssign   = true;
                everyOneAssignStmt = new EveryOneAssignStmt(this);
                everyOneAssignStmt.Analy(context);
            }
        }