/// <summary> /// Only compare C++ interface body and C interface body, not Guid /// Since we only output the differences of methods /// </summary> /// <returns>The target object equals to current one</returns> public override bool Equals(object obj) { InterfaceObject target = (InterfaceObject)obj; return(target != null && this.cplusplusContent == target.cplusplusContent && this.cContent == target.cContent); }
/// <summary> /// Compare interfaces which defined in previous release with current build /// If it is found, compare the interface /// If the content of same interface are differrent /// Compare and output the different methods /// </summary> /// <param name="target">Interfaces Object</param> /// <returns>Differences of interfaces</returns> public List <string> Compare(Interfaces target) { if (this.Count == 0 || target == null || target.Count == 0) { return(null); } List <string> differences = new List <string>(); // Search interfaces which defined in previous release from current build // If it is found, compare the interface // If the content of same interface are differrent // Compare and output the different methods foreach (KeyValuePair <string, InterfaceObject> pair in this.infos) { string name = pair.Key; if (target.infos.ContainsKey(name)) { InterfaceObject cur = target[name]; InterfaceObject pre = pair.Value; if (!pre.Equals(cur)) { Methods curMethods = ValidationHelper.ParseMethodInformation(cur.CplusplusContent); Methods preMethods = ValidationHelper.ParseMethodInformation(pre.CplusplusContent); string difference = preMethods.Compare(curMethods); LogHelper.Log("Differences of {0}:", name); LogHelper.Log(difference); differences.Add(difference); } } } return(differences); }
/// <summary> /// Read all content of .h and parse interface body /// </summary> /// <param name="lines">Content of .h file</param> /// <param name="interfaces">InterfaceObject collection</param> public static void ParseInterfaceBody(List <string> lines, Interfaces interfaces) { LogHelper.Log("Start parsing interface content:"); const string sFlag = "MIDL_INTERFACE"; const string cplusplusEFlag = "};"; const string cEnd = "Vtbl;"; const char space = ' '; // Parse Guid // MIDL_INTERFACE(" const int startIndex = 16; // skip to C++ interface body const int cppCursor = 2; // skip to C interface body const int cCursor = 4; Dictionary <Guid, string> ids = new Dictionary <Guid, string>(); int i = 0; while (i < lines.Count) { // Read till interface definition if (!lines[i].Contains(sFlag)) { i++; continue; } InterfaceObject ic = new InterfaceObject(); string line = lines[i++]; string guid = line.Substring(startIndex, line.Length - startIndex - 2); Guid id = new Guid(guid); ic.ID = id; StringBuilder sb = new StringBuilder(); // Parse interface name string name = lines[i].Split(space)[0]; ic.Name = name; // Save Guid and interfaces to dictionary if (!ids.ContainsKey(id)) { ids.Add(id, name); } else if (interfaces.SameGuidInterfaces.ContainsKey(id)) { interfaces.SameGuidInterfaces[id].Add(name); } else { interfaces.SameGuidInterfaces.Add(id, new List <string>() { ids[id] }); interfaces.SameGuidInterfaces[id].Add(name); } // skip to methods i += cppCursor; while (i < lines.Count && !lines[i].Contains(cplusplusEFlag)) { sb.AppendLine(lines[i++]); } ic.CplusplusContent = sb.ToString(); // skip to BEGIN_INTERFACE i += cCursor; sb.Clear(); while (i < lines.Count && !lines[i].Contains(cEnd)) { sb.AppendLine(lines[i]); i++; } ic.CContent = sb.ToString(); if (interfaces.ContainsName(name)) { interfaces[name] = ic; } i++; } LogHelper.Log("Complete parsing interface content."); }
public void Add(string name, InterfaceObject io) { this.infos.Add(name, io); }