예제 #1
0
        public TypeKey(Type t)
        {
            this.t = t;


            key = (t.Namespace == null ? string.Empty : t.Namespace) + "::" + NativeCodeCreatorBase.GetTypeFullName(t);
        }
예제 #2
0
        public string GetCode()
        {
            string funccode = Properties.Resources.StaticFieldSetter;

            funccode = funccode.Replace("[classname]", classname);

            string pushparas = string.Empty;

            pushparas = pushparas + "\t\t\t\t" + string.Format("para.Add({0});\n", GetAS3RuntimeTypeString(field.FieldType));


            funccode = funccode.Replace("[pushparas]", pushparas);


            string loadargs = string.Empty;


            loadargs = loadargs + GetLoadArgementString(field.FieldType, 0);
            loadargs = loadargs + "\n";

            funccode = funccode.Replace("[loadargement]", loadargs);


            funccode = funccode.Replace("[setstaticfield]", NativeCodeCreatorBase.GetTypeFullName(type) + "." + field.Name + " = " + "(" + GetTypeFullName(field.FieldType) + ")" + "arg0;");


            return(funccode);
        }
        public string GetCode()
        {
            string funccode = Properties.Resources.FieldSetter;

            funccode = funccode.Replace("[classname]", classname);

            string pushparas = string.Empty;

            pushparas = pushparas + "\t\t\t\t" + string.Format("para.Add({0});\n", GetAS3RuntimeTypeString(field.FieldType));
            funccode  = funccode.Replace("[pushparas]", pushparas);

            if (type.IsValueType)
            {
                string loadthis = Properties.Resources.LoadStructThis;
                loadthis = loadthis.Replace("[thisObjtype]", NativeCodeCreatorBase.GetTypeFullName(type));
                funccode = funccode.Replace("[loadthis]", loadthis);
            }
            else
            {
                string loadthis = Properties.Resources.LoadThis;
                loadthis = loadthis.Replace("[thisObjtype]", NativeCodeCreatorBase.GetTypeFullName(type));
                funccode = funccode.Replace("[loadthis]", loadthis);
            }

            string loadargs = string.Empty;

            loadargs = loadargs + GetLoadArgementString(field.FieldType, 0);
            loadargs = loadargs + "\n";
            funccode = funccode.Replace("[loadargement]", loadargs);

            funccode = funccode.Replace("[setfield]", "_this." + field.Name + " = " + "(" + GetTypeFullName(field.FieldType) + ")" + "arg0;");

            if (type.IsValueType)             //结构体,需要重新赋值回去
            {
                string replacethis = "((LinkObj<" + GetTypeFullName(type) + ">)((ASBinCode.rtData.rtObjectBase) thisObj).value).value = _this;";
                funccode = funccode.Replace("[replacethis]", replacethis);
            }
            else
            {
                funccode = funccode.Replace("[replacethis]", string.Empty);
            }

            return(funccode);
        }
예제 #4
0
파일: CreatorBase.cs 프로젝트: ikvm/ASTool
        public static string GetDelegateSignature(Type d)
        {
            var method = GetDelegateMethodInfo(d);

            string ret = NativeCodeCreatorBase.GetTypeFullName(method.ReturnType) + "(";

            var paras = method.GetParameters();

            for (int i = 0; i < paras.Length; i++)
            {
                ret += NativeCodeCreatorBase.GetTypeFullName(paras[i].ParameterType);

                if (i < paras.Length - 1)
                {
                    ret += ",";
                }
            }

            ret = ret + ")";

            return(ret);
        }
