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()); }
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); }
bool analyCallBody() { ExpProcDesc = new TKTProcDesc(); int i = 0; for (; i < this.Elements.Count; i++) { var exp = this.Elements[i]; if (exp is FTextExp) { ExpProcDesc.Add((exp as FTextExp).IdentToken.GetText()); } else if (exp is BracketExp) { var bexp = exp as BracketExp; var exp2 = bexp.Analy(this.AnalyExpContext); if (exp2 != null && exp2.TrueAnalyed) { Elements[i] = exp2; ExpProcDesc.Add(bexp.GetDimArgs()); } else { return(false); } } } return(true); }
public string CreateMethodName() { TKTProcDesc ProcDesc = MethodAST.MethodContext.ProcDesc; List <string> list = new List <string>(); for (int i = 0; i < ProcDesc.Parts.Count; i++) { if (ProcDesc.Parts[i] is string) { list.Add(ProcDesc.Parts[i] as string);; } else if (ProcDesc.Parts[i] is FnBracket) { var fnBracket = (ProcDesc.Parts[i] as FnBracket); if (fnBracket.Args.Count > 0) { foreach (var arg in fnBracket.Args) { list.Add(arg.ArgTypeToken.GetText()); } } } } string str = string.Join("", list); //if(str!="启动") //{ // //str = str + "_" + this.MethodAST.MethodContext.MethodIndex; //} return(str); }
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); }
public V Get(TKTProcDesc procDesc) { foreach (TKTProcDesc key in dict.Keys.ToList()) { if (key.Eq(procDesc)) { return(dict[key]); } } return(default(V)); }
protected void GenerateArgsExp(EmitExpContext context, TKTProcDesc expProcDesc, TKTProcDesc searchedProcDesc, int size) { for (int i = 0; i < size; i++) { var arg = expProcDesc.GetArg(i); var exp = (arg.Value as Exp); TKTProcArg procArg = searchedProcDesc.GetArg(i); exp.RequireType = procArg.ArgType; exp.Generate(context); } }
public TKTProcDesc SearchProc(TKTProcDesc procDesc) { foreach (TKTProcDesc key in dict.Keys.ToList()) { if (key.Eq(procDesc)) { return(key); } } return(null); }
public bool Contains(TKTProcDesc procDesc) { foreach (TKTProcDesc key in dict.Keys.ToList()) { if (key.Eq(procDesc)) { return(true); } } return(false); }
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); }
public static TKTProcDesc[] SearchDirectProc(ClassContext context, TKTProcDesc procDesc) { List <TKTProcDesc> list = new List <TKTProcDesc>(); foreach (var tktClass in context.ImportContext.DirectClasses) { var temp = tktClass.SearchProc(procDesc); if (temp != null) { list.Add(temp); } } return(list.ToArray()); }
public void AnalyBody(ClassContext classContext) { if (ValueExp != null) { MethodContext methodContext = new MethodContext(ClassContext, PropertyName); var symbols = ClassContext.Symbols; AnalyStmtContext stmtContext = new AnalyStmtContext(methodContext, PropertyName); AnalyExpContext expContext = new AnalyExpContext(stmtContext); ValueExp = ValueExp.Analy(expContext); if (ValueExp == null) { return; } if (!ReflectionUtil.IsExtends(ValueExp.RetType, PropertyType)) { error("属性值的类型不正确"); } } else { if (PropertyType.IsValueType) { newCode = 4; } else { List <TKTProcArg> args = new List <TKTProcArg>(); ProcDesc = new TKTProcDesc(); ProcDesc.Add(PropertyGcl.ShowName); ProcDesc.Add(args); TKTProcDesc newProcDesc = searchNewProc(classContext, ProcDesc); if (newProcDesc != null) { newCode = 3; } else { ConstructorDesc = new TKTConstructorDesc(args); TKTConstructorDesc realDesc = PropertyGcl.SearchConstructor(ConstructorDesc); if (realDesc != null) { ConstructorDesc.Constructor = realDesc.Constructor; newCode = 2; } } } } }
string getMethodName(bool isStatic) { if (!isStatic) { if (this.ClassContext.ClassSymbol.BaseGcl != null) { TKTProcDesc desc = this.ClassContext.ClassSymbol.BaseGcl.SearchProc(this.FnName.ProcDesc); if (desc != null) { return(desc.ExMethod.Method.Name); } } } return(FnName.CreateMethodName()); }
public static Tuple <string, Type[]> CreateMethodDesc(TKTProcDesc procDesc) { if (procDesc.Parts.Count > 0 && procDesc.Parts[0] is string) { string methodName = procDesc.Parts[0] as string; if (methodName == null) { return(null); } Type[] types = procDesc.GetArgTypes(0).ToArray(); return(new Tuple <string, Type[]>(methodName, types)); } else { return(null); } }
public TKTProcDesc SearchProc(TKTProcDesc procDesc) { var methodArray = MType.GetMethods(/*BindingFlags.DeclaredOnly*/); foreach (var method in methodArray) { if (ReflectionUtil.IsDeclare(MType, method)) { TKTProcDesc typeProcDesc = ProcDescHelper.CreateProcDesc(method); if (typeProcDesc.Eq(procDesc)) { return(typeProcDesc); } } } return(null); }
bool AnlayNameBody(int startArgIndex) { var symbols = MethodAST.MethodContext.Symbols; ProcDesc = new TKTProcDesc(); int argIndex = startArgIndex; for (int i = 0; i < NameTerms.Count; i++) { var term = NameTerms[i]; if (term is FnText) { var textterm = term as FnText; textterm.Analy(this); ProcDesc.Add(textterm.TextContent); } else if (term is FnBracket) { var argterm = term as FnBracket; List <TKTProcArg> procArgs = new List <TKTProcArg>(); foreach (var arg in argterm.Args) { bool b = arg.Analy(this, argIndex); if (b) { TKTProcArg procArg = new TKTProcArg(arg.ArgName, arg.ArgType, arg.IsGenericArg); procArgs.Add(procArg); argIndex++; } else { return(false); } } ProcDesc.Add(procArgs); } } if (!checkName()) { return(false); } MethodAST.MethodContext.ProcDesc = ProcDesc; MethodAST.MethodContext.ClassContext.ClassSymbol.AddMethod(MethodAST.MethodContext); return(true); }
TKTProcDesc searchNewProc(ClassContext classContext, TKTProcDesc expProcDesc) { var procArray = ClassContextHelper.SearchProc(classContext, expProcDesc); if (procArray.Length == 1) { return(procArray[0]); } else if (procArray.Length > 1) { error("找到多个过程,不能确定是属于哪一个简略使用的类型的过程"); } else if (procArray.Length == 0) { //error("没有找到对应的过程'" + this.ToCode() + "'"); } return(null); }
public TKTProcDesc SearchProc(/*SymbolTable table, */ TKTProcDesc procDesc) { TKTProcDesc proc = MethodDict.SearchProc(procDesc); if (proc != null) { proc.ExMethod = new ExMethodInfo(MethodDict.Get(proc).EmitContext.CurrentMethodBuilder, true); } else if (parentClass != null) { proc = parentClass.SearchProc(procDesc); } else if (BaseGcl != null) { proc = BaseGcl.SearchProc(procDesc); } return(proc); }
public TKTProcDesc Parser(CnEnDict wordDict, string code) { this.WordDict = wordDict; i = 0; desc = new TKTProcDesc(); Code = code; while (i < Code.Length) { if (ch == '(') { parseBracket(); } else { parseText(); } } return(desc); }
public static TKTProcDesc[] SearchSuppleProc(ClassContext context, TKTProcDesc procDesc) { var symbols = context.Symbols; //1.寻找当前CLASS内的PROC var method = context.ClassSymbol.SearchProc(procDesc); if (method != null) { return new TKTProcDesc[] { method } } ; //2.寻找简略使用的PROC var directProcArray = SearchDirectProc(context, procDesc); if (directProcArray.Length > 0) { return(directProcArray); } return(new TKTProcDesc[] { }); }
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); }
public override Exp Analy(AnalyExpContext context) { base.Analy(context); classContext = context.StmtContext.MethodContext.ClassContext; var symbols = this.AnalyExpContext.Symbols; if (!analyCallBody()) { return(null); } searchedProcDesc = searchProc(classContext); if (searchedProcDesc == null) { errorf("没有找到过程'{0}'", this.ToCode()); return(null); } searchedProcDesc.AdjustBracket(ExpProcDesc); CallExMethod = searchedProcDesc.ExMethod; if (CallExMethod == null) { return(null); } RetType = CallExMethod.Method.ReturnType; analyGeneric(); analyArgLanmbda(context); if (isSubjectEveryOneExp()) { InvokeEveryoneSubejctExp ieoexp = new InvokeEveryoneSubejctExp(this); Exp ioeResultExp = ieoexp.Analy(context); return(ioeResultExp); } else if (isObjectEveryOneExp()) { InvokeEveryoneObejctExp ieoexp = new InvokeEveryoneObejctExp(this); Exp ioeResultExp = ieoexp.Analy(context); return(ioeResultExp); } return(this); }
Tuple <Exp, int> analyCall(AnalyExpContext context) { TKTProcDesc procdesc = new TKTProcDesc(); procdesc.Add(IdentName); var procArray = ClassContextHelper.SearchProc(classContext, procdesc); if (procArray.Length == 1) { InvokeSimplestExp exp = new InvokeSimplestExp(this, IdentToken, procArray[0]); return(new Tuple <Exp, int> (exp, 1)); } else if (procArray.Length == 0) { return(new Tuple <Exp, int>(null, 0)); } else { errorf("有多个相同名称'{0}'过程,不能确定是哪个过程", IdentName); return(new Tuple <Exp, int>(null, procArray.Length)); } }
TKTProcDesc searchProc(ClassContext classContext) { var procArray = ClassContextHelper.SearchProc(classContext, ExpProcDesc); if (procArray.Length == 1) { //procArray[0].AdjustBracket(procDesc); return(procArray[0]); } else if (procArray.Length > 1) { error("找到多个过程,不能确定是属于哪一个简略使用的类型的过程"); } else if (procArray.Length == 0) { if (Elements[0] is BracketExp) { SubjectExp = Elements[0]; subjType = SubjectExp.RetType; ExpProcDesc = ExpProcDesc.CreateTail(); procArray = ClassContextHelper.SearchProc(classContext, subjType, ExpProcDesc); if (procArray.Length == 1) { return(procArray[0]); } else if (procArray.Length == 0) { error("没有找到对应的过程'" + this.ToCode() + "'"); } else if (procArray.Length > 1) { error("找到多个过程,不能确定是属于哪一个简略使用的类型的过程:'" + this.ToCode() + "'"); } } } return(null); }
public static TKTProcDesc[] SearchProc(ClassContext context, Type subjType, TKTProcDesc procDesc) { var symbols = context.Symbols; //3.根据主语对象寻找当前项目的PROC if (!(subjType is TypeBuilder)) { var gcl = context.ImportContext.SearchGCL(subjType); if (gcl != null) { TKTProcDesc getedDesc = gcl.SearchProc(procDesc); if (getedDesc == null) { return(new TKTProcDesc[] { }); } else { return(new TKTProcDesc[] { getedDesc }); } } } else//3.根据主语对象寻找开发包的PROC { string name = subjType.Name; SymbolInfo symbol = symbols.Get(name); if (symbol is SymbolDefClass) { var proc3 = (symbol as SymbolDefClass).SearchProc(procDesc); if (proc3 != null) { return(new TKTProcDesc[] { proc3 }); } } } return(new TKTProcDesc[] { }); }
public TKTProcDesc SearchProc(TKTProcDesc procDesc) { var methodArray = MType.GetMethods(/*BindingFlags.DeclaredOnly*/); foreach (var method in methodArray) { if (ReflectionUtil.IsDeclare(MType, method)) { MappingCodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(MappingCodeAttribute)) as MappingCodeAttribute; if (procAttr == null) { TKTProcDesc typeProcDesc = ProcDescHelper.CreateProcDesc(method); if (typeProcDesc.Eq(procDesc)) { return(typeProcDesc); } } else { ProcDescCodeParser parser = new ProcDescCodeParser(); ParameterInfo[] paramArray = method.GetParameters(); foreach (var param in paramArray) { parser.AddType(param.ParameterType); } TKTProcDesc typeProcDesc = parser.Parser(WordDict, procAttr.Code); if (typeProcDesc.Eq(procDesc)) { typeProcDesc.Method = method; return(typeProcDesc); } } } } return(null); }
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)); } }
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)); } }
public InvokeSimplestExp(Exp srcExp, Token token, TKTProcDesc procdesc) : base(srcExp) { ProcToken = token; ProcDesc = procdesc; }
public override Exp Analy(AnalyExpContext context) { base.Analy(context); var classContext = context.StmtContext.MethodContext.ClassContext; var symbols = this.AnalyExpContext.Symbols; BrackestArgs = BrackestArgs.Analy(context) as BracketExp; if (!BrackestArgs.TrueAnalyed) { return(null); } Type subjectType = SubjectGCL.ForType; if (subjectType.FullName.StartsWith(CompileConstant.LangPackageName + ".列表`1[")) { newCode = 1; ConstructorDesc = new TKTConstructorDesc(); var Constructor = subjectType.GetConstructor(new Type[] {}); if (Constructor == null) { error(BrackestArgs.Postion, "没有正确的创建过程"); return(null); } else { RetType = subjectType; ConstructorDesc.Constructor = Constructor; Type[] genericTypes = GenericUtil.GetInstanceGenriceType(subjectType, typeof(列表 <>)); Type ElementType = genericTypes[0]; var args = BrackestArgs.GetDimArgs(); for (int i = 0; i < args.Count; i++) { Exp arg = args[i].Value as Exp; if (arg.RetType != ElementType && !ReflectionUtil.IsExtends(arg.RetType, ElementType)) { errorf(arg.Postion, "类型不是列表的子类型,不能添加"); } } } } else { var args = BrackestArgs.GetDimArgs(); ProcDesc = new TKTProcDesc(); ProcDesc.Add(SubjectGCL.ShowName); ProcDesc.Add(args); TKTProcDesc newProcDesc = searchNewProc(classContext, ProcDesc); if (newProcDesc != null) { newProcDesc.AdjustBracket(ProcDesc);// ProcDesc.AdjustBracket(newProcDesc); ProcDesc.ExMethod = newProcDesc.ExMethod; newCode = 3; RetType = ProcDesc.ExMethod.Method.ReturnType; } else { ConstructorDesc = new TKTConstructorDesc(args); TKTConstructorDesc realDesc = SubjectGCL.SearchConstructor(ConstructorDesc); if (realDesc == null) { error(BrackestArgs.Postion, "没有正确的创建过程"); return(null); } else { RetType = SubjectGCL.ForType; realDesc.AdjustBracket(ConstructorDesc); ConstructorDesc.Constructor = realDesc.Constructor; newCode = 2; } } } return(this); }