Ejemplo n.º 1
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyExpContext.Symbols;
            Exp exp     = null;

            exp = analyNewExp(context);

            if (exp == null)
            {
                exp = analyDiExp();
            }

            if (exp == null)
            {
                InvokeExp invokeexp = new InvokeExp(this);
                invokeexp.Elements = this.Elements;
                exp = invokeexp;
            }

            if (exp != null)
            {
                exp = exp.Analy(context);//exp = AnalyExp(exp);
                return(exp);
            }

            throw new CompileException("FCallExp无法分析完成");
        }
Ejemplo n.º 2
0
        //private List<SymbolDefField> nestedSymbolInfos;

        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            createContext(this.AnalyExpContext);
            var symbols = this.AnalyExpContext.Symbols;

            analyOutClassField(this.AnalyExpContext, false, context.ClassContext.ClassSymbol.ClassBuilder);
            analyFields(false);
            if (RetType != typeof(void))
            {
                retSymbol                = new SymbolVar("结果", RetType);
                retSymbol.IsAssigned     = true;
                retSymbol.LoacalVarIndex = this.NestedMethodContext.CreateLocalVarIndex("结果");
                symbols.AddSafe(retSymbol);
            }
            BodyExp = BodyExp.Analy(this.AnalyExpContext);
            if (FnRetType != typeof(Action))
            {
                if (RetType != typeof(bool))
                {
                    error(BodyExp.Postion, "返回结果的类型不匹配");
                    return(null);
                }
            }
            return(this);
        }
Ejemplo n.º 3
0
        Exp analyParentClass(AnalyExpContext context)
        {
            ClassContext   classContext = context.ClassContext;
            SymbolDefClass classSymbol  = classContext.ClassSymbol;

            if (classSymbol.BaseGcl == null)
            {
                return(null);
            }
            ExPropertyInfo property = classSymbol.BaseGcl.SearchExProperty(IdentName);

            //if (property == null) return null;
            if (property != null)
            {
                if (ReflectionUtil.IsPublic(property.Property) || ReflectionUtil.IsProtected(property.Property))
                {
                    SymbolDefProperty ps = new SymbolDefProperty(IdentName, property.Property.PropertyType, ReflectionUtil.IsStatic(property.Property));
                    ps.SetProperty(property.Property);

                    VarExp exp = new VarExp(this, this.IdentToken);
                    exp.VarSymbol = ps;
                    return(exp);
                }
            }
            return(null);
        }
        protected void createForeachSymbols(AnalyExpContext context, SymbolTable symbols, int foreachIndex, Type listType)
        {
            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, listType);
            listSymbol.LoacalVarIndex = context.StmtContext.MethodContext.CreateLocalVarIndex(listSymbol.SymbolName);
            symbols.Add(listSymbol);

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

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

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

            indexSymbol = new SymbolVar(indexName, typeof(int));
            indexSymbol.LoacalVarIndex = context.StmtContext.MethodContext.CreateLocalVarIndex(indexName);
            indexSymbol.IsInBlock      = true;
            symbols.Add(indexSymbol);
        }
Ejemplo n.º 5
0
 public override Exp Analy(AnalyExpContext context)
 {
     base.Analy(context);
     this.TrueAnalyed = true;
     for (int i = 0; i < InneExps.Count; i++)
     {
         Exp exp = InneExps[i];
         exp = exp.Analy(context);
         if (exp == null)
         {
             TrueAnalyed = false;
         }
         else
         {
             InneExps[i] = exp;
             TrueAnalyed = TrueAnalyed && exp.TrueAnalyed;
         }
     }
     if (InneExps.Count == 1)
     {
         RetType = InneExps[0].RetType;
     }
     else
     {
         RetType = null;
     }
     return(this);
 }
Ejemplo n.º 6
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            LiteralKind  = LiteralToken.Kind;
            LiteralValue = LiteralToken.GetText();

            if (LiteralKind == TokenKind.LiteralInt)
            {
                RetType = intType;
            }
            else if (LiteralKind == TokenKind.LiteralFloat)
            {
                RetType = floatType;
            }
            else if (LiteralKind == TokenKind.LiteralString)
            {
                RetType = stringType;
            }
            else if (LiteralKind == TokenKind.True || LiteralKind == TokenKind.False)
            {
                RetType = boolType;
            }
            else if (LiteralKind == TokenKind.NULL)
            {
                RetType = null;
            }
            else
            {
                error(LiteralToken.ToCode() + "不是正确的值");
                return(null);
            }
            return(this);
        }
