예제 #1
0
    void ParseEnum(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "enum".Length;

        string name = ReadWord(section.data, ref caret);

        if (name == "class")
        {
            name = ReadWord(section.data, ref caret);
        }

        string block = ReadBlock(section.data, ref caret).Trim(' ', '{', '}', '\r', '\t', '\n');
        string blockWithoutComments = RemoveComments(block);
        var    content = Split(blockWithoutComments, ',');

        LexEnum newEnum = new LexEnum()
        {
            begin = begin,
            end   = caret,
            data  = section.data.Substring(begin, caret - begin),
            name  = name
        };

        content.ForEach(x => newEnum.content.Add(x.Trim(' ', '\n', '\t', '\r')));

        section.enums.Add(newEnum);
    }
예제 #2
0
    void ParseIfMacro(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "#if".Length;

        string skipSymbols = " \r\n\t";
        string endWord     = "#endif";

        int dataLen = section.data.Length;

        for (; caret < dataLen; caret++)
        {
            if (skipSymbols.Contains(section.data[caret]))
            {
                continue;
            }

            string sub = section.data.Substring(caret, Math.Min(endWord.Length, dataLen - caret));
            if (sub == endWord)
            {
                caret = Math.Min(dataLen, caret + endWord.Length);
                return;
            }
        }
    }
예제 #3
0
 void BindComments(LexSection section)
 {
     section.functions.ForEach(x => x.comment     = section.FindComment(x.begin, x.end));
     section.variables.ForEach(x => x.comment     = section.FindComment(x.begin, x.end));
     section.unknownBlocks.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
     section.childSections.ForEach(x => BindComments(x));
 }
예제 #4
0
    void ParseNamespace(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "namespace".Length;

        string namespaceName  = ReadWord(section.data, ref caret);
        int    namespaceBegin = section.data.IndexOf('{', caret) + 1;
        string block          = ReadBlock(section.data, ref caret).Trim(' ', '\r', '\t', '\n');
        string body           = block.Substring(1, block.Length - 2).Trim(' ', '\r', '\t', '\n');

        LexNamespace newNamespace = new LexNamespace()
        {
            begin            = begin,
            end              = caret,
            data             = body,
            name             = namespaceName,
            source           = source,
            parentLexSection = section
        };

        section.childSections.Add(newNamespace);

        ParseLexSection(newNamespace, ProtectLevel.Public);
    }
예제 #5
0
    List <LexClass> GetAllClasses(LexSection section)
    {
        List <LexClass> res = new List <LexClass>(section.classes.FindAll(x => x.haveBody));

        section.childSections.ForEach(x => res.AddRange(GetAllClasses(x)));

        return(res);
    }
예제 #6
0
    void ParseFriend(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "friend".Length;
        string name  = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
        string value = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
    }
예제 #7
0
        static List <LexClass> ClassesSeletor(LexSection section)
        {
            var res = section.classes.FindAll(
                y => y.baseClasses.FindIndex(
                    z => z.className == "ISerializable" || z.className == "IObject") >= 0).ToList();

            section.childSections.ForEach(x => ClassesSeletor(x).ForEach(v => res.Add(v)));

            return(res);
        }
예제 #8
0
        static List<LexClass> ClassesSeletor(LexSection section)
        {
            var res = section.classes.FindAll(
                    y => y.baseClasses.FindIndex(
                        z => z.className == "ISerializable" || z.className == "IObject") >= 0).ToList();

            section.childSections.ForEach(x => ClassesSeletor(x).ForEach(v => res.Add(v)));

            return res;
        }
