Commit d975ca02 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Add dummy SourceRange tracking for PreParser

Change-Id: I05db378984b583d9dff3fe9fceb3adbf7e046e20
Reviewed-on: https://chromium-review.googlesource.com/1240338Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56180}
parent f2f48bd8
...@@ -21,8 +21,9 @@ struct SourceRange { ...@@ -21,8 +21,9 @@ struct SourceRange {
static SourceRange OpenEnded(int32_t start) { static SourceRange OpenEnded(int32_t start) {
return SourceRange(start, kNoSourcePosition); return SourceRange(start, kNoSourcePosition);
} }
static SourceRange ContinuationOf(const SourceRange& that) { static SourceRange ContinuationOf(const SourceRange& that,
return that.IsEmpty() ? Empty() : OpenEnded(that.end); int end = kNoSourcePosition) {
return that.IsEmpty() ? Empty() : SourceRange(that.end, end);
} }
int32_t start, end; int32_t start, end;
}; };
......
...@@ -245,6 +245,8 @@ class ParserBase { ...@@ -245,6 +245,8 @@ class ParserBase {
ExpressionClassifier; ExpressionClassifier;
typedef typename Types::FuncNameInferrer FuncNameInferrer; typedef typename Types::FuncNameInferrer FuncNameInferrer;
typedef typename Types::FuncNameInferrer::State FuncNameInferrerState; typedef typename Types::FuncNameInferrer::State FuncNameInferrerState;
typedef typename Types::SourceRange SourceRange;
typedef typename Types::SourceRangeScope SourceRangeScope;
// All implementation-specific methods must be called through this. // All implementation-specific methods must be called through this.
Impl* impl() { return static_cast<Impl*>(this); } Impl* impl() { return static_cast<Impl*>(this); }
...@@ -3158,10 +3160,6 @@ ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1, ...@@ -3158,10 +3160,6 @@ ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1,
right_range_scope.Finalize(); right_range_scope.Finalize();
ValidateExpression(CHECK_OK); ValidateExpression(CHECK_OK);
if (impl()->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos)) {
continue;
}
// For now we distinguish between comparisons and other binary // For now we distinguish between comparisons and other binary
// operations. (We could combine the two and get rid of this // operations. (We could combine the two and get rid of this
// code and AST node eventually.) // code and AST node eventually.)
...@@ -3178,9 +3176,9 @@ ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1, ...@@ -3178,9 +3176,9 @@ ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1,
// The comparison was negated - add a NOT. // The comparison was negated - add a NOT.
x = factory()->NewUnaryOperation(Token::NOT, x, pos); x = factory()->NewUnaryOperation(Token::NOT, x, pos);
} }
} else if (impl()->CollapseNaryExpression(&x, y, op, pos, right_range)) { } else if (!impl()->ShortcutNumericLiteralBinaryExpression(&x, y, op,
continue; pos) &&
} else { !impl()->CollapseNaryExpression(&x, y, op, pos, right_range)) {
// We have a "normal" binary operation. // We have a "normal" binary operation.
x = factory()->NewBinaryOperation(op, x, y, pos); x = factory()->NewBinaryOperation(op, x, y, pos);
if (op == Token::OR || op == Token::AND) { if (op == Token::OR || op == Token::AND) {
...@@ -5283,9 +5281,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement( ...@@ -5283,9 +5281,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
StatementT else_statement = impl()->NullStatement(); StatementT else_statement = impl()->NullStatement();
if (Check(Token::ELSE)) { if (Check(Token::ELSE)) {
else_range = SourceRange::ContinuationOf(then_range);
else_statement = ParseScopedStatement(labels, CHECK_OK); else_statement = ParseScopedStatement(labels, CHECK_OK);
else_range.end = end_position(); else_range = SourceRange::ContinuationOf(then_range, end_position());
} else { } else {
else_statement = factory()->NewEmptyStatement(kNoSourcePosition); else_statement = factory()->NewEmptyStatement(kNoSourcePosition);
} }
......
...@@ -136,6 +136,8 @@ struct ParserTypes<Parser> { ...@@ -136,6 +136,8 @@ struct ParserTypes<Parser> {
typedef v8::internal::ForStatement* ForStatement; typedef v8::internal::ForStatement* ForStatement;
typedef v8::internal::IterationStatement* IterationStatement; typedef v8::internal::IterationStatement* IterationStatement;
typedef v8::internal::FuncNameInferrer FuncNameInferrer; typedef v8::internal::FuncNameInferrer FuncNameInferrer;
typedef v8::internal::SourceRange SourceRange;
typedef v8::internal::SourceRangeScope SourceRangeScope;
// For constructing objects returned by the traversing functions. // For constructing objects returned by the traversing functions.
typedef AstNodeFactory Factory; typedef AstNodeFactory Factory;
......
...@@ -885,9 +885,9 @@ class PreParserTargetScope { ...@@ -885,9 +885,9 @@ class PreParserTargetScope {
class PreParserFuncNameInferrer { class PreParserFuncNameInferrer {
public: public:
PreParserFuncNameInferrer(AstValueFactory* avf, Zone* zone) {} PreParserFuncNameInferrer(AstValueFactory* avf, Zone* zone) {}
void RemoveAsyncKeywordFromEnd() {} void RemoveAsyncKeywordFromEnd() const {}
void Infer() {} void Infer() const {}
void RemoveLastFunction() {} void RemoveLastFunction() const {}
class State { class State {
public: public:
...@@ -901,6 +901,29 @@ class PreParserFuncNameInferrer { ...@@ -901,6 +901,29 @@ class PreParserFuncNameInferrer {
DISALLOW_COPY_AND_ASSIGN(PreParserFuncNameInferrer); DISALLOW_COPY_AND_ASSIGN(PreParserFuncNameInferrer);
}; };
class PreParserSourceRange {
public:
PreParserSourceRange() {}
PreParserSourceRange(int start, int end) {}
static PreParserSourceRange Empty() { return PreParserSourceRange(); }
static PreParserSourceRange OpenEnded(int32_t start) { return Empty(); }
static const PreParserSourceRange& ContinuationOf(
const PreParserSourceRange& that, int end) {
return that;
}
};
class PreParserSourceRangeScope {
public:
PreParserSourceRangeScope(Scanner* scanner, PreParserSourceRange* range) {}
const PreParserSourceRange& Finalize() const { return range_; }
private:
PreParserSourceRange range_;
DISALLOW_IMPLICIT_CONSTRUCTORS(PreParserSourceRangeScope);
};
template <> template <>
struct ParserTypes<PreParser> { struct ParserTypes<PreParser> {
typedef ParserBase<PreParser> Base; typedef ParserBase<PreParser> Base;
...@@ -931,6 +954,8 @@ struct ParserTypes<PreParser> { ...@@ -931,6 +954,8 @@ struct ParserTypes<PreParser> {
typedef PreParserTarget Target; typedef PreParserTarget Target;
typedef PreParserTargetScope TargetScope; typedef PreParserTargetScope TargetScope;
typedef PreParserFuncNameInferrer FuncNameInferrer; typedef PreParserFuncNameInferrer FuncNameInferrer;
typedef PreParserSourceRange SourceRange;
typedef PreParserSourceRangeScope SourceRangeScope;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment