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);
        }
Example #2
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods( );

            foreach (var method in methodArray)
            {
                CodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(CodeAttribute)) as CodeAttribute;
                if (procAttr == null)
                {
                    ExMethodInfo exMethod     = GclUtil.CreatExMethodInfo(method, this.ForType);
                    TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        return(typeProcDesc);
                    }
                }
                else
                {
                    ProcDescCodeParser parser = new ProcDescCodeParser();
                    parser.InitType(ForType, method);
                    TKTProcDesc typeProcDesc = parser.Parser(WordDict, procAttr.Code);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        ExMethodInfo exMethod = GclUtil.CreatExMethodInfo(method, this.ForType);
                        typeProcDesc.ExMethod = exMethod;
                        return(typeProcDesc);
                    }
                }
            }
            if (ParentMapping != null)
            {
                return(ParentMapping.SearchProc(procDesc));
            }
            return(null);
        }
Example #3
0
        public override TKTProcDesc[] GetProces()
        {
            List <TKTProcDesc> list = new List <TKTProcDesc>();
            var methodArray         = this.SharpType.GetMethods();

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 编译器生成的类肯定有标注 */
                ZCodeAttribute     procAttr = AttributeUtil.GetAttribute <ZCodeAttribute>(method);
                ProcDescCodeParser parser   = new ProcDescCodeParser();
                parser.InitType(SharpType, method);
                TKTProcDesc  typeProcDesc = parser.Parser(procAttr.Code);
                ExMethodInfo exMethod     = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                typeProcDesc.ExMethod = exMethod;
                list.Add(typeProcDesc);
            }
            if (ParentMapping != null)
            {
                TKTProcDesc[] epi = ParentMapping.GetProces();
                foreach (var pitem in epi)
                {
                    pitem.ExMethod.IsSelf = false;
                }
                list.AddRange(epi);
            }
            return(list.ToArray());
        }
Example #4
0
        public static ExMethodInfo CreatExMethodInfo(MethodInfo methodInfo, Type forType)
        {
            if (methodInfo == null)
            {
                return(null);
            }
            ExMethodInfo exMethodInfoInfo = new ExMethodInfo(methodInfo, methodInfo.DeclaringType == forType);

            return(exMethodInfoInfo);
        }
Example #5
0
        public static ExMethodInfo MakeGenericExMethod(ExMethodInfo exMethod, Type[] types)
        {
            if (exMethod == null)
            {
                return(null);
            }
            var          newMethod       = exMethod.Method.MakeGenericMethod(types.ToArray());
            ExMethodInfo newExMethodInfo = new ExMethodInfo(newMethod, exMethod.IsSelf);

            return(newExMethodInfo);
        }
 public static MethodInfo SearchMethod(Type type, TKTProcDesc procDesc)
 {
     foreach (var method in type.GetMethods())
     {
         ExMethodInfo exMethod   = new ExMethodInfo(method, method.DeclaringType == type);
         TKTProcDesc  methodDesc = CreateProcDesc(exMethod);
         if (methodDesc.Eq(procDesc))
         {
             return(method);
         }
     }
     return(null);
 }
Example #7
0
        public override void Generate(EmitExpContext context)
        {
            ILGenerator il = context.ILout;

            if (newCode == 1)
            {
                var          Constructor = ConstructorDesc.Constructor;
                LocalBuilder varLocal    = il.DeclareLocal(SubjectGCL.ForType);
                EmitHelper.NewObj(il, Constructor);
                il.Emit(OpCodes.Stloc, varLocal);

                MethodInfo   addMethod       = SubjectGCL.ForType.GetMethod("Add");
                ExMethodInfo exAddMethodInfo = GclUtil.CreatExMethodInfo(addMethod, SubjectGCL.ForType);
                if (BrackestArgs != null)
                {
                    foreach (var exp in BrackestArgs.InneExps)
                    {
                        EmitHelper.LoadVar(il, varLocal);//il.Emit(OpCodes.Ldloc, varLocal);
                        (exp).Generate(context);
                        EmitHelper.CallDynamic(il, exAddMethodInfo);
                    }
                }
                EmitHelper.LoadVar(il, varLocal);//il.Emit(OpCodes.Ldloc, varLocal);
            }
            else if (newCode == 2)
            {
                var Constructor = ConstructorDesc.Constructor;
                if (!IsAssignedValue)
                {
                    LocalBuilder varLocal = il.DeclareLocal(SubjectGCL.ForType);
                    emitConstructor(context);//emitArgs(context);
                    EmitHelper.NewObj(il, Constructor);
                    il.Emit(OpCodes.Stloc, varLocal);
                    EmitHelper.LoadVar(il, varLocal);//il.Emit(OpCodes.Ldloc, varLocal);
                }
                else
                {
                    emitConstructor(context);//emitArgs(context);
                    EmitHelper.NewObj(il, Constructor);
                }
            }
            else
            {
                var Method = ProcDesc.ExMethod;
                emitProc(context);
                EmitHelper.CallDynamic(il, Method);
            }
            base.GenerateConv(context);
        }
