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

Unified Diff: src/parser.h

Issue 13450007: Refactor parser mode configuration for correctness (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 7 years, 8 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/liveedit.cc ('k') | src/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index c65a4ca5f3a46b08a91e139849301e736f3bd888..1a90d1b2f263866617b63f2821529c02d776d3e6 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -163,17 +163,17 @@ class ScriptDataImpl : public ScriptData {
};
-class ParserApi {
+class PreParserApi {
public:
- // Parses the source code represented by the compilation info and sets its
- // function literal. Returns false (and deallocates any allocated AST
- // nodes) if parsing failed.
- static bool Parse(CompilationInfo* info, int flags);
-
- // Generic preparser generating full preparse data.
+ // Pre-parse a character stream and return full preparse data.
+ //
+ // This interface is here instead of in preparser.h because it instantiates a
+ // preparser recorder object that is suited to the parser's purposes. Also,
+ // the preparser doesn't know about ScriptDataImpl.
static ScriptDataImpl* PreParse(Utf16CharacterStream* source);
};
+
// ----------------------------------------------------------------------------
// REGEXP PARSING
@@ -425,18 +425,34 @@ class SingletonLogger;
class Parser {
public:
- Parser(CompilationInfo* info,
- int parsing_flags, // Combination of ParsingFlags
- v8::Extension* extension,
- ScriptDataImpl* pre_data);
+ explicit Parser(CompilationInfo* info);
virtual ~Parser() {
delete reusable_preparser_;
reusable_preparser_ = NULL;
}
+ bool allow_natives_syntax() const { return allow_natives_syntax_; }
+ bool allow_lazy() const { return allow_lazy_; }
+ bool allow_modules() { return scanner().HarmonyModules(); }
+ bool allow_harmony_scoping() { return scanner().HarmonyScoping(); }
+ bool allow_generators() const { return allow_generators_; }
+
+ void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; }
+ void set_allow_lazy(bool allow) { allow_lazy_ = allow; }
+ void set_allow_modules(bool allow) { scanner().SetHarmonyModules(allow); }
+ void set_allow_harmony_scoping(bool allow) {
+ scanner().SetHarmonyScoping(allow);
+ }
+ void set_allow_generators(bool allow) { allow_generators_ = allow; }
+
+ // Parses the source code represented by the compilation info and sets its
+ // function literal. Returns false (and deallocates any allocated AST
+ // nodes) if parsing failed.
+ static bool Parse(CompilationInfo* info) { return Parser(info).Parse(); }
+ bool Parse();
+
// Returns NULL if parsing failed.
FunctionLiteral* ParseProgram();
- FunctionLiteral* ParseLazy();
void ReportMessageAt(Scanner::Location loc,
const char* message,
@@ -550,6 +566,7 @@ class Parser {
Mode old_mode_;
};
+ FunctionLiteral* ParseLazy();
FunctionLiteral* ParseLazy(Utf16CharacterStream* source,
ZoneScope* zone_scope);
@@ -568,10 +585,15 @@ class Parser {
void ReportMessage(const char* message, Vector<const char*> args);
void ReportMessage(const char* message, Vector<Handle<String> > args);
+ void set_pre_parse_data(ScriptDataImpl *data) {
+ pre_parse_data_ = data;
+ symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone());
+ }
+
bool inside_with() const { return top_scope_->inside_with(); }
Scanner& scanner() { return scanner_; }
Mode mode() const { return mode_; }
- ScriptDataImpl* pre_data() const { return pre_data_; }
+ ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
bool is_extended_mode() {
ASSERT(top_scope_ != NULL);
return top_scope_->is_extended_mode();
@@ -833,13 +855,13 @@ class Parser {
FunctionState* current_function_state_;
Target* target_stack_; // for break, continue statements
v8::Extension* extension_;
- ScriptDataImpl* pre_data_;
+ ScriptDataImpl* pre_parse_data_;
FuncNameInferrer* fni_;
Mode mode_;
bool allow_natives_syntax_;
bool allow_lazy_;
- bool allow_modules_;
+ bool allow_generators_;
bool stack_overflow_;
// If true, the next (and immediately following) function literal is
// preceded by a parenthesis.
« no previous file with comments | « src/liveedit.cc ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698