예제 #1
0
        public Hashtable MakeObjectListing(string code, CProject.File filedecl, Hashtable ht)
        {
            // Construct listing of objects and their functions
            Regex rx = new Regex(@"(^(\s*///\s*(.*?)\n){0,5})?^\s*\bfunction\b\s*(\b[A-Z_][A-Z0-9_]*\b)::(\b[A-Z][A-Z0-9]*\b)\s*\((.*?)\)", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            //Hashtable ht = new Hashtable();

            foreach (Match mt in rx.Matches(code))
            {
                CProject.TokenObject tokobj;
                if (ht.ContainsKey(mt.Groups[4].Value.ToLower()))
                {
                    tokobj = (CProject.TokenObject)ht[mt.Groups[4].Value.ToLower()];
                }
                else
                {
                    tokobj            = new CProject.TokenObject();
                    tokobj.ObjectName = mt.Groups[4].Value;
                    tokobj.isInternal = false;
                    ht.Add(mt.Groups[4].Value.ToLower(), tokobj);
                }

                if (!tokobj.ObjectFunctions.ContainsKey(mt.Groups[5].Value.ToLower()))
                {
                    // Create a function definition if none exists already
                    CProject.TokenObject.ObjectDescr objdescr = new CProject.TokenObject.ObjectDescr();
                    objdescr.FuncName   = mt.Groups[5].Value;
                    objdescr.FuncOffset = mt.Groups[5].Index;
                    objdescr.FuncFile   = filedecl;

                    // Set description
                    string descr = mt.Groups[1].Value.Replace("///", "").Replace("\t", "").Replace("\r", "").TrimStart('\n');
                    foreach (string line in descr.Split('\n'))
                    {
                        if (line.Trim() == "")
                        {
                            continue;
                        }

                        objdescr.FuncDescr += line.Trim() + "<br />";
                    }

                    // Grab all the function parameters by splitting it at the comma
                    // and stick them in the appropriate array
                    if (mt.Groups[4].Value != "")
                    {
                        objdescr.FuncParams = mt.Groups[6].Value.Replace(" ", "").Split(',');
                    }
                    else
                    {
                        objdescr.FuncParams = null;
                    }

                    // Add it to the hashtable
                    tokobj.ObjectFunctions.Add(mt.Groups[5].Value.ToLower(), objdescr);
                }
            }

            return(MakeObjectDeclarations(code, filedecl, ht));;
        }
예제 #2
0
        public int FindToken(string word, string prevtok, out CProject.File out_file)
        {
            out_file = null;

            // Find it in the file listing first
            foreach (CProject.File file in g.Project.FileList)
            {
                if (file.TokenList.ContainsKey(word.ToLower()))
                {
                    // Got it!
                    out_file = file;
                    return(((CProject.TokenKey)file.TokenList[word.ToLower()]).LineNumber);
                }
            }

            // Now search active objects, seeing if this is an object
            // we can jump to.
            if (g.Project.TokenObjList.ContainsKey(word.ToLower()))
            {
                // Yes, it appears this is a valid object...
                CProject.TokenObject tokobj = (CProject.TokenObject)g.Project.TokenObjList[word.ToLower()];
                if (tokobj.ObjectFileDecl != null)
                {
                    out_file = tokobj.ObjectFileDecl;
                    return(tokobj.ObjectDeclOffset);
                }
                else
                {
                    return(-1);
                }
            }


            // Check to see if the *previous* token wasn't an object...
            // ... which would mean that the *current* token is a function
            // definition inside an object
            if (g.Project.TokenObjList.ContainsKey(prevtok.ToLower()))
            {
                // Yes, it appears this is so... see if the thingy is a valid function
                CProject.TokenObject tokobj = (CProject.TokenObject)g.Project.TokenObjList[prevtok.ToLower()];

                if (!tokobj.ObjectFunctions.ContainsKey(word.ToLower()))
                {
                    return(-1);
                }

                // Retrieve the function file information
                CProject.TokenObject.ObjectDescr func = (CProject.TokenObject.ObjectDescr)tokobj.ObjectFunctions[word.ToLower()];
                out_file = func.FuncFile;
                return(func.FuncOffset);
            }

            return(-1);
        }
예제 #3
0
        private Hashtable MakeObjectDeclarations(string code, CProject.File file, Hashtable curlist)
        {
            // Private function for enumerating all object declarations
            // which are declared like "new TypeOfObject(ObjectName) { }" ...
            // Skip objects that don't have a name.

            /*Regex rx = new Regex(@"^\s*\bnew\b\s*(\b[A-Z][A-Z0-9]*\b)\s*\((\b[A-Z_][A-Z0-9_]*\b)\)(\s*\n)?" +
             *      @"(" +
             *      @"(?<inner>" +
             *      @"(?>" +
             *      @"\{(?<LEVEL>)" +
             *      @"|" +
             *      @"\};(?<-LEVEL>)" +
             *      @"|" +
             *      @"(?!\{|\};)." +
             *      @")*" +
             *      @"(?(LEVEL)(?!))" +
             *      @"))?"
             *      , RegexOptions.IgnoreCase | RegexOptions.Multiline);*/

            Regex rx = new Regex(@"^\s*\bnew\b\s*(\b[A-Z][A-Z0-9]*\b)\s*\((\b[A-Z_][A-Z0-9_]*\b)\)(\s*\n)?", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            foreach (Match mt in rx.Matches(code))
            {
                // Enumerate each match and try to compare it to an active object

                //System.Windows.Forms.MessageBox.Show(mt.Groups["inner"].Value.ToLower());

                CProject.TokenObject tokobj;
                if (curlist.ContainsKey(mt.Groups[2].Value.ToLower()))
                {
                    tokobj = (CProject.TokenObject)curlist[mt.Groups[2].Value.ToLower()];
                }
                else
                {
                    tokobj            = new CProject.TokenObject();
                    tokobj.ObjectName = mt.Groups[2].Value;
                    tokobj.isInternal = false;
                    curlist.Add(mt.Groups[2].Value.ToLower(), tokobj);
                }

                tokobj.ObjectType       = mt.Groups[1].Value;
                tokobj.ObjectFileDecl   = file;
                tokobj.ObjectDeclOffset = mt.Groups[2].Index;
            }

            return(curlist);
        }
예제 #4
0
        private Hashtable MakeObjectDeclarations(string code, CProject.File file, Hashtable curlist)
        {
            // Private function for enumerating all object declarations
            // which are declared like "new TypeOfObject(ObjectName) { }" ...
            // Skip objects that don't have a name.

            /*Regex rx = new Regex(@"^\s*\bnew\b\s*(\b[A-Z][A-Z0-9]*\b)\s*\((\b[A-Z_][A-Z0-9_]*\b)\)(\s*\n)?" +
                @"(" +
                @"(?<inner>" +
                @"(?>" +
                @"\{(?<LEVEL>)" +
                @"|" +
                @"\};(?<-LEVEL>)" +
                @"|" +
                @"(?!\{|\};)." +
                @")*" +
                @"(?(LEVEL)(?!))" +
                @"))?"
                , RegexOptions.IgnoreCase | RegexOptions.Multiline);*/

            Regex rx = new Regex(@"^\s*\bnew\b\s*(\b[A-Z][A-Z0-9]*\b)\s*\((\b[A-Z_][A-Z0-9_]*\b)\)(\s*\n)?", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            foreach(Match mt in rx.Matches(code)) {
                // Enumerate each match and try to compare it to an active object

                //System.Windows.Forms.MessageBox.Show(mt.Groups["inner"].Value.ToLower());

                CProject.TokenObject tokobj;
                if (curlist.ContainsKey(mt.Groups[2].Value.ToLower()))
                    tokobj = (CProject.TokenObject)curlist[mt.Groups[2].Value.ToLower()];
                else {
                    tokobj = new CProject.TokenObject();
                    tokobj.ObjectName = mt.Groups[2].Value;
                    tokobj.isInternal = false;
                    curlist.Add(mt.Groups[2].Value.ToLower(), tokobj);
                }

                tokobj.ObjectType = mt.Groups[1].Value;
                tokobj.ObjectFileDecl = file;
                tokobj.ObjectDeclOffset = mt.Groups[2].Index;
            }

            return curlist;
        }
예제 #5
0
        public Hashtable MakeObjectListing(string code, CProject.File filedecl, Hashtable ht)
        {
            // Construct listing of objects and their functions
            Regex rx = new Regex(@"(^(\s*///\s*(.*?)\n){0,5})?^\s*\bfunction\b\s*(\b[A-Z_][A-Z0-9_]*\b)::(\b[A-Z][A-Z0-9]*\b)\s*\((.*?)\)", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            //Hashtable ht = new Hashtable();

            foreach(Match mt in rx.Matches(code)) {
                CProject.TokenObject tokobj;
                if (ht.ContainsKey(mt.Groups[4].Value.ToLower()))
                    tokobj = (CProject.TokenObject)ht[mt.Groups[4].Value.ToLower()];
                else {
                    tokobj = new CProject.TokenObject();
                    tokobj.ObjectName = mt.Groups[4].Value;
                    tokobj.isInternal = false;
                    ht.Add(mt.Groups[4].Value.ToLower(), tokobj);
                }

                if (!tokobj.ObjectFunctions.ContainsKey(mt.Groups[5].Value.ToLower())) {
                    // Create a function definition if none exists already
                    CProject.TokenObject.ObjectDescr objdescr = new CProject.TokenObject.ObjectDescr();
                    objdescr.FuncName = mt.Groups[5].Value;
                    objdescr.FuncOffset = mt.Groups[5].Index;
                    objdescr.FuncFile = filedecl;

                    // Set description
                    string descr = mt.Groups[1].Value.Replace("///", "").Replace("\t", "").Replace("\r", "").TrimStart('\n');
                    foreach(string line in descr.Split('\n')) {
                        if (line.Trim() == "")
                            continue;

                        objdescr.FuncDescr += line.Trim() + "<br />";
                    }

                    // Grab all the function parameters by splitting it at the comma
                    // and stick them in the appropriate array
                    if (mt.Groups[4].Value != "")
                        objdescr.FuncParams = mt.Groups[6].Value.Replace(" ", "").Split(',');
                    else
                        objdescr.FuncParams = null;

                    // Add it to the hashtable
                    tokobj.ObjectFunctions.Add(mt.Groups[5].Value.ToLower(), objdescr);
                }
            }

            return MakeObjectDeclarations(code, filedecl, ht);;
        }