| Index: src/parsing/parser-base.h
|
| diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
|
| index 3f006b4bb6aaa3b12e329a824789005dc4959f8b..999173f4c66673d196391a3b365ce3ee38c51f6f 100644
|
| --- a/src/parsing/parser-base.h
|
| +++ b/src/parsing/parser-base.h
|
| @@ -83,6 +83,41 @@ struct FormalParametersBase {
|
| int arity = 0;
|
| };
|
|
|
| +// Stack-allocated scope to collect source ranges from the parser.
|
| +class SourceRangeScope final {
|
| + public:
|
| + enum PositionKind {
|
| + POSITION,
|
| + PEEK_POS,
|
| + };
|
| +
|
| + SourceRangeScope(Scanner* scanner, SourceRange* range,
|
| + PositionKind pre_kind = PEEK_POS,
|
| + PositionKind post_kind = POSITION)
|
| + : scanner_(scanner), range_(range), post_kind_(post_kind) {
|
| + range_->start = GetPosition(pre_kind);
|
| + }
|
| +
|
| + ~SourceRangeScope() { range_->end = GetPosition(post_kind_); }
|
| +
|
| + private:
|
| + int32_t GetPosition(PositionKind kind) {
|
| + switch (post_kind_) {
|
| + case POSITION:
|
| + return scanner_->location().beg_pos;
|
| + case PEEK_POS:
|
| + return scanner_->peek_location().beg_pos;
|
| + default:
|
| + UNREACHABLE();
|
| + }
|
| + }
|
| +
|
| + Scanner* scanner_;
|
| + SourceRange* range_;
|
| + PositionKind post_kind_;
|
| +
|
| + DISALLOW_IMPLICIT_CONSTRUCTORS(SourceRangeScope);
|
| +};
|
|
|
| // ----------------------------------------------------------------------------
|
| // The CHECK_OK macro is a convenient macro to enforce error
|
| @@ -5145,15 +5180,23 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
|
| Expect(Token::LPAREN, CHECK_OK);
|
| ExpressionT condition = ParseExpression(true, CHECK_OK);
|
| Expect(Token::RPAREN, CHECK_OK);
|
| - StatementT then_statement = ParseScopedStatement(labels, CHECK_OK);
|
| +
|
| + SourceRange then_range, else_range;
|
| + StatementT then_statement = impl()->NullStatement();
|
| + {
|
| + SourceRangeScope range_scope(scanner(), &then_range);
|
| + then_statement = ParseScopedStatement(labels, CHECK_OK);
|
| + }
|
| +
|
| StatementT else_statement = impl()->NullStatement();
|
| if (Check(Token::ELSE)) {
|
| + SourceRangeScope range_scope(scanner(), &else_range);
|
| else_statement = ParseScopedStatement(labels, CHECK_OK);
|
| } else {
|
| else_statement = factory()->NewEmptyStatement(kNoSourcePosition);
|
| }
|
| return factory()->NewIfStatement(condition, then_statement, else_statement,
|
| - pos);
|
| + pos, then_range, else_range);
|
| }
|
|
|
| template <typename Impl>
|
|
|