public static bool NeedCallThis(SymbolBase symbol) { if (symbol is SymbolLocalVar) { return(false); } else if (symbol is SymbolArg) { return(false); } else if (symbol is SymbolDefProperty) { SymbolDefProperty symbol2 = (symbol as SymbolDefProperty); return(symbol2.IsStatic == false); } else if (symbol is SymbolDefField) { SymbolDefField symbol2 = (symbol as SymbolDefField); return(symbol2.IsStatic == false); } else if (symbol is SymbolRefStaticMember) { return(false); } else { throw new CompileException(); } }
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(); } }
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); }
//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 CompileName(ClassContext classContext, bool isStatic) { if (TypeToken == null || NameToken == null) { TrueAnalyed = false; return; } IsStatic = isStatic; this.ClassContext = classContext; var symbols = ClassContext.Symbols; TypeName = TypeToken.GetText(); PropertyName = NameToken.GetText(); PropertyGcl = classContext.SearchType(TypeName); if (PropertyGcl != null) { PropertyType = PropertyGcl.ForType; } else { errorf("没有找到类型'{0}'", TypeName); } if (ClassContext.ClassSymbol.PropertyDict.ContainsKey(PropertyName)) { error("属性'" + PropertyName + "'已经存在"); return; } if (PropertyType == null) { error("属性类型'" + TypeName + "'不存在"); return; } PropertySymbol = new SymbolDefProperty(PropertyName, PropertyType, isStatic); symbols.AddSafe(PropertySymbol); ClassContext.ClassSymbol.PropertyDict.Add(PropertyName, PropertySymbol); var classBuilder = ClassContext.EmitContext.CurrentTypeBuilder; GenerateName(classBuilder, IsStatic); AnalyBody(classContext); }
public static bool EmitSet_Storm(ILGenerator il, SymbolInfo symbol) { if (symbol is SymbolVar) { EmitHelper.StormVar(il, (symbol as SymbolVar).VarBuilder); } else if (symbol is SymbolArg) { EmitHelper.StormArg(il, (symbol as SymbolArg).ArgIndex); } else if (symbol is SymbolPropertyDirect) { SymbolPropertyDirect prsymbol = symbol as SymbolPropertyDirect; MethodInfo setMethod = prsymbol.ExProperty.Property.GetSetMethod(); EmitHelper.CallDynamic(il, setMethod, prsymbol.ExProperty.IsSelf); } else if (symbol is SymbolDefProperty) { SymbolDefProperty prsymbol = (symbol as SymbolDefProperty); MethodInfo setMethod = prsymbol.GetProperty().GetSetMethod(); EmitHelper.CallDynamic(il, setMethod, true); } else if (symbol is SymbolDefField) { SymbolDefField prsymbol = (symbol as SymbolDefField); EmitHelper.StormField(il, prsymbol.GetField()); } else if (symbol is SymbolFieldDirect) { SymbolFieldDirect fymbol = symbol as SymbolFieldDirect; EmitHelper.StormField(il, fymbol.ExField.Field); } else { return(false); } return(true); }
public void AnalyName(NameTypeParser parser, PropertyContextCollection context, ContextClass classContext) { this.FileContext = classContext.FileContext; NameTypeParser.ParseResult result = parser.ParseVar(NameToken); if (result != null) { PropertyName = result.TypeName; PropertyZType = result.ZType; if (context.Dict.ContainsKey(PropertyName)) { ErrorE(NameToken.Position, "属性'{0}'重复", PropertyName); } else { WordInfo word = new WordInfo(PropertyName, WordKind.MemberName, this); context.Dict.Add(word); } PropertySymbol = new SymbolDefProperty(PropertyName, PropertyZType, classContext.IsStaticClass); PropertySymbol.HasDefaultValue = true; classContext.MemberDictionary.Add(PropertySymbol); } }
public static bool EmitSet_Load(ILGenerator il, SymbolInfo symbol) { if (symbol is SymbolDefProperty) { SymbolDefProperty prsymbol = (symbol as SymbolDefProperty); if (!prsymbol.IsStatic) { il.Emit(OpCodes.Ldarg_0); } } else if (symbol is SymbolDefField) { SymbolDefField prsymbol = (symbol as SymbolDefField); if (!prsymbol.IsStatic) { il.Emit(OpCodes.Ldarg_0); } } else { return(false); } return(true); }
public override Exp Analy(AnalyExpContext context) { base.Analy(context); var symbols = this.AnalyExpContext.Symbols; VarName = VarToken.GetText(); if (!IsNestedField) { if (VarSymbol == null) { VarSymbol = symbols.Get(VarName); } if (VarSymbol == null) { //VarSymbol = symbols.Get(VarName); List <SymbolEnumItem> enumValues = context.ClassContext.SearchEnumItem(VarName); if (enumValues.Count == 1) { VarSymbol = enumValues[0]; } if (enumValues.Count > 1) { errorf("'{0}'有多个相同约定值", VarName); return(null); } } if (VarSymbol == null) { if (context.ClassContext.ClassSymbol.BaseGcl != null) { ExPropertyInfo property = context.ClassContext.ClassSymbol.BaseGcl.SearchExProperty(VarName); if (property != null) { if (ReflectionUtil.IsPublic(property.Property) || ReflectionUtil.IsProtected(property.Property)) { SymbolDefProperty ps = new SymbolDefProperty(VarName, property.Property.PropertyType, ReflectionUtil.IsStatic(property.Property)); ps.SetProperty(property.Property); VarSymbol = ps; } } } } if (VarSymbol == null) { if (context.ClassContext.ClassSymbol.BaseGcl != null) { ExFieldInfo field = context.ClassContext.ClassSymbol.BaseGcl.SearchExField(VarName); if (field != null) { if (field.Field.IsPublic || field.Field.IsFamily) { SymbolDefField fs = new SymbolDefField(VarName, field.Field.FieldType, field.Field.IsStatic); fs.SetField(field.Field); VarSymbol = fs; } } } } if (VarSymbol == null) { if (IsAssignedBy) { SymbolVar varSymbol = new SymbolVar(VarName); if (!varSymbol.IsInBlock) { varSymbol.LoacalVarIndex = context.StmtContext.MethodContext.CreateLocalVarIndex(VarName); symbols.Add(varSymbol); } VarSymbol = varSymbol; } else { errorf("'{0}'没有赋值", VarName); return(null); } } RetType = ((InstanceSymbol)VarSymbol).DimType; } else { } return(this); }