public void AddAttribute(ObjectInfo objTemp) { if (!string.IsNullOrEmpty(objTemp.Code)) { AttributeInfo attr = new AttributeInfo(); attr.Store(objTemp); this.Attributes.Add(attr); } }
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); } }