public void ReorderToMatch(FunctionList requestedOrderOfFunctions) { /* Rather not effective implementation * For each item on ordered list, find it in this list, put to temp list, remove from this list * when finished, copy remaining items on this list to temp list * copy temp list to this list */ FunctionList tempList = new FunctionList(); foreach (Function ordered in requestedOrderOfFunctions) { foreach (Function current in this) { if ((current.Name == ordered.Name) && current.ReturnType == ordered.ReturnType) { tempList.Add(current); this.Remove(current); break; } } } foreach (Function current in this) { tempList.Add(current); } this.Clear(); this.AddRange(tempList); }
/// <summary> /// Removes entries from this list which have the same name as an entry in other list /// </summary> /// <param name="other"> /// A <see cref="FunctionList"/> /// </param> public void RemoveFunctions(FunctionList other) { /* Copy this list to hashtable */ Dictionary <string, Function> temp = new Dictionary <string, Function>(); FunctionList toBeRemoved = new FunctionList(); foreach (Function f in this) { temp.Add(f.Name, f); } /* Find duplicates */ foreach (Function f in other) { if (temp.ContainsKey(f.Name)) { Function thisf = temp[f.Name]; if (thisf.Arguments.Count != f.Arguments.Count) { throw new ApplicationException(string.Format("Same name, different arguments count: {0} {1} {2}", f.Name, f.Arguments.Count, thisf.Arguments.Count)); } toBeRemoved.Add(thisf); } } foreach (Function f in toBeRemoved) { this.Remove(f); } }
public FunctionList Parse(string pathToFile) { FunctionList functions = new FunctionList(); /* This file might not yet exist */ if (!File.Exists(pathToFile)) { return(functions); } StreamReader sr = File.OpenText(pathToFile); string line = null; int spacePosition = -1; int bracketPosition = -1; while ((line = sr.ReadLine()) != null) { if ((line.IndexOf(" gl") < 0) && (line.IndexOf(" egl") < 0) && (line.IndexOf(" vg") < 0)) { continue; } bracketPosition = line.IndexOf("(", 0); if (bracketPosition < 0) { continue; } spacePosition = line.LastIndexOf(" ", bracketPosition); if (spacePosition < 0) { continue; } Function f = new Function(); f.ReturnType = line.Substring(0, spacePosition).Trim(); f.Name = line.Substring(spacePosition + 1, bracketPosition - spacePosition - 1).Trim(); functions.Add(f); } return(functions); }
public void RemoveFunctionByName(string functionName) { FunctionList toBeRemoved = new FunctionList(); foreach (Function f in this) { if (f.Name == functionName) { toBeRemoved.Add(f); } } foreach (Function f in toBeRemoved) { this.Remove(f); } }
public void RemoveFunctionsExceptFor(FunctionNameDictionary functions) { FunctionList toBeRemoved = new FunctionList(); foreach (Function f in this) { if (!functions.ContainsKey(f.Name)) { toBeRemoved.Add(f); } else { functions.MarkAsMatched(f.Name); } } foreach (Function f in toBeRemoved) { this.Remove(f); } }
public FunctionList Parse(string pathToHeader, string APIstring, string APIENTRYstring) { FunctionList functions = new FunctionList(); StreamReader sr = File.OpenText(pathToHeader); string line = null; int APIposition = -1; int APIENTRYposition = -1; int openbracketposition = -1; int closebracketpositiong = -1; while ((line = readandnormalize(sr)) != null) { if (line == string.Empty) { continue; } if (line.IndexOf("#") >= 0) { continue; } /* check tokens */ APIposition = line.IndexOf(APIstring); if (APIposition < 0) { continue; } /* Check APIENTRY first */ APIENTRYposition = line.IndexOf(APIENTRYstring, APIposition); if (APIENTRYposition < 0) { continue; } if (line[APIENTRYposition - 1] != ' ') /* Space before APIENTRY is required */ { continue; } openbracketposition = line.IndexOf("(", APIENTRYposition); if (openbracketposition < 0) { continue; } closebracketpositiong = line.IndexOf(")", openbracketposition); if (closebracketpositiong < 0) { /* read next lines for closing brackets */ string nextline = null; while ((nextline = readandnormalize(sr)) != null) { line += nextline; closebracketpositiong = line.IndexOf(")", openbracketposition); if (closebracketpositiong >= 0) { break; } } } /* create objects */ Function f = new Function(); f.ReturnType = line.Substring(APIposition + APIstring.Length, APIENTRYposition - APIposition - APIstring.Length).Trim(); f.Name = line.Substring(APIENTRYposition + APIENTRYstring.Length, openbracketposition - APIENTRYposition - APIENTRYstring.Length).Trim(); string argumentsstring = line.Substring(openbracketposition + 1, closebracketpositiong - 1 - openbracketposition); string [] arguments = argumentsstring.Split(','); char nextargumentname = 'a'; foreach (string argument in arguments) { /* change * and & so that they are no concatenated with variable name */ string innerargument = argument.Replace("*", " * "); innerargument = innerargument.Replace("&", " & "); innerargument = innerargument.Replace(" ", " "); innerargument = innerargument.Replace(" [", "["); innerargument = innerargument.Trim(); /* Possible situations: * (A) innerargument = "void" * (B) innerargument = "type variable" * (C) innerargument = "type * variable" * (D) innerargument = "type & variable" * (E) innerargumetn = "type" * (F) innerargument = "type *" * (G) innerargument = "type &" */ string [] argumentparts = innerargument.Split(' '); /* Detection for A: only one argument with one argumentpart containing void*/ if ((argumentparts.Length == 1) && (arguments.Length == 1) && (argumentparts[0].IndexOf("void") >= 0)) { continue; } int lastPositionOfTypeBackwards = 1; /* Means the last element of argumentparts is variable name */ /* Detection for E, F, G: argument without variable name */ if ((argumentparts[argumentparts.Length - 1] == "*") || (argumentparts[argumentparts.Length - 1] == "&") || (argumentparts.Length == 1) ) { lastPositionOfTypeBackwards = 0; /* Means the last element of argumentparts is type */ } Argument arg = new Argument(); arg.Type = ""; for (int i = 0; i < argumentparts.Length - lastPositionOfTypeBackwards; i++) { arg.Type = arg.Type + argumentparts[i] + " "; } arg.Type = arg.Type.Trim(); if (lastPositionOfTypeBackwards == 1) { arg.Name = argumentparts[argumentparts.Length - 1].Trim(); } else { /* Autoname for the variable */ arg.Name = string.Format("{0}", nextargumentname++); } f.Arguments.Add(arg); } functions.Add(f); /*Console.Write("{0} {1} (", f.ReturnType, f.Name); * int j; * if (f.Arguments.Count > 0) * { * for (j = 0; j < f.Arguments.Count - 1; j++) * Console.Write("{0} {1} ({2}), ", f.Arguments[j].Type, f.Arguments[j].Name, f.Arguments[j].Register); * Console.Write("{0} {1} ({2})", f.Arguments[j].Type, f.Arguments[j].Name, f.Arguments[j].Register); * } * Console.WriteLine(");");*/ } sr.Close(); return(functions); }