예제 #9
0
    void ParseLexSection(LexSection section, ProtectLevel protectionLevel)
    {
        section.source = source;

        string skipSymbols = " \r\n\t";
        int    dataLen     = section.data.Length;
        int    caret       = 0;

        for (caret = 0; caret < dataLen; caret++)
        {
            if (skipSymbols.Contains(section.data[caret]))
            {
                continue;
            }

            Dictionary <string, ParserFunc> keyParsers = globalKeyParsers;

            if (section.GetType() == typeof(LexClass))
            {
                keyParsers = classBodyKeyParsers;
            }

            bool passedKeyWord = false;
            foreach (var keyWordParser in keyParsers)
            {
                string sub = section.data.Substring(caret, Math.Min(keyWordParser.Key.Length, dataLen - caret));

                if (sub == keyWordParser.Key)
                {
                    keyWordParser.Value(section, ref caret, ref protectionLevel);
                    passedKeyWord = true;
                    break;
                }
            }

            if (passedKeyWord)
            {
                continue;
            }

            int    blockbegin = caret;
            string block      = ReadBlock(section.data, ref caret);
            block = block.Trim(' ', '\r', '\t', '\n');

            if (block.Length > 0)
            {
                TryParseBlock(section, block, blockbegin, ref caret, ref protectionLevel);
            }
        }

        section.functions.ForEach(x => x.comment     = section.FindComment(x.begin, x.end));
        section.variables.ForEach(x => x.comment     = section.FindComment(x.begin, x.end));
        section.unknownBlocks.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
    }
예제 #10
0
    void ParseSingleLineComment(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "//".Length;
        string comment = ReadWord(section.data, ref caret, "\n", "").Trim(' ', '\r');

        section.comments.Add(new LexComment()
        {
            begin   = begin,
            end     = caret,
            data    = section.data.Substring(begin, caret - begin),
            comment = comment,
            source  = source
        });
    }
예제 #11
0
    void ParseInclude(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "#include".Length;
        string word = ReadWord(section.data, ref caret, "\n").Trim(' ', '\r', '"');

        source.includes.Add(new LexInclude()
        {
            begin       = begin,
            end         = caret,
            data        = section.data.Substring(begin, caret - begin),
            includeFile = word,
            source      = source
        });
    }
예제 #12
0
    void ParsePragma(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "#pragma".Length;
        string word = ReadWord(section.data, ref caret);

        source.pragmas.Add(new LexPragma()
        {
            begin      = begin,
            end        = caret,
            data       = section.data.Substring(begin, caret - begin),
            pragmaWord = word,
            source     = source
        });
    }
예제 #13
0
    void ParseMultiLineComment(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "/*".Length;
        int end = section.data.IndexOf("*/", caret);

        caret = end;
        section.comments.Add(new LexComment()
        {
            begin   = begin,
            end     = end,
            data    = section.data.Substring(begin, caret - begin),
            comment = section.data.Substring(begin + 2, end - begin - 4).Trim(' ', '\r', '\t', '\n'),
            source  = source
        });
    }
예제 #14
0
    void ParseUsing(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "using".Length;

        ReadWord(section.data, ref caret);

        string name = ReadWord(section.data, ref caret);

        section.usingNamespaces.Add(new LexUsingNamespace()
        {
            begin = begin,
            end   = caret,
            data  = section.data.Substring(begin, caret - begin),
            name  = name
        });
    }
예제 #15
0
    void ParseTypedef(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "typedef".Length;
        string value = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
        string name  = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n', ';');

        section.typedefs.Add(new LexTypedef()
        {
            begin  = begin,
            end    = caret,
            data   = section.data.Substring(begin, caret - begin),
            name   = name,
            value  = value,
            source = source
        });
    }
예제 #16
0
    void ParseDefine(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "#define".Length;

        string definition = ReadWord(section.data, ref caret);
        string next       = ReadWord(section.data, ref caret, "\n").Trim(' ', '\r', '\t');

        source.defines.Add(new LexDefine()
        {
            begin      = begin,
            end        = caret,
            data       = section.data.Substring(begin, caret - begin),
            definition = definition,
            content    = next,
            source     = source
        });
    }
예제 #17
0
    void ProcessTypedefs(LexSection section)
    {
        foreach (var tpd in section.typedefs)
        {
            LexClass defClass = section.FindLexSection(tpd.value) as LexClass;
            if (defClass == null)
            {
                continue;
            }

            LexClass newClass = defClass.Clone();
            string   oldName  = newClass.shortName;
            newClass.shortName = tpd.name;
            RenameClass(newClass, newClass.name, section.name + "::" + newClass.shortName);
            section.classes.Add(newClass);
            section.childSections.Add(newClass);
        }

        section.childSections.ForEach(x => ProcessTypedefs(x));
    }
