public void AddMethord(ObjectInfo objTemp, List<ObjectInfo> paramList) { MethordInfo mi = new MethordInfo(); mi.Store(objTemp); if (paramList.Count > 0) { if (mi.Parameters == null) mi.Parameters = new List<ObjectInfo>(); mi.Parameters.AddRange(paramList); } if (string.IsNullOrEmpty(mi.Code) && mi.Type == this.Code) { // 构造函数 mi.Code = mi.Name = mi.Type; mi.Type = ""; } this.Methords.Add(mi); }
public void AddMethord(ObjectInfo objTemp, List <ObjectInfo> paramList) { MethordInfo mi = new MethordInfo(); mi.Store(objTemp); if (paramList.Count > 0) { if (mi.Parameters == null) { mi.Parameters = new List <ObjectInfo>(); } mi.Parameters.AddRange(paramList); } if (string.IsNullOrEmpty(mi.Code) && mi.Type == this.Code) { // 构造函数 mi.Code = mi.Name = mi.Type; mi.Type = ""; } this.Methords.Add(mi); }
public CustomHandlerMethod(MethordInfo aMethod, Operation anOper) : base(null, aMethod.Name, anOper) { base.ProcessAttrs(); }
private void ProcessAType(ref TypeInfo ti, ref string sModifier, string[] list, bool bIsValueType) { string word = NextTokenText(list); ti = new TypeInfo(); ti.Name = ti.Code = word; word = NextTokenText(list); string wordNext = GetTokenText(list, tokenCurrent); if (word == ";") { ti.IsClass = false; return; } ti.IsClass = true; ObjectInfo obj = null, objTemp = new ObjectInfo(), paramObj = new ObjectInfo(); MethordInfo mi = null; List<ObjectInfo> paramList = new List<ObjectInfo>(); AttributeInfo attr = null; bool isTypeBody = false, isMethord = false, isOperator = false; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { switch(word) { case "operator": ReadMethordBody(list, word); objTemp.Clear(); break; case "virtual": case "afx_msg": mi = new MethordInfo(); mi.Virtual = word; break; case "private": case "protected": case "public": sModifier = word; break; case ":": if (isTypeBody) { } else { word = NextTokenText(list); ////obj = new ObjectInfo(); ////switch (word) ////{ //// case "private": //// case "protected": //// case "public": //// obj.Modifier = word; //// word = NextTokenText(list); //// break; //// default: //// break; ////} ////obj.Code = word; ////obj.Name = word; ////ti.Parents.Add(obj); } break; case "(": if (mi == null) mi = new MethordInfo(); isMethord = true; paramList.Clear(); paramObj.Clear(); break; case ")": break; case "}": stack.Pop(); break; case "{": if (isTypeBody) { // 这里应该是方法 // 方法或属性定义结束 if (isMethord) { if (mi != null) { mi.Store(objTemp); if (!string.IsNullOrEmpty(paramObj.Code)) { ObjectInfo param = new ObjectInfo(); param.Store(paramObj); paramList.Add(param); if (mi.Parameters == null) mi.Parameters = new List<ObjectInfo>(); mi.Parameters.AddRange(paramList); } ti.Methords.Add(mi); } } else { if (!string.IsNullOrEmpty(objTemp.Code)) { attr = new AttributeInfo(); attr.Store(objTemp); ti.Attributes.Add(attr); } } objTemp.Clear(); mi = null; attr = null; isMethord = false; ReadMethordBody(list, word); break; } // 类体定义,方法或属性 if (!isTypeBody) { isTypeBody = true; } break; case "DECLARE_DYNCREATE": case "DECLARE_MESSAGE_MAP": // 读取到行尾 word = ReadToLineEnd(list); wordNext = GetTokenText(list, tokenCurrent); continue; case ";": // 方法或属性定义结束 if (isMethord) { if (mi != null) { mi.Store(objTemp); if (!string.IsNullOrEmpty(paramObj.Code)) { ObjectInfo param = new ObjectInfo(); param.Store(paramObj); paramList.Add(param); if (mi.Parameters == null) mi.Parameters = new List<ObjectInfo>(); mi.Parameters.AddRange(paramList); } ti.Methords.Add(mi); } } else { if (!string.IsNullOrEmpty(objTemp.Code)) { attr = new AttributeInfo(); attr.Store(objTemp); ti.Attributes.Add(attr); } } objTemp.Clear(); mi = null; attr = null; isMethord = false; break; case ",": if (isMethord) { if (!string.IsNullOrEmpty(paramObj.Code)) { ObjectInfo param = new ObjectInfo(); param.Store(paramObj); paramList.Add(param); } paramObj.Clear(); } break; default: if (word == ti.Code) { // 构造函数 objTemp.Modifier = sModifier; objTemp.Code = objTemp.Name = word; } else if(word == "~" && GetTokenText(list, tokenCurrent.next) == ti.Code) { // 析构函数 objTemp.Modifier = sModifier; objTemp.Code = objTemp.Name = word + ti.Code; word = NextTokenText(list); } else { if (string.IsNullOrEmpty(objTemp.Type)) { objTemp.Modifier = sModifier; switch (word) { case "const": objTemp.IsConst = true; break; case "inline": break; default: objTemp.Type = word; break; } } else if (string.IsNullOrEmpty(objTemp.Code)) { switch (word) { case "*": case "&": objTemp.Type += word; break; default: objTemp.Code = objTemp.Name = word; break; } } else if (isMethord) { // 一般应该为参数 if (string.IsNullOrEmpty(paramObj.Type)) { paramObj.Modifier = sModifier; if (word == "const") { paramObj.IsConst = true; } else { paramObj.Type = word; } } else if (string.IsNullOrEmpty(paramObj.Code)) { switch(word) { case "*": case "&": paramObj.Type += word; break; default: paramObj.Code = paramObj.Name = word; break; } } } } break; } if (tokenCurrent.next == null) { break; } word = NextTokenText(list); wordNext = GetTokenText(list, tokenCurrent.next); } }
private void CreateMethod(TypeInfo aType, Classifier aCls, MethordInfo aMethod, PdOOM.BasePackage aPckg, Operation anOper, InfluenceTable anInfTable) { Operation operation; if (anOper != null) { operation = anOper; } else { operation = (Operation)aCls.CreateObject(0x18112066, "", -1, true); } operation.Static = aMethod.IsStatic; operation.Visibility = GetTypeVisibility(aMethod.Modifier); //operation.ReturnType = aMethod.Type; //operation.Final = aMethod.IsFinal; if (aMethod.IsGenericMethod) { operation.Generic = true; foreach (TypeParameter parameter in operation.TypeParameters) { parameter.delete(); } ////foreach (Type type in aMethod.GetGenericArguments()) ////{ //// TypeParameter parameter2 = (TypeParameter)operation.CreateObject(0x1811207d, "", -1, true); //// this.ProcessType(type, false); //// TypeMapping mapping = TypeMapping.Retrieve(type); //// parameter2.Name = parameter2.Code = mapping.Name; //// operation.TypeParameters.Add(parameter2); ////} } if (aMethod.IsVirtual) { operation.SetExtendedAttribute("C#.virtual", "true"); } if (aMethod.IsAbstract) { operation.Abstract = true; } new CustomHandlerMethod(aMethod, operation).Convert(); if (anOper == null) { foreach (ObjectInfo info in aMethod.Parameters) { //this.AddParameter(operation, info, aPckg); } } foreach (ObjectInfo type in aMethod.Parameters) { AddParameter(operation, type, null); } try { operation.Code = aMethod.Code; operation.Name = aMethod.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.Code, aMethod.Name }); } } ////bool flag = false; // aMethod.IsConstructor || aMethod.GetType().IsSubclassOf(typeof(ConstructorInfo)); ////if (!flag) ////{ //// MethodInfo info2 = (MethodInfo)aMethod; //// Type returnType = info2.ReturnType; //// if (returnType.IsArray) //// { //// operation.Array = true; //// returnType = returnType.GetElementType(); //// } //// this.ProcessType(returnType, false); //// TypeMapping mapping2 = TypeMapping.Retrieve(returnType); //// if (mapping2.HasClassifier()) //// { //// PdOOM.BaseObject obj2 = ProperRef.Link(NamespaceMapping.Retrieve(aPckg), mapping2); //// operation.UseQualifiedDataType = false; //// operation.ReturnTypeObject = obj2; //// } //// else //// { //// operation.ReturnType = mapping2.Name; //// } //// if ((anInfTable != null) && anInfTable.Contains(info2)) //// { //// anInfTable.Impact(info2, operation); //// } //// if (LZ.Reverse.Info._bVBNet) //// { //// new CustomHandlerReturn(info2, anOper).Convert(); //// } //// bool flag2 = false; //// if (!info2.IsHideBySig && info2.GetBaseDefinition().Equals(info2)) //// { //// string name = info2.Name; //// if (!aType.BaseType.Equals(aType)) //// { //// BindingFlags bindingAttr = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; //// bool flag3 = false; //// foreach (MethodInfo info3 in aType.GetMethods(bindingAttr)) //// { //// if (info3.Name == name) //// { //// flag3 = true; //// break; //// } //// } //// if (flag3) //// { //// flag2 = true; //// } //// } //// } //// //if (info2.GetBaseDefinition().Equals(info2)) //// //{ //// // if (flag2) //// // { //// // if (LZ.Reverse.Info._bVBNet) //// // { //// // operation.SetExtendedAttribute("VB.NET.Shadowing", "Shadows"); //// // } //// // else //// // { //// // operation.SetExtendedAttribute("C#.new", "true"); //// // } //// // } //// // else if (aMethod.IsHideBySig && LZ.Reverse.Info._bVBNet) //// // { //// // operation.SetExtendedAttribute("VB.NET.Shadowing", "Overloads"); //// // } //// //} //// else //// { //// operation.SetExtendedAttribute("C#.override", "true"); //// } ////} ////if (flag) ////{ //// operation.Stereotype = "Constructor"; //// operation.ReturnType = ""; //// operation.InfluentObject = aCls; //// operation.Automatic = true; //// try //// { //// if (LZ.Reverse.Info._bVBNet) //// { //// operation.Name = operation.Code = "New"; //// } //// else //// { //// operation.Name = operation.Code = TypeInfoHelper.GetTypeName(aType); //// } //// return; //// } //// catch (COMException) //// { //// if (LZ.Reverse.Info._bDebug) //// { //// LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.FullName, aMethod.Name }); //// } //// return; //// } ////} ////if (anOper == null) ////{ //// string aName = aMethod.Name; //// if (!LZ.Reverse.Info._bVBNet && ShortenOperator(aMethod.GetParameters().Length, ref aName)) //// { //// operation.Stereotype = "Operator"; //// } //// try //// { //// operation.Name = operation.Code = aName; //// } //// catch (COMException) //// { //// if (LZ.Reverse.Info._bDebug) //// { //// LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.FullName, aMethod.Name }); //// } //// } ////} }
private void CreateMethod(TypeInfo aType, Classifier aCls, MethordInfo aMethod, PdOOM.BasePackage aPckg, Operation anOper, InfluenceTable anInfTable) { Operation operation; if (anOper != null) { operation = anOper; } else { operation = (Operation)aCls.CreateObject(0x18112066, "", -1, true); } operation.Static = aMethod.IsStatic; operation.Visibility = GetTypeVisibility(aMethod.Modifier); operation.ReturnType = aMethod.Type; //operation.Final = aMethod.IsFinal; if (aMethod.IsGenericMethod) { operation.Generic = true; foreach (TypeParameter parameter in operation.TypeParameters) { parameter.delete(); } ////foreach (Type type in aMethod.GetGenericArguments()) ////{ //// TypeParameter parameter2 = (TypeParameter)operation.CreateObject(0x1811207d, "", -1, true); //// this.ProcessType(type, false); //// TypeMapping mapping = TypeMapping.Retrieve(type); //// parameter2.Name = parameter2.Code = mapping.Name; //// operation.TypeParameters.Add(parameter2); ////} } if (aMethod.IsVirtual) { operation.SetExtendedAttribute("C++.virtual", "true"); } if (aMethod.IsAbstract) { operation.Abstract = true; } try { operation.Code = aMethod.Code; operation.Name = aMethod.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.Code, aMethod.Name }); } } new CustomHandlerMethod(aMethod, operation).Convert(); // 添加参数 foreach (ObjectInfo type in aMethod.Parameters) { AddParameter(operation, type, aPckg); } // 防止有重载方法前面改名失败 if (aMethod.Parameters.Count > 0 && operation.Code != aMethod.Code) { try { operation.Code = aMethod.Code; operation.Name = aMethod.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.Code, aMethod.Name }); } } } }