Example #8
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods(/*BindingFlags.DeclaredOnly*/);

            foreach (var method in methodArray)
            {
                if (ReflectionUtil.IsDeclare(MType, method))
                {
                    ExMethodInfo exMethod     = new ExMethodInfo(method, method.DeclaringType == MType);
                    TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        return(typeProcDesc);
                    }
                }
            }
            return(null);
        }
Example #9
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);
        }
Example #10
0
        public override TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = this.SharpType.GetMethods( );

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 编译器生成的类肯定有标注 */
                ZCodeAttribute procAttr = AttributeUtil.GetAttribute <ZCodeAttribute>(method);// Attribute.GetCustomAttribute(method, typeof(ZCodeAttribute)) as ZCodeAttribute;
                //if (procAttr == null)
                //{
                //    ExMethodInfo exMethod = ZTypeHelper.CreatExMethodInfo(method, this.SharpType);
                //    TKTProcDesc typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                //    if (typeProcDesc.Eq(procDesc))
                //    {
                //        return typeProcDesc;
                //    }
                //}
                //else
                //{
                ProcDescCodeParser parser = new ProcDescCodeParser();
                parser.InitType(SharpType, method);
                TKTProcDesc typeProcDesc = parser.Parser(procAttr.Code);
                if (typeProcDesc.Eq(procDesc))
                {
                    ExMethodInfo exMethod = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                    typeProcDesc.ExMethod = exMethod;
                    return(typeProcDesc);
                }
                //}
            }
            if (ParentMapping != null)
            {
                return(ParentMapping.SearchProc(procDesc));
            }
            return(null);
        }
Example #11
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods();

            foreach (var method in methodArray)
            {
                if (ReflectionUtil.IsDeclare(MType, method))
                {
                    //ZCodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(ZCodeAttribute)) as ZCodeAttribute;
                    Attribute[] attrs = Attribute.GetCustomAttributes(method, typeof(ZCodeAttribute));
                    if (attrs.Length == 0) // if (procAttr == null)
                    {
                        ExMethodInfo exMethod     = GclUtil.CreatExMethodInfo(method, this.ForType);
                        TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                        if (typeProcDesc.Eq(procDesc))
                        {
                            MethodInfo rmethod = method;
                            if (rmethod.IsAbstract)
                            {
                                rmethod = searchMethodByMethod(method);
                            }
                            if (rmethod == null)
                            {
                                return(null);
                            }
                            else
                            {
                                TKTProcDesc rdesc = ProcDescHelper.CreateProcDesc(exMethod);
                                return(rdesc);
                            }
                        }
                    }
                    else
                    {
                        ParameterInfo[] paramArray = method.GetParameters();

                        parser.InitType(ForType, method);
                        foreach (Attribute attr in attrs)
                        {
                            ZCodeAttribute zCodeAttribute = attr as ZCodeAttribute;
                            TKTProcDesc    typeProcDesc   = parser.Parser(WordDict, zCodeAttribute.Code);
                            if (method.IsStatic && !method.IsAbstract && typeProcDesc.HasSubject() &&
                                typeProcDesc.GetSubjectArg().ArgType == this.ForType)
                            {
                                typeProcDesc = typeProcDesc.CreateTail();
                            }
                            if (typeProcDesc.Eq(procDesc))
                            {
                                MethodInfo rmethod = method;
                                if (rmethod.IsAbstract)
                                {
                                    rmethod = searchMethodByMethod(method);
                                }
                                if (rmethod == null)
                                {
                                    return(null);
                                }
                                else
                                {
                                    ExMethodInfo exMethod = GclUtil.CreatExMethodInfo(rmethod, this.ForType);
                                    typeProcDesc.ExMethod = exMethod;
                                    return(typeProcDesc);
                                }
                            }
                        }
                    }
                }
            }
            if (isRootMapping())
            {
                return(null);
            }
            else
            {
                return(ParentMapping.SearchProc(procDesc));
            }
        }