예제 #18
0
    void ParseTemplate(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        caret += "template".Length;

        for (; caret < section.data.Length; caret++)
        {
            if (section.data[caret] == '<')
            {
                break;
            }
        }

        caret++;
        int braces = 1;
        int begin  = caret;

        for (; caret < section.data.Length; caret++)
        {
            if (section.data[caret] == '<')
            {
                braces++;
            }

            if (section.data[caret] == '>')
            {
                braces--;

                if (braces == 0)
                {
                    break;
                }
            }
        }

        string tempInside = section.data.Substring(begin, caret - begin);

        isNextLexTemplate = true;
        templatesBuffer   = tempInside;
    }
예제 #19
0
    void ParseClassOrStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel, bool isstruct)
    {
        int begin = caret;

        if (isstruct)
        {
            caret += "struct".Length;
        }
        else
        {
            caret += "class".Length;
        }

        string className = ReadWord(section.data, ref caret, " \n\t\r:;/");
        string afterName = ReadWord(section.data, ref caret, ";{/").Trim(' ', ':', '\r', '\n', '\t');

        string shortClassName = className;

        if (section.GetType() == typeof(LexClass))
        {
            className = (section as LexClass).name + "::" + className;
        }
        else
        {
            className = (section as LexNamespace).name + "::" + className;
        }

        LexClass newClass = new LexClass()
        {
            begin            = begin,
            end              = caret,
            data             = section.data.Substring(begin, caret - begin),
            name             = className,
            shortName        = shortClassName,
            source           = source,
            parentLexSection = section,
            protectLevel     = protectionLevel,
            haveBody         = false,
            isTemplate       = isNextLexTemplate
        };

        if (isNextLexTemplate)
        {
            newClass.templates = templatesBuffer;
        }

        isNextLexTemplate = false;

        if (afterName.Length > 0)
        {
            var baseClasses = Split(afterName, ',');

            foreach (var baseClass in baseClasses)
            {
                string trimmedBaseClass = baseClass.Trim();

                int spacePos = trimmedBaseClass.IndexOf(' ');
                if (spacePos < 0)
                {
                    newClass.baseClasses.Add(new LexClass.BaseClassDef()
                    {
                        type      = ProtectLevel.Private,
                        className = trimmedBaseClass
                    });
                }
                else
                {
                    string sectionTypeName = trimmedBaseClass.Substring(0, spacePos);
                    string baseClassName   = trimmedBaseClass.Substring(spacePos + 1);

                    if (baseClassName.StartsWith("virtual"))
                    {
                        baseClassName = baseClassName.Substring("virtual".Length + 1);
                    }

                    ProtectLevel sectionType = ProtectLevel.Private;

                    if (sectionTypeName == "public")
                    {
                        sectionType = ProtectLevel.Public;
                    }
                    else if (sectionTypeName == "protected")
                    {
                        sectionType = ProtectLevel.Protected;
                    }

                    newClass.baseClasses.Add(new LexClass.BaseClassDef()
                    {
                        type      = sectionType,
                        className = baseClassName
                    });
                }
            }
        }

        if (caret < section.data.Length && section.data[caret] == '/')
        {
            string comment = ReadWord(section.data, ref caret, "\n");
            ReadWord(section.data, ref caret, ";{/");

            newClass.comment = new LexComment()
            {
                comment = comment
            };
        }

        if (caret < section.data.Length && section.data[caret] == '{')
        {
            int sectionBegin = caret;
            newClass.data     = ReadBlock(section.data, ref caret).Trim('{', '}', ' ', '\n', '\r', '\t');
            newClass.haveBody = true;

            section.classes.Add(newClass);
            section.childSections.Add(newClass);

            ParseLexSection(newClass, isstruct ? ProtectLevel.Public : ProtectLevel.Private);
        }
    }
예제 #20
0
    void ParseTemplate(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        caret += "template".Length;

        for (; caret < section.data.Length; caret++)
            if (section.data[caret] == '<')
                break;

        caret++;
        int braces = 1;
        int begin = caret;

        for (; caret < section.data.Length; caret++)
        {
            if (section.data[caret] == '<')
                braces++;

            if (section.data[caret] == '>')
            {
                braces--;

                if (braces == 0)
                    break;
            }
        }

        string tempInside = section.data.Substring(begin, caret - begin);

        isNextLexTemplate = true;
        templatesBuffer = tempInside;
    }