Ejemplo n.º 7
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyExpContext.Symbols;
            OpKind = OpToken.Kind;

           if(OpKind!= TokenKind.ADD && OpKind!= TokenKind.SUB)
           {
               errorf(OpToken.Postion, "运算符'{0}'缺少表达式", OpToken.GetText());
               return null;
           }

           RightExp = RightExp.Analy(context);//RightExp = AnalyExp(RightExp);
           if(RightExp==null)
           {
               TrueAnalyed = false;
               return null;
           }
     
            Type rtype = RightExp.RetType;
            RetType = rtype;
            if(rtype!= typeof(int)&& rtype!= typeof(float) && rtype!= typeof(double) && rtype != typeof(decimal))
            {
                errorf(RightExp.Postion,"不能进行'{0}'运算",OpToken.GetText());
                return null;
            }

            if (OpKind == TokenKind.ADD)
            {
                return RightExp;
            }
            return this;
        }
Ejemplo n.º 8
0
 public override Exp Analy(AnalyExpContext context)
 {
     base.Analy(context);
     lambdaExp.Analy(context);
     this.RetType = lambdaExp.FnRetType;
     return(this);
 }
Ejemplo n.º 9
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyExpContext.Symbols;

            RetType = (memberSymbol as InstanceSymbol).DimType;
            return(this);
        }
Ejemplo n.º 10
0
        void analyArgLanmbda(AnalyExpContext context)
        {
            var          totype       = LeftToExp.RetType;
            NewLambdaExp newLambdaExp = new NewLambdaExp(RightValueExp, RightValueExp, totype);

            RightValueExp = newLambdaExp;
            newLambdaExp.Analy(context);
        }
Ejemplo n.º 11
0
        //string propertyName;
        //PropertyInfo ExProperty;

        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            //SubjectExp.LoadRefTypes(context);
            Type[] types = GenericUtil.GetInstanceGenriceType(ListExp.RetType, typeof(Z语言系统.列表 <>));
            this.RetType = types[0];
            return(this);
        }
Ejemplo n.º 12
0
 protected Exp AnalyExp(Exp exp)
 {
     exp.Stmt = this;
     if (_AnalyExpContext == null)
     {
         _AnalyExpContext = new AnalyExpContext(this.AnalyStmtContext);
     }
     return(exp.Analy(_AnalyExpContext));
 }
Ejemplo n.º 13
0
 public override Exp Analy(AnalyExpContext context)
 {
     base.Analy(context);
     ValueExp = ValueExp.Analy(context);
     if (ValueExp == null)
     {
         return(null);
     }
     RetType = ValueExp.RetType;
     return(this);
 }
Ejemplo n.º 14
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;
        }
Ejemplo n.º 15
0
        Exp analyType(AnalyExpContext context)
        {
            IGcl gcl = context.StmtContext.MethodContext.ClassContext.SearchType(IdentName);

            if (gcl != null)
            {
                Type    type = gcl.ForType;
                TypeExp exp  = new TypeExp(this, IdentToken, type);
                return(exp);
            }
            return(null);
        }
Ejemplo n.º 16
0
        Exp analyDiDe(AnalyExpContext context)
        {
            Exp exp = identParser.Parse(IdentToken, this);

            if (exp == null)
            {
                return(null);
            }
            exp.IsAssignedBy    = this.IsAssignedBy;
            exp.IsAssignedValue = this.IsAssignedValue;
            return(exp);
        }
Ejemplo n.º 17
0
        //private SymbolDefField outClassFieldSymbol;

        void analyOutClassField(AnalyExpContext context, bool isStatic, Type outClassType)
        {
            var name    = "__$__Nested_This";
            var symbols = NestedClassContext.Symbols;
            //var curContext = context.StmtContext.MethodContext.ClassContext;
            var propertyType = outClassType;

            outClassFieldBuilder             = NestedClassContext.EmitContext.CurrentTypeBuilder.DefineField(name, propertyType, FieldAttributes.Public);
            NestedClassContext.OutClassField = new SymbolDefField(name, propertyType, isStatic);
            NestedClassContext.OutClassField.SetField(outClassFieldBuilder);
            symbols.AddSafe(NestedClassContext.OutClassField);
        }
Ejemplo n.º 18
0
 public override Exp Analy(AnalyExpContext context)
 {
     if (type == 1)
     {
         RetType = EType;
     }
     else if (type == 2)
     {
         RetType = DType.ClassBuilder;
     }
     return(this);
 }
