Revision: 18183
Author:   [email protected]
Date:     Mon Dec  2 11:45:18 2013 UTC
Log:      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]

Review URL: https://codereview.chromium.org/98863002
http://code.google.com/p/v8/source/detail?r=18183

Modified:
 /branches/experimental/parser/src/lexer/experimental-scanner.h
 /branches/experimental/parser/src/lexer/lexer-shell.cc
 /branches/experimental/parser/src/parser.cc
 /branches/experimental/parser/src/parser.h
 /branches/experimental/parser/src/preparser.h

=======================================
--- /branches/experimental/parser/src/lexer/experimental-scanner.h Fri Nov 29 15:14:11 2013 UTC +++ /branches/experimental/parser/src/lexer/experimental-scanner.h Mon Dec 2 11:45:18 2013 UTC
@@ -87,6 +87,29 @@
       scanners_ = NULL;
     }
   }
+
+  // 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() {
@@ -216,26 +239,6 @@
     return literal.length() == keyword.length() &&
         (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 {
@@ -299,6 +302,9 @@
         last_octal_end_(NULL) {
     ASSERT(source->IsFlat());
     SetBufferBasedOnHandle();
+  }
+
+  virtual void Init() {
     Scan();
   }

=======================================
--- /branches/experimental/parser/src/lexer/lexer-shell.cc Fri Nov 29 10:35:20 2013 UTC +++ /branches/experimental/parser/src/lexer/lexer-shell.cc Mon Dec 2 11:45:18 2013 UTC
@@ -267,12 +267,13 @@
                                  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();
=======================================
--- /branches/experimental/parser/src/parser.cc Mon Dec  2 10:38:54 2013 UTC
+++ /branches/experimental/parser/src/parser.cc Mon Dec  2 11:45:18 2013 UTC
@@ -553,12 +553,7 @@
       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 @@
   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(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);
@@ -5673,5 +5668,12 @@
   info()->SetFunction(result);
   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
=======================================
--- /branches/experimental/parser/src/parser.h  Wed Nov 27 13:01:38 2013 UTC
+++ /branches/experimental/parser/src/parser.h  Mon Dec  2 11:45:18 2013 UTC
@@ -414,8 +414,6 @@
   ~Parser() {
     delete reusable_preparser_;
     reusable_preparser_ = NULL;
-    delete scanner_;
-    scanner_ = NULL;
   }

// Parses the source code represented by the compilation info and sets its
@@ -760,6 +758,8 @@
   AstNodeFactory<AstConstructionVisitor>* factory() {
     return current_function_state_->factory();
   }
+
+  void SetScannerFlags();

   Isolate* isolate_;
   ZoneList<Handle<String> > symbol_cache_;
=======================================
--- /branches/experimental/parser/src/preparser.h Wed Nov 27 13:01:38 2013 UTC +++ /branches/experimental/parser/src/preparser.h Mon Dec 2 11:45:18 2013 UTC
@@ -48,7 +48,11 @@
         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.

Reply via email to