예제 #21
0
 void ParseSingleLineComment(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "//".Length;
     string comment = ReadWord(section.data, ref caret, "\n", "").Trim(' ', '\r');
     section.comments.Add(new LexComment()
     {
         begin = begin,
         end = caret,
         data = section.data.Substring(begin, caret - begin),
         comment = comment,
         source = source
     });
 }
예제 #22
0
    void ParseNamespace(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "namespace".Length;

        string namespaceName = ReadWord(section.data, ref caret);
        int namespaceBegin = section.data.IndexOf('{', caret) + 1;
        string block = ReadBlock(section.data, ref caret).Trim(' ', '\r', '\t', '\n');
        string body = block.Substring(1, block.Length - 2).Trim(' ', '\r', '\t', '\n');

        LexNamespace newNamespace = new LexNamespace()
        {
            begin = begin,
            end = caret,
            data = body,
            name = namespaceName,
            source = source,
            parentLexSection = section
        };
        section.childSections.Add(newNamespace);

        ParseLexSection(newNamespace, ProtectLevel.Public);
    }
예제 #23
0
    void ParseLexSection(LexSection section, ProtectLevel protectionLevel)
    {
        section.source = source;

        string skipSymbols = " \r\n\t";
        int dataLen = section.data.Length;
        int caret = 0;

        for (caret = 0; caret < dataLen; caret++)
        {
            if (skipSymbols.Contains(section.data[caret]))
                continue;

            Dictionary<string, ParserFunc> keyParsers = globalKeyParsers;

            if (section.GetType() == typeof(LexClass))
                keyParsers = classBodyKeyParsers;

            bool passedKeyWord = false;
            foreach (var keyWordParser in keyParsers)
            {
                string sub = section.data.Substring(caret, Math.Min(keyWordParser.Key.Length, dataLen - caret));

                if (sub == keyWordParser.Key)
                {
                    keyWordParser.Value(section, ref caret, ref protectionLevel);
                    passedKeyWord = true;
                    break;
                }
            }

            if (passedKeyWord)
                continue;

            int blockbegin = caret;
            string block = ReadBlock(section.data, ref caret);
            block = block.Trim(' ', '\r', '\t', '\n');

            if (block.Length > 0)
                TryParseBlock(section, block, blockbegin, ref caret, ref protectionLevel);
        }

        section.functions.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
        section.variables.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
        section.unknownBlocks.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
    }
예제 #24
0
    void ParseIfMacro(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "#if".Length;

        string skipSymbols = " \r\n\t";
        string endWord = "#endif";

        int dataLen = section.data.Length;
        for (; caret < dataLen; caret++)
        {
            if (skipSymbols.Contains(section.data[caret]))
                continue;

            string sub = section.data.Substring(caret, Math.Min(endWord.Length, dataLen - caret));
            if (sub == endWord)
            {
                caret = Math.Min(dataLen, caret + endWord.Length);
                return;
            }
        }
    }
예제 #25
0
    void ParseEnum(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "enum".Length;

        string name = ReadWord(section.data, ref caret);

        if (name == "class")
            name = ReadWord(section.data, ref caret);

        string block = ReadBlock(section.data, ref caret).Trim(' ', '{', '}', '\r', '\t', '\n');
        string blockWithoutComments = RemoveComments(block);
        var content = Split(blockWithoutComments, ',');

        LexEnum newEnum = new LexEnum()
        {
            begin = begin,
            end = caret,
            data = section.data.Substring(begin, caret - begin),
            name = name
        };

        content.ForEach(x => newEnum.content.Add(x.Trim(' ', '\n', '\t', '\r')));

        section.enums.Add(newEnum);
    }
예제 #26
0
    void ParseUsing(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "using".Length;

        ReadWord(section.data, ref caret);

        string name = ReadWord(section.data, ref caret);
        section.usingNamespaces.Add(new LexUsingNamespace()
        {
            begin = begin,
            end = caret,
            data = section.data.Substring(begin, caret - begin),
            name = name
        });
    }
