Ejemplo n.º 1
0
        void _resolveNames(Globals globals)
        {
            foreach (string key in globals.Properties.Keys)
            {
                if (!globals.Properties[key].IsComplete)
                {
                    globals.Properties[key] = globals.Classes[globals.Properties[key].Name];
                }
                if (globals.Properties[key] is TemplateInst)
                {
                    TemplateInst ti = globals.Properties[key] as TemplateInst;
                    if (!ti.WrappedType.IsComplete)
                    {
                        ti.WrappedType = globals.Classes[ti.WrappedType.Name];
                    }
                }
            }

            foreach (FunctionInfo f in globals.Functions)
            {
                f.ResolveIncompletion(globals);
            }

            foreach (TypeInfo type in globals.Classes.Values)
            {
                type.ResolveIncompletion(globals);
            }
        }
Ejemplo n.º 2
0
        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.Classes[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), "");
                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.Classes[ti.WrappedType.Name]);
            }
            else if (Properties.ContainsKey(path[0]))
            {
                BaseTypeInfo ti = Properties[path[0]];
                if (ti is TemplateInst)
                {
                    ti = globals.Classes[((TemplateInst)ti).Name];
                }
                if (path.Length > 1)
                {
                    ti = ti.ResolvePropertyPath(globals, path.SubArray(1, path.Length - 1));
                }
                return(ti);
            }
            return(null);
        }
Ejemplo n.º 3
0
        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.Classes.ContainsKey(nameParts[0]))
            {
                retType = globals.Classes[nameParts[0]];
            }
            else if (nameParts[0].Contains('<'))
            {
                string       wrappedType  = nameParts[0].Extract('<', '>');
                string       templateType = nameParts[0].Replace(string.Format("<{0}>", wrappedType), "");
                TypeInfo     wrapped      = globals.Classes.FirstOrDefault(t => t.Key.Equals(wrappedType)).Value;
                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
            });
        }
Ejemplo n.º 4
0
        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.Classes[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;

            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("/*"))
                {
                    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.Classes.FirstOrDefault(t => t.Key.Equals(containedType)).Value;
                        TemplateInst ti            = new TemplateInst()
                        {
                            Name = templateType, IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo {
                                Name = containedType, IsComplete = false
                            }
                        };
                        classInfo.Properties[parts[1]] = ti;
                        if (nextReadOnly)
                        {
                            classInfo.ReadonlyProperties.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.Classes.ContainsKey(pname))
                        {
                            pType = globals.Classes[pname];
                        }
                        if (pType == null)   //create temp type to resolve later
                        {
                            pType = new TypeInfo()
                            {
                                Name = pname, IsComplete = false
                            };
                        }
                        classInfo.Properties[parts[1]] = pType;
                        if (nextReadOnly)
                        {
                            classInfo.ReadonlyProperties.Add(parts[1]);
                        }
                    }
                    nextReadOnly = false;
                }
                else     //function
                {
                    nextReadOnly = false;
                    classInfo.Functions.Add(_parseFunction(line, globals));
                }
            }
        }