Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: src/parsing/parser-base.h

Issue 2882973002: [coverage] Block coverage with support for IfStatements (Closed)
Patch Set: Address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects/shared-function-info.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « src/objects/shared-function-info.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698