예제 #5
0
        public override string Create()
        {
            Dictionary <Type, string> typeimports = new Dictionary <Type, string>();

            StringBuilder nativefunc = new StringBuilder();

            //GenNativeFuncImport(nativefunc);
            GenNativeFuncNameSpaceAndClass(nativefunc);

            BeginRegFunction(nativefunc);

            List <string> regfunctions      = new List <string>();
            List <string> nativefuncClasses = new List <string>();



            StringBuilder as3api = new StringBuilder();

            GenAS3FileHead(as3api);

            as3api.AppendLine("@imports");
            as3api.AppendLine();

            as3api.AppendFormat("\t[link_system_interface({0})]", GetCreatorNativeFuncName(type));
            as3api.AppendLine();
            as3api.AppendFormat("\tpublic interface {0}", name);


            regfunctions.Add(
                "\t\t\tbin.regNativeFunction(LinkSystem_Buildin.getCreator(\"" + GetCreatorNativeFuncName(type) + "\", default(" + NativeCodeCreatorBase.GetTypeFullName(type) + ")));");


            if (super != null)
            {
                as3api.AppendFormat(" extends {0}", GetAS3TypeString(super, typeimports, null, null, null));
            }

            as3api.AppendLine();
            as3api.AppendLine("\t{");

            bool existsindexgetter = false;
            bool existsindexsetter = false;

            foreach (var method in methodlist)
            {
                //if (method.IsGenericMethod)
                //{
                //	Console.WriteLine("跳过泛型方法"+method.ToString());

                //	continue;
                //}

                //if (IsSkipType(method.ReturnType))
                //{
                //	Console.WriteLine(method.ToString() + "返回类型被配置为需要跳过");
                //	continue;
                //}


                var paras = method.GetParameters();

                //bool parachecked = true;
                //foreach (var para in paras)
                //{
                //	if (para.IsOut)
                //	{
                //		Console.WriteLine(method.ToString()+"参数"+ para.Position+" " +para+ "为out,跳过");
                //		parachecked=false;
                //		break;
                //	}
                //	if (para.ParameterType.IsByRef)
                //	{
                //		Console.WriteLine(method.ToString() + "参数" + para.Position + " " + para + "为byref,跳过");
                //		parachecked = false;
                //		break;
                //	}
                //	if (para.ParameterType.IsGenericType)
                //	{
                //		Console.WriteLine(method.ToString() + "参数" + para.Position + " " + para + "为泛型,跳过");
                //		parachecked = false;
                //		break;
                //	}

                //	if (para.IsOptional)
                //	{
                //		if (para.RawDefaultValue != null)
                //		{
                //			var rt = MethodNativeCodeCreator.GetAS3Runtimetype(para.ParameterType);
                //			if (rt > ASBinCode.RunTimeDataType.unknown)
                //			{
                //				Console.WriteLine(method.ToString() + "参数" + para.Position + " " + para + "为可选,并且默认值不是基本类型");
                //				parachecked = false;
                //				break;
                //			}
                //		}
                //	}

                //	if (IsSkipType(para.ParameterType))
                //	{
                //		Console.WriteLine(method.ToString() + "参数" + para.Position + " " + para + "被配置为需要跳过");
                //		parachecked = false;
                //		break;
                //	}

                //}

                //if (!parachecked)
                //{
                //	continue;
                //}

                if (isMethodSkip(method))
                {
                    Console.WriteLine(method.ToString() + "有参数或返回值被配置为需要跳过");
                    continue;
                }
                string returntype = GetAS3TypeString(method.ReturnType, typeimports, type, method, null);

                string nativefunName = GetMethodNativeFunctionName(method, type, null, null);

                System.Reflection.PropertyInfo pinfo;
                if (MethodNativeCodeCreator.CheckIsIndexerGetter(method, type, out pinfo) && !existsindexgetter)
                {
                    existsindexgetter = true;
                    //****索引器****
                    as3api.Append("\t\t");
                    as3api.AppendLine("[get_this_item];");


                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}];", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    var name = GetMethodName(method.Name, method, type, null, null);
                    as3api.Append("function " + name);
                }
                else if (MethodNativeCodeCreator.CheckIsGetter(method, type, out pinfo))
                {
                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}]", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    as3api.Append("function get ");
                    as3api.Append(GetMethodName(pinfo.Name, method, type, null, null));
                }
                else if (MethodNativeCodeCreator.CheckIsIndexerSetter(method, type, out pinfo) && !existsindexsetter)
                {
                    existsindexsetter = true;
                    //****索引器****
                    as3api.Append("\t\t");
                    as3api.AppendLine("[set_this_item];");

                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}];", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    var name = GetMethodName(method.Name, method, type, null, null);
                    as3api.Append("function " + name);

                    var temp = paras[0];
                    paras[0] = paras[1];
                    paras[1] = temp;
                }
                else if (MethodNativeCodeCreator.CheckIsSetter(method, type, out pinfo))
                {
                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}]", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    as3api.Append("function set ");
                    as3api.Append(GetMethodName(pinfo.Name, method, type, null, null));
                }
                else
                {
                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}]", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    as3api.Append("function ");
                    as3api.Append(GetMethodName(method.Name, method, type, null, null));
                }

                as3api.Append("(");

                for (int i = 0; i < paras.Length; i++)
                {
                    var para = paras[i];
                    as3api.Append(para.Name);
                    if (as3keywords.ContainsKey(para.Name))
                    {
                        as3api.Append("_");
                    }
                    as3api.Append(":");
                    as3api.Append(GetAS3TypeString(para.ParameterType, typeimports, null, method, para));

                    if (para.IsOptional)
                    {
                        as3api.Append("=");

                        if (para.RawDefaultValue != null)
                        {
                            var rt = MethodNativeCodeCreator.GetAS3Runtimetype(para.ParameterType);
                            if (rt == ASBinCode.RunTimeDataType.rt_string)
                            {
                                string str = para.RawDefaultValue.ToString();
                                str = str.Replace("\\", "\\\\");
                                str = str.Replace("\"", "\\\"");

                                as3api.Append("\"" + str + "\"");
                            }
                            else
                            {
                                as3api.Append(para.RawDefaultValue.ToString());
                            }
                        }
                        else
                        {
                            as3api.Append("null");
                        }
                    }

                    if (i < paras.Length - 1)
                    {
                        as3api.Append(",");
                    }
                }

                as3api.Append(")");
                as3api.Append(":");
                as3api.Append(returntype);
                as3api.AppendLine(";");
                as3api.AppendLine();

                //***编写方法的本地代码***


                //****检测是否可以用反射。***
                bool checkreflection = true;

                if (method.ReturnType.IsByRef)
                {
                    checkreflection = false;
                }


                var param = method.GetParameters();
                foreach (var item in param)
                {
                    if (item.ParameterType.IsByRef)
                    {
                        checkreflection = false;
                    }
                    if (item.ParameterType.Equals(typeof(Type)))
                    {
                        checkreflection = false;
                    }
                    //if (item.ParameterType.IsValueType)
                    //	checkreflection = false;
                }
                if (method.ReturnType.Equals(typeof(Type)))
                {
                    checkreflection = false;
                }

                if (checkreflection && false)
                {
                    bool needswap = false;
                    System.Reflection.PropertyInfo propertyInfo;
                    if (MethodNativeCodeCreator.CheckIsIndexerSetter((System.Reflection.MethodInfo)method, method.DeclaringType, out propertyInfo) && param.Length == 2)
                    {
                        needswap = true;
                    }

                    string returntypestr;
                    if (method.ReturnType.IsValueType && !method.ReturnType.Equals(typeof(void)))
                    {
                        returntypestr = NativeCodeCreatorBase.GetTypeFullName(method.ReturnType);
                    }
                    else
                    {
                        returntypestr = "object";
                    }
                    string regrefl = string.Format("\t\t\tbin.regNativeFunction(new ReflectionInvokeNativeFunction<" + returntypestr + ">("
                                                   + (method.IsStatic ? "true" : "false") + ","
                                                   + (needswap ? "true" : "false") + ","
                                                   + param.Length + ",\"{0}\",\"{1}\",", nativefunName, method.Name);
                    regrefl += GetReflectionInvokeNativeFunctionTypeCodeString(method.ReturnType) + " ,\n\t\t\t\t";

                    regrefl += "new int[]";
                    regrefl += "{";

                    if (needswap)
                    {
                        regrefl += GetReflectionInvokeNativeFunctionTypeCodeString(param[1].ParameterType);
                        regrefl += ",\n\t\t\t\t";
                        regrefl += GetReflectionInvokeNativeFunctionTypeCodeString(param[0].ParameterType);
                    }
                    else
                    {
                        for (int i = 0; i < param.Length; i++)
                        {
                            regrefl += GetReflectionInvokeNativeFunctionTypeCodeString(param[i].ParameterType);
                            if (i < param.Length - 1)
                            {
                                regrefl += ",\n\t\t\t\t";
                            }
                        }
                    }
                    regrefl += "}))";

                    regrefl += ";";

                    regfunctions.Add(regrefl);
                }
                else
                {
                    regfunctions.Add(string.Format("\t\t\tbin.regNativeFunction(\"{0}\",\"{1}\");", LinkCodeNampScapePart + nativefunName, nativefunName));
                    MethodNativeCodeCreator mc = new MethodNativeCodeCreator(nativefunName, method, type);
                    nativefuncClasses.Add(mc.GetCode());
                }
            }

            as3api.AppendLine("\t}");

            EndAS3File(as3api);

            string imports = string.Empty;

            foreach (var item in typeimports.Values)
            {
                imports += "\t" + item + "\n";
            }
            as3api.Replace("@imports", imports);


            for (int i = 0; i < regfunctions.Count; i++)
            {
                nativefunc.AppendLine(regfunctions[i]);
            }

            EndRegFunction(nativefunc);

            for (int i = 0; i < nativefuncClasses.Count; i++)
            {
                nativefunc.AppendLine(nativefuncClasses[i]);
            }

            EndNativeFuncClass(nativefunc);



            //Console.WriteLine(as3api.ToString());
            //Console.WriteLine(nativefunc.ToString());

            string as3file       = as3apidocpath + "/" + GetPackageName(type).Replace(".", "/") + "/" + name + ".as";
            string nativefunfile = csharpnativecodepath + "/" + GetNativeFunctionClassName(type) + ".cs";

            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(as3file));
            System.IO.File.WriteAllText(as3file, as3api.ToString());

            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(nativefunfile));

            StringBuilder usingcode = new StringBuilder();

            GenNativeFuncImport(usingcode);

            System.IO.File.WriteAllText(nativefunfile, usingcode.ToString() + nativefunc.ToString());

            return(nativefunc.ToString());
        }
        public string GetCode()
        {
            System.Reflection.ParameterInfo[] paras;
            if (constructor != null)
            {
                paras = constructor.GetParameters();
            }
            else
            {
                paras = new System.Reflection.ParameterInfo[0];
            }

            string funccode = Properties.Resources.CreateInstance;

            funccode = funccode.Replace("[classname]", classname);
            funccode = funccode.Replace("[paracount]", paras.Length.ToString());

            string pushparas = string.Empty;

            for (int i = 0; i < paras.Length; i++)
            {
                var para = paras[i];

                pushparas = pushparas + "\t\t\t\t" + string.Format("para.Add({0});\n", GetAS3RuntimeTypeString(para.ParameterType));
            }

            funccode = funccode.Replace("[pushparas]", pushparas);


            string loadargs = string.Empty;

            for (int i = 0; i < paras.Length; i++)
            {
                var argement = paras[i];

                loadargs = loadargs + GetLoadArgementString(argement);
                loadargs = loadargs + "\n";
            }

            funccode = funccode.Replace("[loadargement]", loadargs);



            string newobj = "new ";

            newobj += NativeCodeCreatorBase.GetTypeFullName(type);
            newobj += "(";

            for (int i = 0; i < paras.Length; i++)
            {
                newobj += string.Format("({0})arg{1}", GetTypeFullName(paras[i].ParameterType), i);
                if (i < paras.Length - 1)
                {
                    newobj += ",";
                }
            }

            newobj += ")";



            funccode = funccode.Replace("[newinstance]", newobj);
            return(funccode);
        }
