-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[LLDB] Add array subscription and integer parsing to DIL #138551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ad204cd
54af853
95d3950
7235b4a
c7c9a0a
3f295ce
9ea4312
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,10 @@ class Token { | |
| eof, | ||
| identifier, | ||
| l_paren, | ||
| l_square, | ||
| numeric_constant, | ||
| r_paren, | ||
| r_square, | ||
| star, | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,42 @@ ASTNodeUP DILParser::ParseUnaryExpression() { | |
| llvm_unreachable("invalid token kind"); | ||
| } | ||
| } | ||
| return ParsePrimaryExpression(); | ||
| return ParsePostfixExpression(); | ||
| } | ||
|
|
||
| // Parse a postfix_expression. | ||
| // | ||
| // postfix_expression: | ||
| // primary_expression | ||
| // postfix_expression "[" integer_literal "]" | ||
| // | ||
| ASTNodeUP DILParser::ParsePostfixExpression() { | ||
| ASTNodeUP lhs = ParsePrimaryExpression(); | ||
| while (CurToken().Is(Token::l_square)) { | ||
| uint32_t loc = CurToken().GetLocation(); | ||
| Token token = CurToken(); | ||
| switch (token.GetKind()) { | ||
| case Token::l_square: { | ||
|
Comment on lines
+128
to
+129
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point? You've already checked the type three lines above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for when other postfix expressions get added here,
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay... I guess that makes sense... |
||
| m_dil_lexer.Advance(); | ||
| std::optional<int64_t> rhs = ParseIntegerConstant(); | ||
| if (!rhs) { | ||
| BailOut( | ||
| llvm::formatv("failed to parse integer constant: {0}", CurToken()), | ||
| CurToken().GetLocation(), CurToken().GetSpelling().length()); | ||
| return std::make_unique<ErrorNode>(); | ||
| } | ||
| Expect(Token::r_square); | ||
| m_dil_lexer.Advance(); | ||
| lhs = std::make_unique<ArraySubscriptNode>(loc, std::move(lhs), | ||
| std::move(*rhs)); | ||
| break; | ||
| } | ||
| default: | ||
| llvm_unreachable("invalid token"); | ||
| } | ||
| } | ||
|
|
||
| return lhs; | ||
| } | ||
|
|
||
| // Parse a primary_expression. | ||
|
|
@@ -280,6 +315,23 @@ void DILParser::BailOut(const std::string &error, uint32_t loc, | |
| m_dil_lexer.ResetTokenIdx(m_dil_lexer.NumLexedTokens() - 1); | ||
| } | ||
|
|
||
| // Parse a integer_literal. | ||
| // | ||
| // integer_literal: | ||
| // ? Integer constant ? | ||
| // | ||
| std::optional<int64_t> DILParser::ParseIntegerConstant() { | ||
| auto spelling = CurToken().GetSpelling(); | ||
| llvm::StringRef spelling_ref = spelling; | ||
| int64_t raw_value; | ||
| if (!spelling_ref.getAsInteger<int64_t>(0, raw_value)) { | ||
| m_dil_lexer.Advance(); | ||
| return raw_value; | ||
| } | ||
|
|
||
| return std::nullopt; | ||
| } | ||
|
|
||
| void DILParser::Expect(Token::Kind kind) { | ||
| if (CurToken().IsNot(kind)) { | ||
| BailOut(llvm::formatv("expected {0}, got: {1}", kind, CurToken()), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically, this has nothing to do with the type. A formatter can (and we have formatters that do that) return different numbers of children for different values of the same type.
I think you can just delete the comment as it's kinda obvious..