Example #12
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);
        }
Example #13
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods();

            foreach (var method in methodArray)
            {
                if (ReflectionUtil.IsDeclare(MType, method))
                {
                    CodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(CodeAttribute)) as CodeAttribute;
                    if (procAttr == null)
                    {
                        ExMethodInfo exMethod     = GclUtil.CreatExMethodInfo(method, this.ForType);
                        TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                        if (typeProcDesc.Eq(procDesc))
                        {
                            MethodInfo rmethod = method;
                            if (rmethod.IsAbstract)
                            {
                                rmethod = searchMethodByMethod(method);
                            }
                            if (rmethod == null)
                            {
                                throw new RTException("方法与被翻译类型的方法不一致");
                            }
                            else
                            {
                                TKTProcDesc rdesc = ProcDescHelper.CreateProcDesc(exMethod);
                                return(rdesc);
                            }
                        }
                    }
                    else
                    {
                        ParameterInfo[] paramArray = method.GetParameters();

                        parser.InitType(ForType, method);
                        TKTProcDesc typeProcDesc = parser.Parser(WordDict, procAttr.Code);
                        if (method.IsStatic && !method.IsAbstract && typeProcDesc.HasSubject() && typeProcDesc.GetSubjectArg().ArgType == this.ForType)
                        {
                            typeProcDesc = typeProcDesc.CreateTail();
                        }
                        if (typeProcDesc.Eq(procDesc))
                        {
                            MethodInfo rmethod = method;
                            if (rmethod.IsAbstract)
                            {
                                rmethod = searchMethodByMethod(method);
                            }
                            if (rmethod == null)
                            {
                                throw new RTException("过程描述标注错误");
                            }
                            else
                            {
                                ExMethodInfo exMethod = GclUtil.CreatExMethodInfo(rmethod, this.ForType);
                                typeProcDesc.ExMethod = exMethod;
                                return(typeProcDesc);
                            }
                        }
                    }
                }
            }
            if (isRootMapping())
            {
                return(null);
            }
            else
            {
                return(ParentMapping.SearchProc(procDesc));
            }
        }
Example #14
0
        public override TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = this.SharpType.GetMethods();

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 映射类可能有多个同义的方法对应同一个实际方法 */
                ZCodeAttribute[] attrs = AttributeUtil.GetAttributes <ZCodeAttribute>(method);
                /* 编译器生成的类可能没有标注,没有标注的方法必定在ZMappingType上 */
                if (attrs.Length == 0)
                {
                    ExMethodInfo exMethod     = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                    TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        TKTProcDesc rdesc = ProcDescHelper.CreateProcDesc(exMethod);
                        return(rdesc);
                    }
                }
                else if (attrs.Length > 0)
                {
                    ParameterInfo[] paramArray = method.GetParameters();
                    parser.InitType(SharpType, method);
                    foreach (ZCodeAttribute attr in attrs)
                    {
                        ZCodeAttribute zCodeAttribute = attr as ZCodeAttribute;
                        TKTProcDesc    typeProcDesc   = parser.Parser(zCodeAttribute.Code);
                        if (method.IsStatic && !method.IsAbstract && typeProcDesc.HasSubject() &&
                            typeProcDesc.GetSubjectArg().ArgType == this.SharpType)
                        {
                            typeProcDesc = typeProcDesc.CreateTail();
                        }
                        if (typeProcDesc.Eq(procDesc))
                        {
                            ExMethodInfo exMethod = null;// getExMethod(method);
                            /* 非 Abstract 的方法肯定从被映射的类中搜索 */
                            if (method.IsAbstract)
                            {
                                var method2 = searchMethodFromSharp(method);
                                exMethod = ZTypeUtil.CreatExMethodInfo(method2, this.SharpType);
                                //return exMethod;
                            }
                            else
                            {
                                exMethod = ZTypeUtil.CreatExMethodInfo(method, this.ZMappingType);
                                //return exMethod;
                            }
                            typeProcDesc.ExMethod = exMethod;
                            return(typeProcDesc);
                        }
                    }
                }
            }
            if (ParentMapping != null && !isRoot())
            {
                var epi = ParentMapping.SearchProc(procDesc);
                if (epi != null)
                {
                    //epi.IsSelf = false;
                    return(epi);
                }
            }
            return(null);
        }
Example #15
0
 public static void CallDynamic(ILGenerator il, ExMethodInfo exMethod)
 {
     CallDynamic(il, exMethod.Method, exMethod.IsSelf);
 }