예제 #27
0
 void BindUsingNamespaces(LexSection section)
 {
     section.usingNamespaces.ForEach(x => x.nspace = section.FindLexSection(x.name) as LexNamespace);
     section.childSections.ForEach(x => BindUsingNamespaces(x));
 }
예제 #28
0
    void TryParseBlock(LexSection section, string block, int blockBegin, ref int caret, ref ProtectLevel protectionLevel)
    {
        int  locCaret   = 0;
        bool isFunction = false;

        string firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord.Length == 0)
        {
            LexUnknown unkn = new LexUnknown()
            {
                begin        = blockBegin,
                end          = caret,
                data         = block,
                protectLevel = protectionLevel,
                value        = block
            };

            section.unknownBlocks.Add(unkn);
            return;
        }

        if (firstWord == "virtual")
        {
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");
        }

        if (firstWord == "static")
        {
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");
        }

        if (firstWord == "typename")
        {
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");
        }

        if (firstWord == "inline")
        {
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");
        }

        if (GetNextSymbol(block, locCaret, " \n\r\t") == '(')
        {
            string braces   = ReadBraces(block, ref locCaret).Trim(' ', '\n', '\t', '\r', '(', ')');
            int    tmpCaret = 0;
            string word     = ReadWord(braces, ref tmpCaret);

            isFunction = GetNextSymbol(braces, tmpCaret, " \n\r\t") != ':';

            if (!isFunction && braces.StartsWith("std"))
            {
                isFunction = true;
            }
        }
        else
        {
            if (firstWord == "const")
            {
                ReadWord(block, ref locCaret, " \n\r(){}[]");
            }

            string thirdWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

            if (thirdWord == "operator")
            {
                thirdWord = ReadWord(block, ref locCaret, " \n\r(){}");
            }

            if (GetNextSymbol(block, locCaret, " \n\r\t") == '(')
            {
                isFunction = true;
            }
        }

        if (isFunction)
        {
            section.functions.Add(ParseFunction(block, protectionLevel, blockBegin, caret));
        }
        else
        {
            section.variables.Add(ParseVariable(block, protectionLevel, blockBegin, caret));
        }
    }
예제 #29
0
 void ParseClassProtected(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     caret          += "protected:".Length;
     protectionLevel = ProtectLevel.Protected;
 }
예제 #30
0
 void ParseClassPublic(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     caret          += "public:".Length;
     protectionLevel = ProtectLevel.Public;
 }
예제 #31
0
 void ParseClassPublic(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     caret += "public:".Length;
     protectionLevel = ProtectLevel.Public;
 }
예제 #32
0
    void ParseDefine(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "#define".Length;

        string definition = ReadWord(section.data, ref caret);
        string next = ReadWord(section.data, ref caret, "\n").Trim(' ', '\r', '\t');

        source.defines.Add(new LexDefine()
        {
            begin = begin,
            end = caret,
            data = section.data.Substring(begin, caret - begin),
            definition = definition,
            content = next,
            source = source
        });
    }
예제 #33
0
 void BindComments(LexSection section)
 {
     section.functions.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
     section.variables.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
     section.unknownBlocks.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
     section.childSections.ForEach(x => BindComments(x));
 }
예제 #34
0
 void ParseFriend(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "friend".Length;
     string name = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
     string value = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
 }
예제 #35
0
    void TryParseBlock(LexSection section, string block, int blockBegin, ref int caret, ref ProtectLevel protectionLevel)
    {
        int locCaret = 0;
        bool isFunction = false;

        string firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord.Length == 0)
        {
            LexUnknown unkn = new LexUnknown()
            {
                begin = blockBegin,
                end = caret,
                data = block,
                protectLevel = protectionLevel,
                value = block
            };

            section.unknownBlocks.Add(unkn);
            return;
        }

        if (firstWord == "virtual")
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord == "static")
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord == "typename")
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord == "inline")
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (GetNextSymbol(block, locCaret, " \n\r\t") == '(')
        {
            string braces = ReadBraces(block, ref locCaret).Trim(' ', '\n', '\t', '\r', '(', ')');
            int tmpCaret = 0;
            string word = ReadWord(braces, ref tmpCaret);

            isFunction = GetNextSymbol(braces, tmpCaret, " \n\r\t") != ':';

            if (!isFunction && braces.StartsWith("std"))
                isFunction = true;
        }
        else
        {
            if (firstWord == "const")
                ReadWord(block, ref locCaret, " \n\r(){}[]");

            string thirdWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

            if (thirdWord == "operator")
                thirdWord = ReadWord(block, ref locCaret, " \n\r(){}");

            if (GetNextSymbol(block, locCaret, " \n\r\t") == '(')
                isFunction = true;
        }

        if (isFunction)
            section.functions.Add(ParseFunction(block, protectionLevel, blockBegin, caret));
        else
            section.variables.Add(ParseVariable(block, protectionLevel, blockBegin, caret));
    }
