Reviewers: ,
Message:
Committed patchset #1 manually as r18183 (presubmit successful).
Description:
Experimental scanner: fix harmony flag setting.
Also, a misc fix: reusable preparser depends on scanner, so it has to
be recreated whenever scanner is.
BUG=
[email protected]
Committed: https://code.google.com/p/v8/source/detail?r=18183
Please review this at https://codereview.chromium.org/98863002/
SVN Base: https://v8.googlecode.com/svn/branches/experimental/parser
Affected files (+50, -37 lines):
M src/lexer/experimental-scanner.h
M src/lexer/lexer-shell.cc
M src/parser.h
M src/parser.cc
M src/preparser.h
Index: src/lexer/experimental-scanner.h
diff --git a/src/lexer/experimental-scanner.h
b/src/lexer/experimental-scanner.h
index
ab07ef62e5bda4f91e33e2225421777452ce0912..b85aa770befa19715e420f7d4ef9dfa44b9e1abe
100644
--- a/src/lexer/experimental-scanner.h
+++ b/src/lexer/experimental-scanner.h
@@ -88,6 +88,29 @@ class ScannerBase {
}
}
+ // Has to be called after creating the scanner and setting the flags.
+ virtual void Init() = 0;
+
+ // Seek forward to the given position. This operation works for simple
cases
+ // such as seeking forward until simple delimiter tokens, which is what
it is
+ // used for. After this call, we will have the token at the given
position as
+ // the "next" token. The "current" token will be invalid. FIXME: for
utf-8,
+ // we need to decide if pos is counted in characters or in bytes.
+ virtual void SeekForward(int pos) = 0;
+ virtual void SetEnd(int pos) = 0;
+
+ // Scans the input as a regular expression pattern, previous
character(s) must
+ // be /(=). Returns true if a pattern is scanned. FIXME: this won't work
for
+ // utf-8 newlines.
+ virtual bool ScanRegExpPattern(bool seen_equal) = 0;
+ // Returns true if regexp flags are scanned (always since flags can
+ // be empty).
+ virtual bool ScanRegExpFlags() = 0;
+
+ // Returns the location of the last seen octal literal.
+ virtual Location octal_position() const = 0;
+ virtual void clear_octal_position() = 0;
+
// Returns the next token and advances input.
Token::Value Next() {
has_line_terminator_before_next_ = false;
@@ -217,26 +240,6 @@ class ScannerBase {
(memcmp(literal.start(), keyword.start(), literal.length()) == 0);
}
- // Seek forward to the given position. This operation works for simple
cases
- // such as seeking forward until simple delimiter tokens, which is what
it is
- // used for. After this call, we will have the token at the given
position as
- // the "next" token. The "current" token will be invalid. FIXME: for
utf-8,
- // we need to decide if pos is counted in characters or in bytes.
- virtual void SeekForward(int pos) = 0;
- virtual void SetEnd(int pos) = 0;
-
- // Scans the input as a regular expression pattern, previous
character(s) must
- // be /(=). Returns true if a pattern is scanned. FIXME: this won't work
for
- // utf-8 newlines.
- virtual bool ScanRegExpPattern(bool seen_equal) = 0;
- // Returns true if regexp flags are scanned (always since flags can
- // be empty).
- virtual bool ScanRegExpFlags() = 0;
-
- // Returns the location of the last seen octal literal.
- virtual Location octal_position() const = 0;
- virtual void clear_octal_position() = 0;
-
protected:
struct TokenDesc {
Token::Value token;
@@ -299,6 +302,9 @@ class ExperimentalScanner : public ScannerBase {
last_octal_end_(NULL) {
ASSERT(source->IsFlat());
SetBufferBasedOnHandle();
+ }
+
+ virtual void Init() {
Scan();
}
Index: src/lexer/lexer-shell.cc
diff --git a/src/lexer/lexer-shell.cc b/src/lexer/lexer-shell.cc
index
83d273935b20fdd14983d4bd7657fe38ea91a8ff..5cc6e8b7294af2d3f03db67b21fc0b847bee1dd0
100644
--- a/src/lexer/lexer-shell.cc
+++ b/src/lexer/lexer-shell.cc
@@ -267,12 +267,13 @@ TimeDelta RunExperimentalScanner(Handle<String>
source,
int repeat,
HarmonySettings harmony_settings) {
ElapsedTimer timer;
- timer.Start();
ExperimentalScanner<Char> scanner(source, isolate);
scanner.SetHarmonyNumericLiterals(harmony_settings.numeric_literals);
scanner.SetHarmonyModules(harmony_settings.modules);
scanner.SetHarmonyScoping(harmony_settings.scoping);
+ timer.Start();
+ scanner.Init();
Token::Value token;
do {
token = scanner.Next();
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
08bc948f0b82067ef3a6c0e47199c579be103853..b56e1fd15dd3ae5e8342f35fe50d0f08b7f37414
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -553,12 +553,7 @@ Parser::Parser(CompilationInfo* info)
info_(info) {
ASSERT(!script_.is_null());
isolate_->set_ast_node_id(0);
- // FIXME: these can be done only when the ExperimentalScanner has been
- // created, and they need to be redone when it's recreated.
- // set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
- // set_allow_modules(!info->is_native() && FLAG_harmony_modules);
set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
- // set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
set_allow_lazy(false); // Must be explicitly enabled.
set_allow_generators(FLAG_harmony_generators);
set_allow_for_of(FLAG_harmony_iteration);
@@ -581,19 +576,17 @@ FunctionLiteral* Parser::ParseProgram() {
FlattenString(source);
FunctionLiteral* result;
if (source->IsTwoByteRepresentation()) {
- // Notice that the stream is destroyed at the end of the branch block.
- // The last line of the blocks can't be moved outside, even though
they're
- // identical calls. // FIXME
+ delete reusable_preparser_;
delete scanner_;
scanner_ = new ExperimentalScanner<uint16_t>(source, isolate());
- // FIXME: set flags
- result = DoParseProgram(info(), source);
} else {
+ delete reusable_preparser_;
delete scanner_;
scanner_ = new ExperimentalScanner<uint8_t>(source, isolate());
- // FIXME: set flags
- result = DoParseProgram(info(), source);
}
+ SetScannerFlags();
+ scanner_->Init();
+ result = DoParseProgram(info(), source);
if (FLAG_trace_parse && result != NULL) {
double ms = timer.Elapsed().InMillisecondsF();
@@ -725,15 +718,17 @@ FunctionLiteral* Parser::ParseLazy() {
FunctionLiteral* Parser::ParseLazy(Handle<String> source, int start, int
end) {
+ delete reusable_preparser_;
delete scanner_;
if (source->IsTwoByteRepresentation()) {
scanner_ = new ExperimentalScanner<uint16_t>(source, isolate());
} else {
scanner_ = new ExperimentalScanner<uint8_t>(source, isolate());
}
+ SetScannerFlags();
+ // We don't need to Init() if we immediately SeekForward.
scanner_->SeekForward(start);
scanner_->SetEnd(end);
- // FIXME: set flags
Handle<SharedFunctionInfo> shared_info = info()->shared_info();
ASSERT(top_scope_ == NULL);
@@ -5674,4 +5669,11 @@ bool Parser::Parse() {
return (result != NULL);
}
+
+void Parser::SetScannerFlags() {
+ scanner_->SetHarmonyScoping(!info_->is_native() && FLAG_harmony_scoping);
+ scanner_->SetHarmonyModules(!info_->is_native() && FLAG_harmony_modules);
+ scanner_->SetHarmonyNumericLiterals(FLAG_harmony_numeric_literals);
+}
+
} } // namespace v8::internal
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index
e546ec4bc9af10453032eb2803b54095a6c90888..e5024b931b2d5782fcdf1123e241a6b9a38f7f09
100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -414,8 +414,6 @@ class Parser : public ParserBase {
~Parser() {
delete reusable_preparser_;
reusable_preparser_ = NULL;
- delete scanner_;
- scanner_ = NULL;
}
// Parses the source code represented by the compilation info and sets
its
@@ -761,6 +759,8 @@ class Parser : public ParserBase {
return current_function_state_->factory();
}
+ void SetScannerFlags();
+
Isolate* isolate_;
ZoneList<Handle<String> > symbol_cache_;
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
4dfa19c7d2b2bd061b5fa9eb8a818e2ce367baa2..3cbd0dd9e557d5bb1c670bd0444863abcd1853dd
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -48,7 +48,11 @@ class ParserBase {
allow_generators_(false),
allow_for_of_(false) { }
// TODO(mstarzinger): Only virtual until message reporting has been
unified.
- virtual ~ParserBase() { }
+ // FIXME: Might need to continue to be virtual for the experimental
branch.
+ virtual ~ParserBase() {
+ delete scanner_;
+ scanner_ = NULL;
+ }
// Getters that indicate whether certain syntactical constructs are
// allowed to be parsed by this instance of the parser.
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.