Ejemplo n.º 19
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            identParser = new IdentParser();
            symbols     = this.AnalyExpContext.Symbols;

            IdentName    = IdentToken.GetText();
            classContext = context.StmtContext.MethodContext.ClassContext;

            Exp exp = null;

            exp = analyCurrentClass(context);

            if (exp == null)
            {
                exp = analyParentClass(context);
            }

            if (exp == null)
            {
                exp = analyAsDirectMember(context);
            }

            if (exp == null)
            {
                exp = analyCall(context).Item1;
            }

            if (exp == null)
            {
                if (IdentName.IndexOf('的') != -1 || IdentName.IndexOf('第') != -1)
                {
                    exp = analyDiDe(context);
                }
                else
                {
                    exp = analyType(context);
                }
            }
            if (exp == null)
            {
                exp = dimVar(context);
            }

            if (exp != null)
            {
                exp = exp.Analy(context);//
                return(exp);
            }
            return(null);
        }
Ejemplo n.º 20
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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
 void analyArgLanmbda(AnalyExpContext context)
 {
     for (int i = 0; i < ExpProcDesc.ArgCount; i++)
     {
         TKTProcArg procArg = searchedProcDesc.GetArg(i);
         if (procArg.ArgType == TKTLambda.ActionType || procArg.ArgType == TKTLambda.CondtionType)
         {
             TKTProcArg   expArg       = ExpProcDesc.GetArg(i);
             Exp          exp          = expArg.Value as Exp;
             NewLambdaExp newLambdaExp = new NewLambdaExp(this, exp, procArg.ArgType);
             expArg.Value = newLambdaExp;
             newLambdaExp.Analy(context);
         }
     }
 }
Ejemplo n.º 22
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyExpContext.Symbols;

            OpKind = OpToken.Kind;

            if (RightExp == null)
            {
                errorf(OpToken.Postion, "运算符'{0}'右边缺少运算元素", OpToken.GetText());
                return(null);
            }
            else if (LeftExp == null && RightExp != null)
            {
                UnaryExp unexp = new UnaryExp(OpToken, RightExp);
                var      exp   = unexp.Analy(context);
                return(exp);
            }

            LeftExp  = LeftExp.Analy(context);  //LeftExp = AnalyExp(LeftExp);
            RightExp = RightExp.Analy(context); //RightExp = AnalyExp(RightExp);

            if (LeftExp == null || RightExp == null)
            {
                TrueAnalyed = false;
                return(null);
            }

            Type ltype = LeftExp.RetType;
            Type rtype = RightExp.RetType;

            OpMethod = BinExpUtil.GetCalcMethod(OpKind, ltype, rtype);
            if (OpMethod != null)
            {
                RetType = OpMethod.ReturnType;
            }

            if (RetType == null)
            {
                error("两种类型无法进行'" + OpToken.ToCode() + "'运算");
            }
            return(this);
        }
Ejemplo n.º 23
0
 Exp analyAsDirectMember(AnalyExpContext context)
 {
     object[] objs = ClassContextHelper.SearchDirectIdent(classContext, IdentName);
     if (objs.Length == 0)
     {
         //error("属性或者规定的值'" + IdentName + "'不存在");
         return(null);
     }
     else if (objs.Length > 1)
     {
         error("属性或者规定的值'" + IdentName + "'不明确");
         return(null);
     }
     else
     {
         var        obj = objs[0];
         SymbolInfo directSymbol;
         if (obj is ExPropertyInfo)
         {
             var pvar = obj as ExPropertyInfo;
             directSymbol = new SymbolPropertyDirect(IdentName, pvar);
             RetType      = pvar.Property.PropertyType;
         }
         else if (obj is ExFieldInfo)
         {
             var pvar = obj as ExFieldInfo;
             directSymbol = new SymbolFieldDirect(IdentName, pvar);
             RetType      = pvar.Field.FieldType;
         }
         else
         {
             var enumSymbol = new SymbolEnumItem(IdentName, obj);
             directSymbol = enumSymbol;
             RetType      = enumSymbol.DimType;
         }
         if (directSymbol != null)
         {
             DirectMemberExp exp = new DirectMemberExp(this, IdentToken, directSymbol, this.IsAssignedBy, this.IsAssignedValue);
             return(exp);
         }
     }
     return(null);
 }
Ejemplo n.º 24
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            int foreachIndex = context.StmtContext.MethodContext.CreateForeachIndex();
            var symbols      = context.Symbols;
            Exp listExp      = everyoneExp.ListExp;
            //PropertyInfo countProperty = listExp.RetType.GetProperty("Count");
            ExPropertyInfo countProperty = GclUtil.SearchExProperty("Count", listExp.RetType);

            var rgetCountMethod = countProperty.Property.GetGetMethod();

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

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

            createForeachSymbols(context, symbols, foreachIndex, everyoneExp.ListExp.RetType);
            this.RetType = invokeExp.CallExMethod.Method.ReturnType;
            return(this);
        }
