public static void EmitStorm(ILGenerator il, SymbolBase symbol) { if (symbol is SymbolLocalVar) { var symbolVar = symbol as SymbolLocalVar; EmitHelper.StormVar(il, symbolVar.VarBuilder); } else if (symbol is SymbolArg) { SymbolArg argsymbol = (symbol as SymbolArg); EmitHelper.StormArg(il, argsymbol.ArgIndex); } else if (symbol is SymbolDefProperty) { SymbolDefProperty symbol2 = (symbol as SymbolDefProperty); MethodInfo setMethod = symbol2.Property.GetSetMethod(); EmitHelper.CallDynamic(il, setMethod); } else if (symbol is SymbolDefField) { SymbolDefField symbol2 = (symbol as SymbolDefField); EmitHelper.StormField(il, symbol2.Field); } else if (symbol is SymbolRefStaticMember) { EmitStorm(il, symbol as SymbolRefStaticMember); } else { throw new CompileException(); } }
//public static void CallDynamic(ILGenerator il, MethodInfo method) //{ //il.Emit(OpCodes.Callvirt, method); /*if (method.IsAbstract || method.IsVirtual) * { * il.Emit(OpCodes.Callvirt, method); * } * else * { * il.Emit(OpCodes.Call, method); * }*/ /* Console.WriteLine(string.Format("{0} IsStatic:{1}", method.Name, method.IsStatic)); * if (method.IsStatic) * { * il.Emit(OpCodes.Call, method); * } * else * { * il.Emit(OpCodes.Callvirt, method); * } * }*/ /* * public static void CallDynamic(ILGenerator il, MethodInfo method,Type objType) * { * if (objType == method.DeclaringType) * il.Emit(OpCodes.Call, method); * else * il.Emit(OpCodes.Callvirt, method); * }*/ public static bool EmitSymbolGet(ILGenerator il, SymbolInfo symbol) { if (symbol is SymbolVar) { var symbolVar = symbol as SymbolVar; EmitHelper.LoadVar(il, symbolVar.VarBuilder); } else if (symbol is SymbolArg) { SymbolArg argsymbol = (symbol as SymbolArg); il.Emit(OpCodes.Ldarg, argsymbol.ArgIndex); } else if (symbol is SymbolEnumItem) { SymbolEnumItem eisymbol = (symbol as SymbolEnumItem); EmitHelper.LoadInt(il, (int)eisymbol.EnumValue); } else if (symbol is SymbolPropertyDirect) { SymbolPropertyDirect prsymbol = symbol as SymbolPropertyDirect; MethodInfo getMethod = prsymbol.ExProperty.Property.GetGetMethod(); EmitHelper.CallDynamic(il, getMethod, prsymbol.ExProperty.IsSelf); } else if (symbol is SymbolFieldDirect) { SymbolFieldDirect fymbol = symbol as SymbolFieldDirect; EmitHelper.LoadField(il, fymbol.ExField.Field); } else if (symbol is SymbolDefProperty) { SymbolDefProperty prsymbol = (symbol as SymbolDefProperty); if (!prsymbol.IsStatic) { il.Emit(OpCodes.Ldarg_0); } MethodInfo getMethod = prsymbol.GetProperty().GetGetMethod(); EmitHelper.CallDynamic(il, getMethod, true); } else if (symbol is SymbolDefField) { SymbolDefField prsymbol = (symbol as SymbolDefField); if (!prsymbol.IsStatic) { il.Emit(OpCodes.Ldarg_0); } //il.Emit(OpCodes.Ldfld, prsymbol.Builder); EmitHelper.LoadField(il, prsymbol.GetField()); } else if (symbol is SymbolDefClass) { return(true); } else { return(false); } return(true); }
public void Analy(NameTypeParser parser) { ArgText = ArgToken.GetText(); if (AnalyNameType(parser)) { SymbolArg argSymbol = new SymbolArg(ArgName, ArgZType, this.ProcContext.CreateArgIndex(ArgName)); this.ProcContext.Symbols.Add(argSymbol); WordInfo word = new WordInfo(ArgName, WordKind.ArgName, this); this.ProcContext.ProcVarWordDictionary.Add(word); } }
public bool AnalyRet( ) { var methodContext = this.MethodAST.MethodContext; var symbols = MethodAST.MethodContext.Symbols; if (RetToken == null) { methodContext.RetType = typeof(void); } else { string retName = RetToken.GetText(); SymbolInfo symbol = symbols.Get(retName); if (symbol is SymbolArg) { SymbolArg argSymbol = symbol as SymbolArg; if (argSymbol.IsGeneric) { IsGenericRet = true; GenericRetIndex = argSymbol.ArgIndex; methodContext.RetType = typeof(object); methodContext.RetIsGeneric = true; } else { error("非‘类型’的参数不能用作返回类型"); return(false); } } else if (symbol is SymbolDefClass) { methodContext.RetType = (symbol as SymbolDefClass).GetRealType(); } else { IGcl gcl = this.MethodAST.ClassContext.SearchType(retName); if (gcl != null) { methodContext.RetType = gcl.ForType; } else { errorf("返回结果'{0}'不是类型", retName); return(false); } } } return(true); }
public bool Analy(FnName fn, int argIndex) { var symbols = fn.MethodAST.MethodContext.Symbols; if (ArgTypeToken != null && ArgNameToken != null) { ArgName = ArgNameToken.GetText(); if (ArgTypeToken.IsKeyIdent("类型")) { ArgType = typeof(object); IsGenericArg = true; } else { IsGenericArg = false; string argTypeName = ArgTypeToken.GetText(); SymbolInfo symbol = symbols.Get(argTypeName); if (symbol != null) { SymbolDefClass defClass = symbol as SymbolDefClass; if (defClass != null) { ArgType = defClass.ClassBuilder; } } if (ArgType == null) { //var gcls = fn.MethodAST.MethodContext.ClassContext.ImportContext.SearchGCL(argTypeName); //if (gcls.Length == 1) //{ // ArgType = gcls[0].ForType; //} var gcl = fn.MethodAST.MethodContext.ClassContext.SearchType(argTypeName); // if (gcl != null) { ArgType = gcl.ForType; } if (ArgType == null) { error(string.Format("不存在或者不确定'{0}'类型", argTypeName)); return(false); } } } if (ArgType != null) { if (symbols.Contains(ArgName)) { errorf("'{0}'已经存在相同的名称", ArgName); return(false); } else { SymbolArg argSymbol = new SymbolArg(ArgName, ArgType, argIndex, IsGenericArg); symbols.AddSafe(argSymbol); } } } else { error("参数不正确"); return(false); } return(true); }