void loadPackage(string packageName, ClassContext classContext) { var refTypes = classContext.ProjectContext.TKTTypes; var libWords = classContext.ProjectContext.LibWords; var genericTypes = classContext.ImportContext.GenericTypes; var importPackages = classContext.ImportContext.importPackages; List <IGcl> list = new List <IGcl>(); foreach (var type in refTypes) { if (type.IsPublic && type.Namespace == packageName) { IGcl gcl = GclUtil.Load(type, getWordDict(libWords, type)); if (gcl != null) { list.Add(gcl); addGeneric(genericTypes, gcl); } } } if (list.Count == 0) { errorf("开发包'{0}'内没有类型", packageName); } else { importPackages.Add(packageName, list); } }
void analyGeneric() { if (CallExMethod.Method.IsGenericMethod) { List <Type> types = findGenericTypes(); CallExMethod = GclUtil.MakeGenericExMethod(CallExMethod, types.ToArray()); } }
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); }
public override void Analy(AnalyStmtContext context) { base.Analy(context); var symbols = this.AnalyStmtContext.Symbols; int foreachIndex = context.MethodContext.CreateForeachIndex(); var propertyName = "Item"; var subjType = ToExp.ListExp.RetType; ExProperty = GclUtil.SearchExProperty(propertyName, subjType);//subjType.GetExProperty(propertyName); PropertyInfo countProperty = subjType.GetProperty("Count"); getCountMethod = countProperty.GetGetMethod(); createForeachSymbols(context, symbols, foreachIndex); setMethod = ExProperty.Property.GetSetMethod(); }
public List <IGcl> searchType(string typeName, ClassContext classContext) { List <IGcl> list = new List <IGcl>(); var refTypes = classContext.ProjectContext.TKTTypes; var libWords = classContext.ProjectContext.LibWords; foreach (var type in refTypes) { if (type.IsPublic && type.Name == typeName) { var gcl = GclUtil.Load(type, getWordDict(libWords, type)); if (gcl != null) { list.Add(gcl); } } } return(list); }
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); }
public override Exp Analy(AnalyExpContext context) { base.Analy(context); var symbols = this.AnalyExpContext.Symbols; SubjectExp = SubjectExp.Analy(context); // AnalyExp(SubjectExp); ArgExp = ArgExp.Analy(context); //AnalyExp(ArgExp); var propertyName = "Item"; var subjType = SubjectExp.RetType; ExProperty = GclUtil.SearchExProperty(propertyName, subjType); //subjType.GetExProperty(propertyName); if (ExProperty == null) { error(SubjectExp.Postion, "不存在索引"); return(null); } else { RetType = ExProperty.Property.PropertyType; } return(this); }
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); }
public override Exp Analy(AnalyExpContext context) { base.Analy(context); if (MemberToken == null) { error("'的'字前面没有对象"); return(null); } if (MemberToken == null) { error("'的'字后面没有属性名称"); return(null); } var symbols = this.AnalyExpContext.Symbols; SubjectExp.IsAssignedBy = this.IsAssignedBy; SubjectExp.IsAssignedValue = this.IsAssignedValue; SubjectExp = SubjectExp.Analy(context); propertyName = MemberToken.GetText(); var subjType = SubjectExp.RetType; if (subjType == null) { return(null); } if (propertyName == "每一个" && subjType.IsGenericType && subjType.GetGenericTypeDefinition() == typeof(Z语言系统.列表 <>)) { EveryOneExp eoexp = new EveryOneExp(); eoexp.ListExp = this.SubjectExp; eoexp.MemberToken = this.MemberToken; Exp eoExp = eoexp.Analy(context); return(eoExp); } else { if (!(subjType is TypeBuilder)) { IGcl obj = context.StmtContext.MethodContext.ClassContext.ImportContext.SearchGCL(subjType); if (obj == null) { //ExProperty = subjType.GetExProperty(propertyName); ExProperty = GclUtil.SearchExProperty(propertyName, subjType); } else { ExProperty = obj.SearchExProperty(propertyName); } } else { string name = subjType.Name; SymbolInfo symbol = symbols.Get(name); if (symbol is SymbolDefClass) { ExProperty = (symbol as SymbolDefClass).GetExProperty(propertyName); //ExProperty = GclUtil.SearchExProperty(propertyName, symbol as SymbolDefClass); } } } if (ExProperty == null) { error(SubjectExp.Postion, "不存在" + propertyName + "属性"); return(null); } else { RetType = ExProperty.Property.PropertyType; } return(this); }