Ejemplo n.º 25
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            classContext = context.StmtContext.MethodContext.ClassContext;
            var symbols = this.AnalyExpContext.Symbols;

            if (!analyCallBody())
            {
                return(null);
            }
            searchedProcDesc = searchProc(classContext);
            if (searchedProcDesc == null)
            {
                errorf("没有找到过程'{0}'", this.ToCode());
                return(null);
            }
            searchedProcDesc.AdjustBracket(ExpProcDesc);
            CallExMethod = searchedProcDesc.ExMethod;
            if (CallExMethod == null)
            {
                return(null);
            }
            RetType = CallExMethod.Method.ReturnType;

            analyGeneric();
            analyArgLanmbda(context);
            if (isSubjectEveryOneExp())
            {
                InvokeEveryoneSubejctExp ieoexp = new InvokeEveryoneSubejctExp(this);
                Exp ioeResultExp = ieoexp.Analy(context);
                return(ioeResultExp);
            }
            else if (isObjectEveryOneExp())
            {
                InvokeEveryoneObejctExp ieoexp = new InvokeEveryoneObejctExp(this);
                Exp ioeResultExp = ieoexp.Analy(context);
                return(ioeResultExp);
            }
            return(this);
        }
Ejemplo n.º 26
0
        Tuple <Exp, int> analyCall(AnalyExpContext context)
        {
            TKTProcDesc procdesc = new TKTProcDesc();

            procdesc.Add(IdentName);
            var procArray = ClassContextHelper.SearchProc(classContext, procdesc);

            if (procArray.Length == 1)
            {
                InvokeSimplestExp exp = new InvokeSimplestExp(this, IdentToken, procArray[0]);
                return(new Tuple <Exp, int> (exp, 1));
            }
            else if (procArray.Length == 0)
            {
                return(new Tuple <Exp, int>(null, 0));
            }
            else
            {
                errorf("有多个相同名称'{0}'过程,不能确定是哪个过程", IdentName);
                return(new Tuple <Exp, int>(null, procArray.Length));
            }
        }
Ejemplo n.º 27
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyExpContext.Symbols;

            SubjectExp = SubjectExp.Analy(context); // AnalyExp(SubjectExp);
            ArgExp     = ArgExp.Analy(context);     //AnalyExp(ArgExp);
            var propertyName = "Item";
            var subjType     = SubjectExp.RetType;

            ExProperty = GclUtil.SearchExProperty(propertyName, subjType); //subjType.GetExProperty(propertyName);

            if (ExProperty == null)
            {
                error(SubjectExp.Postion, "不存在索引");
                return(null);
            }
            else
            {
                RetType = ExProperty.Property.PropertyType;
            }
            return(this);
        }
Ejemplo n.º 28
0
        NewExp analyNewExp(AnalyExpContext context)
        {
            var symbols = this.AnalyExpContext.Symbols;

            if (!isNewFormat())
            {
                return(null);
            }
            Exp    first = Elements[0];
            string name  = (first as FTextExp).IdentToken.GetText();
            IGcl   gcl   = context.StmtContext.MethodContext.ClassContext.SearchType(name);

            if (gcl == null)
            {
                return(null);
            }
            NewExp newExp = new NewExp(this);

            newExp.SubjectGCL      = gcl;
            newExp.IsAssignedValue = this.IsAssignedValue;
            newExp.BrackestArgs    = (Elements[1] as BracketExp);
            return(newExp);
        }
Ejemplo n.º 29
0
        Exp analyCurrentClass(AnalyExpContext context)
        {
            var IdentSymbol = symbols.Get(IdentName);

            if (IdentSymbol == null)
            {
                return(null);
            }
            if (IdentSymbol is InstanceSymbol)
            {
                VarExp exp = new VarExp(this, IdentToken, this.IsAssignedBy, this.IsAssignedValue);
                return(exp);
            }
            else if (IdentSymbol is SymbolDefClass)
            {
                TypeExp exp = new TypeExp(this, IdentToken, (IdentSymbol as SymbolDefClass));
                return(exp);
            }
            else
            {
                throw new CompileException("类型非IVarSymbol、SymbolDefClass");
            }
        }
Ejemplo n.º 30
0
 public override Exp Analy(AnalyExpContext context)
 {
     base.Analy(context);
     RetType = ProcDesc.ExMethod.Method.ReturnType;
     return(this);
 }