Skip to content

Commit 54f9f7a

Browse files
authored
[NFC] Simplify lexer and move to header (#8597)
The lexer previously used its own internal `LexerCtx` abstraction that allowed it to consume the characters that made up a token without changing the lexer state, then update the state at once when committing to consuming the characters. However, manually resetting the lexer to the original position when giving up on parsing a token is simple enough that this abstraction was not holding its weight. Simplify the lexer by removing internal contexts, and move the simplified method bodies to lexer.h. Generally we try to avoid putting lots of code in headers, but in this case making the code available to the inliner, along with removing the extra layer of abstraction, makes the parser about 20% faster.
1 parent 1f65c57 commit 54f9f7a

File tree

5 files changed

+1038
-1259
lines changed

5 files changed

+1038
-1259
lines changed

src/parser/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ FILE(GLOB parser_HEADERS *.h)
22
set(parser_SOURCES
33
context-decls.cpp
44
context-defs.cpp
5-
lexer.cpp
65
parse-1-decls.cpp
76
parse-2-typedefs.cpp
87
parse-3-implicit-types.cpp

src/parser/contexts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx>, AnnotationParserCtx {
19851985
void setSrcLoc(const std::vector<Annotation>& annotations) {
19861986
const Annotation* annotation = nullptr;
19871987
for (auto& a : annotations) {
1988-
if (a.kind == srcAnnotationKind) {
1988+
if (a.kind.str == std::string_view("src")) {
19891989
annotation = &a;
19901990
}
19911991
}

0 commit comments

Comments
 (0)