summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCpp
AgeCommit message (Collapse)Author
2021-08-21LibCpp: Use lex_iterable() where applicableItamar
2021-08-21LibCpp: Add lex_iterable() method to the LexerItamar
This allows us to collect the tokens iteratively instead of having to lex the whole program and then get a tokens vector.
2021-08-21LibCpp: Lex before processing the source in the PreprocessorItamar
Previously, the preprocessor first split the source into lines, and then processed and lexed each line separately. This patch makes the preprocessor first lex the source, and then do the processing on the tokenized representation. This generally simplifies the code, and also fixes an issue we previously had with multiline comments (we did not recognize them correctly when processing each line separately).
2021-08-21LibCpp: Allow whitespace between # and preprocessor directiveItamar
For example, '# include <stdio.h>' is now supported by the Lexer.
2021-08-14Tests: Add regression tests for the LibCpp preprocessorItamar
Similarly to the LibCpp parser regression tests, these tests run the preprocessor on the .cpp test files under Userland/LibCpp/Tests/preprocessor, and compare the output with existing .txt ground truth files.
2021-08-14LibCpp: Move parser tests to Userland/Libraries/LibCpp/Tests/parserItamar
2021-08-14LibCpp: Evaluate function-like macro callsItamar
2021-08-14LibCpp: Understand preprocessor macro definition and invocationItamar
The preprocessor now understands when a function-like macro is defined, and can also parse calls to such macros. The actual evaluation of function-like macros will be done in a separate commit.
2021-08-14LibCpp: Add lexer option to ignore whitespace tokensItamar
2021-08-07LibCpp: Do macro substitution in the preprocessor instead of the parserItamar
After this change, the parser is completely separated from preprocessor concepts.
2021-08-07LibCpp: Import definitions from headers while processingItamar
When the preprocessor encounters an #include statement it now adds the preprocessor definitions that exist in the included header to its own set of definitions. We previously only aggregated the definitions from headers after processing the source, which was less correct. (For example, there could be an #ifdef that depends on a definition from another header).
2021-08-07LibCpp: Do lexing in the PreprocessorItamar
We now call Preprocessor::process_and_lex() and pass the result to the parser. Doing the lexing in the preprocessor will allow us to maintain the original position information of tokens after substituting definitions.
2021-08-07LibCpp: Support initializing the lexer with a "start line"Itamar
2021-08-02LibCpp: Allow 'final' in a class declaration with inheritanceAli Mohammad Pur
2021-08-02LibCpp: Add support for east constAli Mohammad Pur
Now LibCpp can understand the eastest of consts too :^)
2021-08-02LibCpp: Allow 'override' as a function target qualifierAli Mohammad Pur
This is just ignored right now.
2021-08-02LibCpp: Add support for parsing function typesAli Mohammad Pur
This makes it work with types like `Function<T(U, V)>`.
2021-08-02LibCpp: Allow 'const' after a function's signatureAli Mohammad Pur
This is too lax for functions that aren't class members, but let's allow that anyway.
2021-08-02LibCpp: Add support for parsing reference typesAli Mohammad Pur
2021-08-02LibCpp: Allow virtual destructorsAli Mohammad Pur
2021-08-02LibCpp: Match and ignore struct/class inheritanceAli Mohammad Pur
2021-08-02LibCpp: Correctly parse lines that end in '\'Ali Mohammad Pur
Such lines should be considered to be joined into the next line. This makes multiline preprocessor stuff "work".
2021-08-02LibCpp: Parse enum members with explicit valuesAli Mohammad Pur
2021-08-02LibCpp: Parse "extern" declarationsAli Mohammad Pur
Note that this is not the `extern "C"` declarations, just extern decl qualifiers.
2021-08-02LibCpp: Accept scoped variable declarationsAli Mohammad Pur
For instance, `Type Scope::Class::variable = value;` is a valid declaration.
2021-07-13LibCpp: Don't store entire ASTNode vector in each parser stateItamar
We previously stored the entire ASTNode vector in each parser state, and this vector was copied whenever a state was loaded or saved. We don't actually need to store the whole nodes list in each state because a new state can only add new nodes to this list, and won't mutate existing nodes. It would suffice to only hold a vector of the nodes that were created while parsing in the current state to keep a reference to them. This reduces the time it takes on my machine for the c++ language server to handle a file that #includes <LibGUI/Widget.h> from ~4sec to ~0.7sec.
2021-07-13LibCpp: Only store error messages for the main parser stateItamar
There's no need to store parser error messages for states with depth > 0, as they will eventually be popped from the states stack and their error messages will never be displayed to the user. Profiling shows that this change reduces the % of backtraces that contain the store_state & load_state functions from ~95% to ~70%. Empirically this change reduces the time it takes on my machine for the c++ language server to handle a file that #includes <LibGUI/Widget.h> from ~14sec to ~4sec.
2021-07-10LibCpp: Use fast_is<T> and verify_cast<T> to replace C-style castsItamar
Thanks to @alimpfard for suggesting this :)
2021-07-10LibCpp: Make the fields of AST node types privateItamar
Previously almost all fields were public and were directly accessed by the Parser and CppComprehensionEngine. This commit makes all fields of AST node types private. They are now accessed via getters & setters.
2021-07-04LibCpp: Add Parser::tokens_in_range(start, end)Itamar
This function returns the tokens that exist in the specified range.
2021-07-04LibCpp: Fix positional information of Pointer typesItamar
2021-07-04LibCpp: Fix parsing of ellipsisItamar
Previously the positional information for the node of an ellipsis was incorrect.
2021-06-29LibCpp: Update Parser test data after Type=>NamedType changeItamar
2021-06-29LibCpp: Differentiate between Type and NamedTypeItamar
This adds a new ASTNode type called 'NamedType' which inherits from the Type node. Previously every Type node had a name field, but it was not logically accurate. For example, pointer types do not have a name (the pointed-to type may have one).
2021-06-29LibCpp: Add LOG_SCOPE() macro for debugging the parser's flowItamar
LOG_SCOPE() uses ScopeLogger and additionally shows the current token in the parser's state.
2021-06-29LibCpp: Support parsing enum classesItamar
2021-06-23HackStudio: Make TODO entries clickableFederico Guerinoni
Now you can click a TODO entry to set focus on that position of that file.
2021-06-23LibCpp: Add function for retrieving TODO comments from the parserFederico Guerinoni
Now `get_todo_entries` collects all TODO found within a comment statement.
2021-06-16LibCpp: Remove InlineLinkedList from the list of known typesBrian Gianforcaro
2021-06-12AK: Rename Vector::append(Vector) => Vector::extend(Vector)Andreas Kling
Let's make it a bit more clear when we're appending the elements from one vector to the end of another vector.
2021-06-09LibCpp: Add test for parsing class definitionsItamar
2021-06-09LibCpp: Parse basic constructors and destructorsItamar
2021-06-09LibCpp: Handle class access-specifiers in the ParserItamar
We can now handle access-specifier tags (for example 'private:') when parsing class declarations. We currently only consume these tags on move on. We'll need to add some logic that accounts for the access level of symbols down the road.
2021-06-09LibCpp: Support non-field class membersItamar
Previously, we had a special ASTNode for class members, "MemberDeclaration", which only represented fields. This commit removes MemberDeclaration and instead uses regular Declaration nodes for representing the members of a class. This means that we can now also parse methods, inner-classes, and other declarations that appear inside of a class.
2021-06-09LibCpp: Make 'bool' a Token::Type::KnownTypeItamar
2021-06-07LibWeb+LibSyntax: Implement nested syntax highlightersAli Mohammad Pur
And use them to highlight javascript in HTML source. This commit also changes how TextDocumentSpan::data is interpreted, as it used to be an opaque pointer, but everyone stuffed an enum value inside it, which made the values not unique to each highlighter; that field is now a u64 serial id. The syntax highlighters don't need to change their ways of stuffing token types into that field, but a highlighter that calls another nested highlighter needs to register the nested types for use with token pairs.
2021-06-05LibCpp: Fix off-by-one error in SyntaxHighlighterMax Wipfli
This changes the C++ SyntaxHighlighter to conform to the now-fixed rendering of syntax highlighting spans in GUI::TextEditor. Contrary to other syntax highlighters, for this one the change has been made to the SyntaxHighlighter rather than the Lexer. This is due to the fact that the Parser also uses the same Lexer. I'm soure there is some more elegant way to do this, but this patch at least unbreaks the C++ syntax highlighting.
2021-06-05LibCpp: Do not emit empty whitespace token after include statementMax Wipfli
If an include statement didn't contain whitespace between the word "include" and the '<' or '"', the lexer would previous emit an empty whitespace token. This has been changed now.
2021-06-05LibCpp: Use CharacterTypes.h and constexpr functions in LexerMax Wipfli
2021-06-05LibCpp: Use east const style in Lexer and SyntaxHighlighterMax Wipfli