Exemplo n.º 1
0
        public static TKTProcDesc CreateProcDesc(ExMethodInfo exMethod)
        {
            var         method = exMethod.Method;
            TKTProcDesc desc   = new TKTProcDesc();

            desc.Add(method.Name);
            if (method.IsGenericMethod)
            {
                foreach (Type paramType in method.GetGenericArguments())
                {
                    TKTProcArg arg = new TKTProcArg(paramType, true);
                    desc.Add(arg);
                }
            }
            if (method.GetParameters().Length > 0)
            {
                List <TKTProcArg> args = new List <TKTProcArg>();
                foreach (ParameterInfo param in method.GetParameters())
                {
                    TKTProcArg arg = new TKTProcArg(param.Name, param.ParameterType, false);
                    args.Add(arg);
                }
                desc.Add(args);
            }
            desc.ExMethod = exMethod;
            return(desc);
        }
Exemplo n.º 2
0
        bool analyCallBody()
        {
            ExpProcDesc = new TKTProcDesc();
            int i = 0;

            for (; i < this.Elements.Count; i++)
            {
                var exp = this.Elements[i];
                if (exp is FTextExp)
                {
                    ExpProcDesc.Add((exp as FTextExp).IdentToken.GetText());
                }
                else if (exp is BracketExp)
                {
                    var bexp = exp as BracketExp;
                    var exp2 = bexp.Analy(this.AnalyExpContext);
                    if (exp2 != null && exp2.TrueAnalyed)
                    {
                        Elements[i] = exp2;
                        ExpProcDesc.Add(bexp.GetDimArgs());
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        void parseText()
        {
            StringBuilder buff = new StringBuilder();

            for (; i < Code.Length && ch != '('; i++)
            {
                buff.Append(ch);
            }
            desc.Add(buff.ToString());
        }
Exemplo n.º 4
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;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        bool AnlayNameBody(int startArgIndex)
        {
            var symbols = MethodAST.MethodContext.Symbols;

            ProcDesc = new TKTProcDesc();
            int argIndex = startArgIndex;

            for (int i = 0; i < NameTerms.Count; i++)
            {
                var term = NameTerms[i];
                if (term is FnText)
                {
                    var textterm = term as FnText;
                    textterm.Analy(this);
                    ProcDesc.Add(textterm.TextContent);
                }
                else if (term is FnBracket)
                {
                    var argterm = term as FnBracket;
                    List <TKTProcArg> procArgs = new List <TKTProcArg>();
                    foreach (var arg in argterm.Args)
                    {
                        bool b = arg.Analy(this, argIndex);
                        if (b)
                        {
                            TKTProcArg procArg = new TKTProcArg(arg.ArgName, arg.ArgType, arg.IsGenericArg);
                            procArgs.Add(procArg);
                            argIndex++;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    ProcDesc.Add(procArgs);
                }
            }
            if (!checkName())
            {
                return(false);
            }
            MethodAST.MethodContext.ProcDesc = ProcDesc;
            MethodAST.MethodContext.ClassContext.ClassSymbol.AddMethod(MethodAST.MethodContext);
            return(true);
        }
Exemplo n.º 6
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));
            }
        }
Exemplo n.º 7
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            var classContext = context.StmtContext.MethodContext.ClassContext;
            var symbols      = this.AnalyExpContext.Symbols;

            BrackestArgs = BrackestArgs.Analy(context) as BracketExp;
            if (!BrackestArgs.TrueAnalyed)
            {
                return(null);
            }
            Type subjectType = SubjectGCL.ForType;

            if (subjectType.FullName.StartsWith(CompileConstant.LangPackageName + ".列表`1["))
            {
                newCode         = 1;
                ConstructorDesc = new TKTConstructorDesc();
                var Constructor = subjectType.GetConstructor(new Type[] {});
                if (Constructor == null)
                {
                    error(BrackestArgs.Postion, "没有正确的创建过程");
                    return(null);
                }
                else
                {
                    RetType = subjectType;
                    ConstructorDesc.Constructor = Constructor;
                    Type[] genericTypes = GenericUtil.GetInstanceGenriceType(subjectType, typeof(列表 <>));
                    Type   ElementType  = genericTypes[0];

                    var args = BrackestArgs.GetDimArgs();
                    for (int i = 0; i < args.Count; i++)
                    {
                        Exp arg = args[i].Value as Exp;
                        if (arg.RetType != ElementType && !ReflectionUtil.IsExtends(arg.RetType, ElementType))
                        {
                            errorf(arg.Postion, "类型不是列表的子类型,不能添加");
                        }
                    }
                }
            }
            else
            {
                var args = BrackestArgs.GetDimArgs();
                ProcDesc = new TKTProcDesc();
                ProcDesc.Add(SubjectGCL.ShowName);
                ProcDesc.Add(args);
                TKTProcDesc newProcDesc = searchNewProc(classContext, ProcDesc);
                if (newProcDesc != null)
                {
                    newProcDesc.AdjustBracket(ProcDesc);// ProcDesc.AdjustBracket(newProcDesc);
                    ProcDesc.ExMethod = newProcDesc.ExMethod;
                    newCode           = 3;
                    RetType           = ProcDesc.ExMethod.Method.ReturnType;
                }
                else
                {
                    ConstructorDesc = new TKTConstructorDesc(args);
                    TKTConstructorDesc realDesc = SubjectGCL.SearchConstructor(ConstructorDesc);
                    if (realDesc == null)
                    {
                        error(BrackestArgs.Postion, "没有正确的创建过程");
                        return(null);
                    }
                    else
                    {
                        RetType = SubjectGCL.ForType;
                        realDesc.AdjustBracket(ConstructorDesc);
                        ConstructorDesc.Constructor = realDesc.Constructor;
                        newCode = 2;
                    }
                }
            }
            return(this);
        }