예제 #7
0
        public override string Create()
        {
            StringBuilder nativefunc = new StringBuilder();

            //GenNativeFuncImport(nativefunc);
            GenNativeFuncNameSpaceAndClass(nativefunc);

            BeginRegFunction(nativefunc);


            List <string> regfunctions      = new List <string>();
            List <string> nativefuncClasses = new List <string>();


            StringBuilder as3api = new StringBuilder();

            GenAS3FileHead(as3api);

            as3api.Append('\t');
            as3api.Append("[no_constructor]");
            as3api.AppendLine();

            as3api.Append('\t');
            as3api.Append("[link_system]");
            as3api.AppendLine();

            GenClassDefine(as3api);

            //****枚举的creator***
            as3api.Append("\t\t");
            as3api.Append("[creator];");
            as3api.AppendLine();
            as3api.Append("\t\t");
            as3api.AppendFormat("[native,{0}];", GetCreatorNativeFuncName(type));
            as3api.AppendLine();
            as3api.Append("\t\t");
            as3api.Append("private static function _creator(type:Class):*;");
            as3api.AppendLine();
            as3api.AppendLine();

            regfunctions.Add(
                string.Format("\t\t\tbin.regNativeFunction(LinkSystem_Buildin.getCreator(\"{0}\", default({1})));"
                              , GetCreatorNativeFuncName(type)
                              , NativeCodeCreatorBase.GetTypeFullName(type)
                              )
                );

            //***枚举的构造函数***
            as3api.Append("\t\t");
            as3api.AppendFormat("[native,{0}];", GetCtorNativeFuncName(type));
            as3api.AppendLine();
            as3api.Append("\t\t");
            as3api.AppendFormat("public function {0}();", name);
            as3api.AppendLine();
            as3api.AppendLine();

            //regfunctions.Add(
            //    string.Format("\t\t\tbin.regNativeFunction(new {0}());"
            //    ,GetCtorNativeFuncName(type)
            //    )
            //    );
            regfunctions.Add(
                string.Format("\t\t\tbin.regNativeFunction(\"{0}\",\"{1}\");"
                              , LinkCodeNampScapePart + GetCtorNativeFuncName(type)
                              , GetCtorNativeFuncName(type)
                              )
                );
            nativefuncClasses.Add(GetCtorClassString());

            //****创建枚举成员***
            foreach (var item in type.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public))
            {
                if (IsObsolete(item, type))
                {
                    continue;
                }
                if (IsSkipMember(item))
                {
                    continue;
                }

                string enumItemName = item.Name;
                if (as3keywords.ContainsKey(enumItemName))
                {
                    enumItemName = enumItemName + "_";
                }
                if (enumItemName == "Class")
                {
                    enumItemName = "Class_";
                }
                if (enumItemName == "Object")
                {
                    enumItemName = "Object_";
                }

                //object v = item.GetValue(null);
                as3api.Append("\t\t");
                as3api.AppendLine("/**");
                as3api.AppendLine("\t\t *" + enumItemName + " = " + item.ToString());
                as3api.AppendLine("\t\t */");

                as3api.Append("\t\t");
                as3api.AppendFormat("[native,{0}];", GetEnumItemNativeFuncName(item));
                as3api.AppendLine();
                as3api.Append("\t\t");
                as3api.AppendFormat("public static const {0}:{1};", enumItemName, name);
                as3api.AppendLine();
                as3api.AppendLine();


                string nf = "\t\t\tbin.regNativeFunction(";
                nf += "LinkSystem_Buildin.getStruct_static_field_getter(\"" + GetEnumItemNativeFuncName(item) + "\"";
                nf += ",";
                nf += "()=>{ return " + NativeCodeCreatorBase.GetTypeFullName(type) + "." + item.Name + ";}";
                nf += ")";
                nf += ");";

                regfunctions.Add(nf);
            }

            //***枚举的ValueOf***
            as3api.Append("\t\t");
            as3api.AppendFormat("[native, _system_Enum_valueOf];");
            as3api.AppendLine();
            as3api.Append("\t\t");
            as3api.AppendFormat("public function valueOf():int;");
            as3api.AppendLine();
            as3api.AppendLine();

            //***枚举的bitOr操作****
            as3api.Append("\t\t");
            as3api.Append("[operator,\"|\"];");
            as3api.AppendLine();
            as3api.Append("\t\t");
            as3api.Append("[native," + GetEnumBitOrFuncName() + "];");
            as3api.AppendLine();
            as3api.Append("\t\t");
            as3api.AppendFormat("private static function bitOr(t1:{0},t2:{0}):{0};", name);
            as3api.AppendLine();

            string bitorclass = Properties.Resources.EnumItemBitOr;

            bitorclass = bitorclass.Replace("{0}", GetEnumBitOrFuncName());
            bitorclass = bitorclass.Replace("{1}", NativeCodeCreatorBase.GetTypeFullName(type));
            nativefuncClasses.Add(bitorclass);

            //regfunctions.Add("\t\t\tbin.regNativeFunction(new "+ GetEnumBitOrFuncName() +"());");
            regfunctions.Add("\t\t\tbin.regNativeFunction(\"" + LinkCodeNampScapePart + GetEnumBitOrFuncName() + "\",\"" + GetEnumBitOrFuncName() + "\");");


            EndClassDefine(as3api);
            EndAS3File(as3api);


            for (int i = 0; i < regfunctions.Count; i++)
            {
                nativefunc.AppendLine(regfunctions[i]);
            }

            EndRegFunction(nativefunc);

            for (int i = 0; i < nativefuncClasses.Count; i++)
            {
                nativefunc.AppendLine(nativefuncClasses[i]);
            }

            EndNativeFuncClass(nativefunc);

            //Console.WriteLine(as3api.ToString());

            //Console.WriteLine(nativefunc.ToString());

            string as3file       = as3apidocpath + "/" + GetPackageName(type).Replace(".", "/") + "/" + name + ".as";
            string nativefunfile = csharpnativecodepath + "/" + GetNativeFunctionClassName(type) + ".cs";

            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(as3file));
            System.IO.File.WriteAllText(as3file, as3api.ToString());

            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(nativefunfile));

            StringBuilder usingcode = new StringBuilder();

            GenNativeFuncImport(usingcode);

            System.IO.File.WriteAllText(nativefunfile, usingcode.ToString() + nativefunc.ToString());

            return(nativefunc.ToString());
        }
        public string GetCode()
        {
            string funccode = Properties.Resources.StaticFieldGetter;

            funccode = funccode.Replace("[classname]", classname);
            funccode = funccode.Replace("[returntype]", GetAS3RuntimeTypeString(field.FieldType));
            string pushparas = string.Empty;

            string getter = string.Empty;

            var rettype = GetAS3Runtimetype(field.FieldType);

            if (rettype == ASBinCode.RunTimeDataType.fun_void)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult += "\t\t\t\t\t;\n";
                storeresult  = storeresult + "\t\t\t\t\treturnSlot.directSet(ASBinCode.rtData.rtUndefined.undefined);";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_int)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "int _result_ = (int)(" + NativeCodeCreatorBase.GetTypeFullName(type) + "." + field.Name;

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_uint)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "uint _result_ = (uint)(" + NativeCodeCreatorBase.GetTypeFullName(type) + "." + field.Name;

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_number)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "double _result_ = (double)(" + NativeCodeCreatorBase.GetTypeFullName(type) + "." + field.Name;

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_string)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "string _result_ = (string)(" + NativeCodeCreatorBase.GetTypeFullName(type) + "." + field.Name;

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_boolean)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "bool _result_ = (bool)" + NativeCodeCreatorBase.GetTypeFullName(type) + "." + field.Name;

                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\tif(_result_)\n";
                storeresult += "\t\t\t\t\t{\n";
                storeresult += "\t\t\t\t\t\treturnSlot.setValue(ASBinCode.rtData.rtBoolean.True);\n";
                storeresult += "\t\t\t\t\t}\n";
                storeresult += "\t\t\t\t\telse\n";
                storeresult += "\t\t\t\t\t{\n";
                storeresult += "\t\t\t\t\t\treturnSlot.setValue(ASBinCode.rtData.rtBoolean.False);\n";
                storeresult += "\t\t\t\t\t}\n";


                funccode = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype > ASBinCode.RunTimeDataType.unknown)
            {
                if (field.FieldType.IsValueType)
                {
                    string storeresult = string.Empty;
                    //***调用方法****
                    storeresult = GetTypeFullName(field.FieldType) + " _result_ = " + NativeCodeCreatorBase.GetTypeFullName(type) + "." + field.Name;

                    storeresult += "\t\t\t\t\t;\n";
                    //storeresult += "\t\t\t\t\tstackframe.player.linktypemapper.storeLinkObject_ToSlot(_result_, functionDefine.signature.returnType, returnSlot, bin, stackframe.player);";
                    storeresult += "\t\t\t\t\t((StackSlot)returnSlot).setLinkObjectValue(bin.getClassByRunTimeDataType(functionDefine.signature.returnType), stackframe.player, _result_);";

                    funccode = funccode.Replace("[storeresult]", storeresult);
                }
                else
                {
                    string storeresult = string.Empty;
                    //***调用方法****
                    storeresult = "object _result_ = " + NativeCodeCreatorBase.GetTypeFullName(type) + "." + field.Name;

                    storeresult += "\t\t\t\t\t;\n";
                    storeresult += "\t\t\t\t\tstackframe.player.linktypemapper.storeLinkObject_ToSlot(_result_, functionDefine.signature.returnType, returnSlot, bin, stackframe.player);";
                    funccode     = funccode.Replace("[storeresult]", storeresult);
                }
            }
            else
            {
                funccode = funccode.Replace("[storeresult]", "代码生成错误,不能转换返回类型");
            }



            return(funccode);
        }
