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 static void BuildIntellisenseDatabase()
        {
            string dir = System.Reflection.Assembly.GetEntryAssembly().Location;
            dir = System.IO.Path.GetDirectoryName(dir);
            dir = System.IO.Path.Combine(dir, "bin");
            string file = System.IO.Path.Combine(dir, "dump.h");

            // For convenience purposes check for the old file and auto update it to the new "AngelScriptAPI.h" naming
            // This change removes the silly need to rename the API header
            string newFile = System.IO.Path.Combine(dir, "AngelScriptAPI.h");
            if (System.IO.File.Exists(file) && !System.IO.File.Exists(newFile))
                System.IO.File.Copy(file, newFile);

            if (watcher_ == null && System.IO.Directory.Exists(dir)) {
                try
                {
                    watcher_ = new FileSystemWatcher(dir);
                    watcher_.Changed += watcher__Changed;
                    watcher_.EnableRaisingEvents = true;
                }
                catch (Exception)
                {
                    // UAC and other user/system issues may deny us access
                }
            }

            Thread thread = new Thread(delegate() {
                Globals globs = new Globals(true);
                DumpParser parser = new DumpParser();
                try
                {
                    StringReader rdr = new StringReader(File.ReadAllText(newFile));
                    parser.ParseDumpFile(rdr, globs);
                    MainWindow.inst().Dispatcher.Invoke(delegate()
                    {
                        IDEProject.inst().GlobalTypes = globs;
                    });
                }
                catch (Exception ex)
                {
                    // swallow all exceptions
                }
            });
            thread.Start();
        }
 public void ParseDumpFile(StringReader rdr, Globals globals)
 {
     string line = "";
     while ((line = rdr.ReadLine()) != null) {
         if (line.Length == 0)
             continue;
         if (line.Contains("class")) {
             ParseDumpClass(line, rdr, globals);
         } else if (line.Contains("enum")) {
             ParseDumpEnum(line, rdr, globals);
         } else if (line.StartsWith("// Global functions")) {
             ParseDumpGlobFuncs(line, rdr, globals);
         } else if (line.StartsWith("// Global properties")) {
             ParseDumpGlobProps(line, rdr, globals);
         } else if (line.StartsWith("// Global constants")) {
             ParseDumpGlobProps(line, rdr, globals);
         }
     }
     _resolveNames(globals);
 }
 // Present usage only wants classes
 public void MergeIntoThis(Globals other)
 {
     foreach (string k in other.Classes.Keys)
     {
         if (!Classes.ContainsKey(k))
             Classes[k] = IDEProject.inst().GlobalTypes.Classes[k];
     }
 }
 public void AddNamespace(string ns, Globals g)
 {
     Namespaces[ns] = g;
 }
 public abstract BaseTypeInfo ResolvePropertyPath(Globals globals, params string[] path);
 public override BaseTypeInfo ResolvePropertyPath(Globals globals, params string[] path)
 {
     return ReturnType;
 }
Exemple #8
0
 public void AddNamespace(string ns, Globals g)
 {
     Namespaces[ns] = g;
 }
 public void ResolveIncompletion(Globals globs)
 {
     foreach (FunctionInfo f in Functions)
         f.ResolveIncompletion(globs);
     // Properties
     List<string> keys = new List<string>(Properties.Keys);
     foreach (string key in keys)
     {
         if (!Properties[key].IsComplete)
         {
             Properties[key] = globs.GetTypeInfo(Properties[key].Name);
         }
     }
     // Base types
     foreach (TypeInfo t in BaseTypes)
     {
         if (!t.IsComplete)
             t.ResolveIncompletion(globs);
     }
 }
        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);
            }
        }
 void ParseDumpGlobProps(string line, StringReader rdr, Globals globals)
 {
     while ((line = rdr.ReadLine()) != null) {
         if (line.Length == 0)
             return;
         if (line.StartsWith("/*") || line.StartsWith("//"))
             continue;
         else {
             string[] parts = line.Replace(";", "").Split(' '); //[TypeName] [PropertyName]
             string pname = parts[0].EndsWith("@") ? parts[0].Substring(0, parts[0].Length - 1) : parts[0]; //handle
             TypeInfo pType = null;
             string myname = parts[1];
             if (globals.ContainsTypeInfo(pname))
                 pType = globals.GetTypeInfo(pname);
             if (pType == null) { //create temp type to resolve
                 pType = new TypeInfo() { Name = pname, IsComplete = false };
             }
             globals.AddProperty(myname, pType, -1, null);
         }
     }
 }
 void ParseDumpGlobFuncs(string line, StringReader rdr, Globals globals)
 {
     while ((line = rdr.ReadLine()) != null) {
         if (line.Length == 0)
             return;
         if (line.StartsWith("/*") || line.StartsWith("//"))
             continue;
         else {
             globals.AddFunction(_parseFunction(line, globals));
         }
     }
 }
 void ParseDumpEnum(string line, StringReader rdr, Globals globals)
 {
     string[] nameparts = line.Split(' ');
     string enumName = nameparts[1];
     List<string> enumValues = new List<string>();
     while ((line = rdr.ReadLine()) != null) {
         if (line.Equals("};")) {
             EnumInfo ret = new EnumInfo { Name = enumName };
             ret.Values.AddRange(enumValues);
             globals.AddTypeInfo(enumName, ret);
             return;
         } else if (line.Contains(',')) {
             int sub = line.IndexOf(',');
             enumValues.Add(line.Substring(0, sub));
         }
     }
 }
Exemple #14
0
 public abstract BaseTypeInfo ResolvePropertyPath(Globals globals, params string[] path);
 // Left mostly to when used as a namespace
 public override BaseTypeInfo ResolvePropertyPath(Globals globals, params string[] path)
 {
     if (Classes.ContainsKey(path[0]))
         return Classes[path[0]];
     else if (Namespaces.ContainsKey(path[0]))
         return Namespaces[path[0]];
     foreach (FunctionInfo f in Functions)
     {
         if (f.Name.Equals(path[0]))
             return f;
     }
     return null;
 }
 public void ResolveIncompletion(Globals globs)
 {
     if (!Type.IsComplete && globs.ContainsTypeInfo(Type.Name))
         Type = globs.GetTypeInfo(Type.Name);
     if (WrappedType != null && !WrappedType.IsComplete && globs.ContainsTypeInfo(WrappedType.Name))
         WrappedType = globs.GetTypeInfo(WrappedType.Name);
 }
        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;
                }
            }
        }
 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;
 }
 public void ResolveIncompletion(Globals globs)
 {
     if (globs.ContainsTypeInfo(ReturnType.Name))
         ReturnType = globs.GetTypeInfo(ReturnType.Name);
     if (ReturnType is TemplateInst)
     { //not found in globals
         ((TemplateInst)ReturnType).WrappedType = globs.GetTypeInfo(((TemplateInst)ReturnType).WrappedType.Name);
     }
     for (int i = 0; i < Params.Count; ++i)
     {
         if (!Params[i].IsComplete && globs.ContainsTypeInfo(Params[i].Name))
             Params[i] = globs.GetTypeInfo(Params[i].Name);
     }
 }
 public NameResolver(Globals globals, DepthScanner aScanner)
 {
     scanner_ = aScanner;
     globals_ = globals;
 }
Exemple #21
0
 public override BaseTypeInfo ResolvePropertyPath(Globals globals, params string[] path)
 {
     return ReturnType;
 }