예제 #36
0
 void ParseInclude(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "#include".Length;
     string word = ReadWord(section.data, ref caret, "\n").Trim(' ', '\r', '"');
     source.includes.Add(new LexInclude()
     {
         begin = begin,
         end = caret,
         data = section.data.Substring(begin, caret - begin),
         includeFile = word,
         source = source
     });
 }
예제 #37
0
 void BindUsingNamespaces(LexSection section)
 {
     section.usingNamespaces.ForEach(x => x.nspace = section.FindLexSection(x.name) as LexNamespace);
     section.childSections.ForEach(x => BindUsingNamespaces(x));
 }
예제 #38
0
 void ParseMultiLineComment(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "/*".Length;
     int end = section.data.IndexOf("*/", caret);
     caret = end;
     section.comments.Add(new LexComment()
     {
         begin = begin,
         end = end,
         data = section.data.Substring(begin, caret - begin),
         comment = section.data.Substring(begin + 2, end - begin - 4).Trim(' ', '\r', '\t', '\n'),
         source = source
     });
 }
예제 #39
0
    List<LexClass> GetAllClasses(LexSection section)
    {
        List<LexClass> res = new List<LexClass>(section.classes.FindAll(x => x.haveBody));
        section.childSections.ForEach(x => res.AddRange(GetAllClasses(x)));

        return res;
    }
예제 #40
0
 void ParsePragma(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "#pragma".Length;
     string word = ReadWord(section.data, ref caret);
     source.pragmas.Add(new LexPragma()
     {
         begin = begin,
         end = caret,
         data = section.data.Substring(begin, caret - begin),
         pragmaWord = word,
         source = source
     });
 }
예제 #41
0
    void ParseClassOrStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel, bool isstruct)
    {
        int begin = caret;

        if (isstruct) caret += "struct".Length;
        else caret += "class".Length;

        string className = ReadWord(section.data, ref caret, " \n\t\r:;/");
        string afterName = ReadWord(section.data, ref caret, ";{/").Trim(' ', ':', '\r', '\n', '\t');

        string shortClassName = className;

        if (section.GetType() == typeof(LexClass))
            className = (section as LexClass).name + "::" + className;
        else
            className = (section as LexNamespace).name + "::" + className;

        LexClass newClass = new LexClass()
        {
            begin = begin,
            end = caret,
            data = section.data.Substring(begin, caret - begin),
            name = className,
            shortName = shortClassName,
            source = source,
            parentLexSection = section,
            protectLevel = protectionLevel,
            haveBody = false,
            isTemplate = isNextLexTemplate
        };

        if (isNextLexTemplate)
            newClass.templates = templatesBuffer;

        isNextLexTemplate = false;

        if (afterName.Length > 0)
        {
            var baseClasses = Split(afterName, ',');

            foreach (var baseClass in baseClasses)
            {
                string trimmedBaseClass = baseClass.Trim();

                int spacePos = trimmedBaseClass.IndexOf(' ');
                if (spacePos < 0)
                {
                    newClass.baseClasses.Add(new LexClass.BaseClassDef()
                    {
                        type = ProtectLevel.Private,
                        className = trimmedBaseClass
                    });
                }
                else
                {
                    string sectionTypeName = trimmedBaseClass.Substring(0, spacePos);
                    string baseClassName = trimmedBaseClass.Substring(spacePos + 1);

                    if (baseClassName.StartsWith("virtual"))
                        baseClassName = baseClassName.Substring("virtual".Length + 1);

                    ProtectLevel sectionType = ProtectLevel.Private;

                    if (sectionTypeName == "public")
                        sectionType = ProtectLevel.Public;
                    else if (sectionTypeName == "protected")
                        sectionType = ProtectLevel.Protected;

                    newClass.baseClasses.Add(new LexClass.BaseClassDef()
                    {
                        type = sectionType,
                        className = baseClassName
                    });
                }
            }
        }

        if (caret < section.data.Length && section.data[caret] == '/')
        {
            string comment = ReadWord(section.data, ref caret, "\n");
            ReadWord(section.data, ref caret, ";{/");

            newClass.comment = new LexComment() { comment = comment };
        }

        if (caret < section.data.Length && section.data[caret] == '{')
        {
            int sectionBegin = caret;
            newClass.data = ReadBlock(section.data, ref caret).Trim('{', '}', ' ', '\n', '\r', '\t');
            newClass.haveBody = true;

            section.classes.Add(newClass);
            section.childSections.Add(newClass);

            ParseLexSection(newClass, isstruct ? ProtectLevel.Public : ProtectLevel.Private);
        }
    }