예제 #9
0
        public string GetCode()
        {
            System.Reflection.ParameterInfo[] paras;
            if (constructor != null)
            {
                paras = constructor.GetParameters();
            }
            else
            {
                paras = new System.Reflection.ParameterInfo[0];
            }

            string funccode = Properties.Resources.CtorFunc;

            funccode = funccode.Replace("[classname]", classname);
            funccode = funccode.Replace("[paracount]", paras.Length.ToString());

            string pushparas = string.Empty;

            for (int i = 0; i < paras.Length; i++)
            {
                var para = paras[i];

                pushparas = pushparas + "\t\t\t\t" + string.Format("para.Add({0});\n", GetAS3RuntimeTypeString(para.ParameterType));
            }

            funccode = funccode.Replace("[pushparas]", pushparas);


            string loadargs = string.Empty;

            for (int i = 0; i < paras.Length; i++)
            {
                var argement = paras[i];

                loadargs = loadargs + GetLoadArgementString(argement);
                loadargs = loadargs + "\n";
            }

            funccode = funccode.Replace("[loadargement]", loadargs);


            string setnativeinstance = string.Empty;

            if (type.IsValueType)
            {
                //((LinkObj<UInt64>)((ASBinCode.rtData.rtObjectBase)thisObj).value).value = (UInt64)value;
                setnativeinstance = "((LinkObj<" + GetTypeFullName(type) + ">)((ASBinCode.rtData.rtObjectBase)thisObj).value).value = ";
            }
            else
            {
                setnativeinstance = "((LinkObj<object>)((ASBinCode.rtData.rtObjectBase)thisObj).value).value = ";
            }



            string newobj = "new ";

            newobj += NativeCodeCreatorBase.GetTypeFullName(type);
            newobj += "(";

            for (int i = 0; i < paras.Length; i++)
            {
                newobj += string.Format("({0})arg{1}", GetTypeFullName(paras[i].ParameterType), i);
                if (i < paras.Length - 1)
                {
                    newobj += ",";
                }
            }

            newobj += ");";

            setnativeinstance += newobj;

            funccode = funccode.Replace("[setnativeinstance]", setnativeinstance);
            return(funccode);
        }