void _resolveNames(Globals globals) { foreach (string key in globals.GetPropertyNames()) { TypeInfo t = globals.GetProperty(key, true) as TypeInfo; if (t != null) { if (!t.IsComplete) { globals.AddProperty(key, globals.GetTypeInfo(t.Name), -1, ""); } if (t is TemplateInst) { TemplateInst ti = globals.GetProperty(key, true) as TemplateInst; if (!ti.WrappedType.IsComplete) { ti.WrappedType = globals.GetTypeInfo(ti.WrappedType.Name); } } } } foreach (FunctionInfo f in globals.GetFunctions(null, true)) { f.ResolveIncompletion(globals); } foreach (TypeInfo type in globals.TypeInfo) { type.ResolveIncompletion(globals); } }
static FunctionInfo _parseFunction(string line, Globals globals) { int firstParen = line.IndexOf('('); int lastParen = line.LastIndexOf(')'); string baseDecl = line.Substring(0, firstParen); string paramDecl = line.Substring(firstParen, lastParen - firstParen + 1); //-1 for the ; string[] nameParts = baseDecl.Split(' '); if (nameParts.Length > 1) { if (nameParts[0].ToLower().Equals("const")) // Tolerate const type returns nameParts = nameParts.SubArray(1, nameParts.Length - 1); } TypeInfo retType = null; //TODO: split the name parts if (globals.ContainsTypeInfo(nameParts[0])) { retType = globals.GetTypeInfo(nameParts[0]); } else if (nameParts[0].Contains('<')) { string wrappedType = nameParts[0].Extract('<', '>'); string templateType = nameParts[0].Replace(string.Format("<{0}>", wrappedType), ""); TypeInfo wrapped = globals.GetTypeInfo(wrappedType); TemplateInst ti = new TemplateInst() { Name = nameParts[0], IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo { Name = wrappedType, IsComplete = false } }; retType = ti; } else { retType = new TypeInfo() { Name = nameParts[0], IsPrimitive = false }; } return new FunctionInfo {Name = nameParts[1], ReturnType = retType, Inner = paramDecl}; }
public override BaseTypeInfo ResolvePropertyPath(Globals globals, params string[] path) { string str = path[0]; if (str.Contains('(')) { string content = str.Substring(0, str.IndexOf('(')); FunctionInfo fi = Functions.FirstOrDefault(f => f.Name.Equals(content)); if (fi != null) { if (str.Contains('[') && fi.ReturnType is TemplateInst) return ((TemplateInst)fi.ReturnType).WrappedType; else if (fi.ReturnType is TemplateInst) { return globals.GetTypeInfo(fi.ReturnType.Name.Substring(0, fi.ReturnType.Name.IndexOf('<'))); } return fi.ReturnType; } } else if (str.Contains('[')) { string content = str.Extract('[', ']'); str = str.Replace(string.Format("[{0}]", content), ""); if (!Properties.ContainsKey(str)) return null; TemplateInst ti = Properties[str] as TemplateInst; if (ti != null && path.Length > 1) { TypeInfo t = ti.WrappedType; return t.ResolvePropertyPath(globals, path.SubArray(1, path.Length - 1)); } if (ti == null) return null; else if (ti.WrappedType == null) return ti; return globals.GetTypeInfo(ti.WrappedType.Name); } else if (Properties.ContainsKey(path[0])) { BaseTypeInfo ti = Properties[path[0]]; if (ti is TemplateInst) ti = globals.GetTypeInfo(((TemplateInst)ti).Name); if (path.Length > 1) ti = ti.ResolvePropertyPath(globals, path.SubArray(1, path.Length - 1)); return ti; } else if (BaseTypes.Count > 0) // Check our base classes { foreach (TypeInfo t in BaseTypes) { BaseTypeInfo ti = t.ResolvePropertyPath(globals, path); if (ti != null) return ti; } } return null; }
static FunctionInfo _parseFunction(string line, Globals globals) { int firstParen = line.IndexOf('('); int lastParen = line.LastIndexOf(')'); string baseDecl = line.Substring(0, firstParen); string paramDecl = line.Substring(firstParen, lastParen - firstParen + 1); //-1 for the ; string[] nameParts = baseDecl.Split(' '); TypeInfo retType = null; //TODO: split the name parts if (globals.ContainsTypeInfo(nameParts[0])) { retType = globals.GetTypeInfo(nameParts[0]); } else if (nameParts[0].Contains('<')) { string wrappedType = nameParts[0].Extract('<', '>'); string templateType = nameParts[0].Replace(string.Format("<{0}>", wrappedType), ""); TypeInfo wrapped = globals.GetTypeInfo(wrappedType); TemplateInst ti = new TemplateInst() { Name = nameParts[0], IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo { Name = wrappedType, IsComplete = false } }; retType = ti; } else { retType = new TypeInfo() { Name = nameParts[0], IsPrimitive = false }; } return(new FunctionInfo { Name = nameParts[1], ReturnType = retType, Inner = paramDecl }); }
void ParseDumpClass(string line, StringReader rdr, Globals globals) { bool isTemplate = false; if (line.Contains("template <class T> ")) { isTemplate = true; } string[] nameparts = line.Replace(",", "").Replace("template <class T> ", "").Split(' '); //dump the commas string classname = nameparts[1]; //class is first string classtype = nameparts[0]; //it might be an interface TypeInfo classInfo = new TypeInfo() { IsTemplate = isTemplate }; classInfo.Name = classname; globals.AddTypeInfo(classInfo.Name, classInfo); for (int i = 3; i < nameparts.Length; ++i) //list bases 2 would be :, 3 will be first basetype { classInfo.BaseTypeStr.Add(nameparts[i]); //add a base class } bool inprops = false; bool nextReadOnly = false; bool nextProtected = false; while ((line = rdr.ReadLine()) != null) { if (line.Length == 0) //empty line { continue; } if (line.StartsWith("{")) { continue; } if (line.Equals("};")) { //TODO: push our class return; } else if (line.StartsWith("/* readonly */")) { nextReadOnly = true; continue; } else if (line.StartsWith("/* protected */")) { nextProtected = true; continue; } else if (line.StartsWith("/*")) { continue; } else if (line.Contains("// Properties:")) { inprops = true; } else if (line.StartsWith("//")) // // Methods: { continue; } else if (inprops) //property { string[] parts = line.Replace(";", "").Split(' '); //[TypeName] [PropertyName] if (parts[0].Contains('<')) { string templateType = parts[0].Substring(0, parts[0].IndexOf('<')); string containedType = parts[0].Extract('<', '>'); TypeInfo wrapped = globals.GetTypeInfo(containedType); TemplateInst ti = new TemplateInst() { Name = templateType, IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo { Name = containedType, IsComplete = false } }; classInfo.Properties[parts[1]] = ti; classInfo.PropertyLines[parts[1]] = -1; if (nextReadOnly) { classInfo.ReadonlyProperties.Add(parts[1]); } else if (nextProtected) { classInfo.ProtectedProperties.Add(parts[1]); } } else { string pname = parts[0].EndsWith("@") ? parts[0].Substring(0, parts[0].Length - 1) : parts[0]; //handle TypeInfo pType = null; if (globals.ContainsTypeInfo(pname)) { pType = globals.GetTypeInfo(pname); } if (pType == null) //create temp type to resolve later { pType = new TypeInfo() { Name = pname, IsComplete = false }; } classInfo.Properties[parts[1]] = pType; classInfo.PropertyLines[parts[1]] = -1; if (nextReadOnly) { classInfo.ReadonlyProperties.Add(parts[1]); } else if (nextProtected) { classInfo.ProtectedProperties.Add(parts[1]); } } nextReadOnly = false; nextProtected = false; } else //function { classInfo.Functions.Add(_parseFunction(line, globals)); nextReadOnly = false; nextProtected = false; } } }
void ParseDumpClass(string line, StringReader rdr, Globals globals) { bool isTemplate = false; if (line.Contains("template <class T> ")) isTemplate = true; string[] nameparts = line.Replace(",","").Replace("template <class T> ","").Split(' '); //dump the commas string classname = nameparts[1]; //class is first string classtype = nameparts[0]; //it might be an interface TypeInfo classInfo = new TypeInfo() { IsTemplate = isTemplate }; classInfo.Name = classname; globals.AddTypeInfo(classInfo.Name, classInfo); for (int i = 3; i < nameparts.Length; ++i) { //list bases 2 would be :, 3 will be first basetype classInfo.BaseTypeStr.Add(nameparts[i]); //add a base class } bool inprops = false; bool nextReadOnly = false; bool nextProtected = false; while ((line = rdr.ReadLine()) != null) { if (line.Length == 0) //empty line continue; if (line.StartsWith("{")) continue; if (line.Equals("};")) { //TODO: push our class return; } else if (line.StartsWith("/* readonly */")) { nextReadOnly = true; continue; } else if (line.StartsWith("/* protected */")) { nextProtected = true; continue; } else if (line.StartsWith("/*")) { continue; } else if (line.Contains("// Properties:")) { inprops = true; } else if (line.StartsWith("//")) { // // Methods: continue; } else if (inprops) { //property string[] parts = line.Replace(";", "").Split(' '); //[TypeName] [PropertyName] if (parts[0].Contains('<')) { string templateType = parts[0].Substring(0, parts[0].IndexOf('<')); string containedType = parts[0].Extract('<', '>'); TypeInfo wrapped = globals.GetTypeInfo(containedType); TemplateInst ti = new TemplateInst() { Name = templateType, IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo { Name = containedType, IsComplete = false } }; classInfo.Properties[parts[1]] = ti; classInfo.PropertyLines[parts[1]] = -1; if (nextReadOnly) classInfo.ReadonlyProperties.Add(parts[1]); else if (nextProtected) classInfo.ProtectedProperties.Add(parts[1]); } else { string pname = parts[0].EndsWith("@") ? parts[0].Substring(0, parts[0].Length - 1) : parts[0]; //handle TypeInfo pType = null; if (globals.ContainsTypeInfo(pname)) pType = globals.GetTypeInfo(pname); if (pType == null) { //create temp type to resolve later pType = new TypeInfo() { Name = pname, IsComplete = false }; } classInfo.Properties[parts[1]] = pType; classInfo.PropertyLines[parts[1]] = -1; if (nextReadOnly) classInfo.ReadonlyProperties.Add(parts[1]); else if (nextProtected) classInfo.ProtectedProperties.Add(parts[1]); } nextReadOnly = false; nextProtected = false; } else { //function classInfo.Functions.Add(_parseFunction(line, globals)); nextReadOnly = false; nextProtected = false; } } }