예제 #42
0
 void ParseStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     ParseClassOrStruct(section, ref caret, ref protectionLevel, true);
 }
예제 #43
0
 void ParseClassProtected(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     caret += "protected:".Length;
     protectionLevel = ProtectLevel.Protected;
 }
예제 #44
0
 void ParseTypedef(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "typedef".Length;
     string value = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
     string name = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n', ';');
     section.typedefs.Add(new LexTypedef()
     {
         begin = begin,
         end = caret,
         data = section.data.Substring(begin, caret - begin),
         name = name,
         value = value,
         source = source
     });
 }
예제 #45
0
 void ParseStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     ParseClassOrStruct(section, ref caret, ref protectionLevel, true);
 }
예제 #46
0
    void ProcessTypedefs(LexSection section)
    {
        foreach (var tpd in section.typedefs)
        {
            LexClass defClass = section.FindLexSection(tpd.value) as LexClass;
            if (defClass == null)
                continue;

            LexClass newClass = defClass.Clone();
            string oldName = newClass.shortName;
            newClass.shortName = tpd.name;
            RenameClass(newClass, newClass.name, section.name + "::" + newClass.shortName);
            section.classes.Add(newClass);
            section.childSections.Add(newClass);
        }

        section.childSections.ForEach(x => ProcessTypedefs(x));
    }
예제 #47
0
    public LexSection FindLexSection(string name)
    {
        int delm = name.IndexOf("::");

        if (delm < 0)
        {
            LexSection fnd = classes.Find(x => x.shortName == name);

            if (fnd != null)
            {
                return(fnd);
            }

            fnd = childSections.Find(x => x.GetType() == typeof(LexNamespace) && (x as LexNamespace).name == name);

            if (fnd != null)
            {
                return(fnd);
            }

            if (GetType() == typeof(LexClass))
            {
                foreach (var baseCls in (this as LexClass).baseClasses)
                {
                    if (baseCls.lexClass == null)
                    {
                        continue;
                    }

                    fnd = baseCls.lexClass.FindLexSection(name);
                    if (fnd != null)
                    {
                        return(fnd);
                    }
                }
            }

            if (parentLexSection != null && parentLexSection.usingNamespaces.Find(x => x.nspace == this) == null)
            {
                return(parentLexSection.FindLexSection(name));
            }
        }
        else
        {
            string part = name.Substring(0, delm);

            LexSection childSec = childSections.Find(x =>
            {
                return((x.GetType() == typeof(LexNamespace) && (x as LexNamespace).name == part));
            });

            if (childSec == null)
            {
                childSec = classes.Find(x => x.shortName == part);
            }

            if (childSec != null)
            {
                return(childSec.FindLexSection(name.Substring(delm + 2)));
            }
            else
            {
                if (parentLexSection != null && parentLexSection.usingNamespaces.Find(x => x.nspace == this) == null)
                {
                    return(parentLexSection.FindLexSection(name));
                }
            }
        }

        foreach (var sps in usingNamespaces)
        {
            var res = sps.nspace.FindLexSection(name);
            if (res != null)
            {
                return(res);
            }
        }

        return(null);
    }