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

Unified Diff: src/parsing/parser.h

Issue 2307073002: [parser] Refactor of Parse*Statement*, part 1 (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | src/parsing/parser.cc » ('j') | src/parsing/parser-base.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.h
diff --git a/src/parsing/parser.h b/src/parsing/parser.h
index 38695495545aa9d69e4d6dee9adb7b42fd748472..10754415e19449ee8fa83980441a7b89c90b5a62 100644
--- a/src/parsing/parser.h
+++ b/src/parsing/parser.h
@@ -21,7 +21,8 @@ namespace internal {
class ParseInfo;
class ScriptData;
-class Target;
+class ParserTarget;
+class ParserTargetScope;
class FunctionEntry BASE_EMBEDDED {
public:
@@ -152,11 +153,15 @@ struct ParserTypes<Parser> {
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
typedef ParserFormalParameters FormalParameters;
+ typedef v8::internal::Statement* Statement;
typedef ZoneList<v8::internal::Statement*>* StatementList;
typedef v8::internal::Block* Block;
// For constructing objects returned by the traversing functions.
typedef AstNodeFactory Factory;
+
+ typedef ParserTarget Target;
+ typedef ParserTargetScope TargetScope;
};
class Parser : public ParserBase<Parser> {
@@ -243,8 +248,6 @@ class Parser : public ParserBase<Parser> {
// which is set to false if parsing failed; it is unchanged otherwise.
// By making the 'exception handling' explicit, we are forced to check
// for failure at the call sites.
- void ParseStatementList(ZoneList<Statement*>* body, int end_token, bool* ok);
- Statement* ParseStatementListItem(bool* ok);
void ParseModuleItemList(ZoneList<Statement*>* body, bool* ok);
Statement* ParseModuleItem(bool* ok);
const AstRawString* ParseModuleSpecifier(bool* ok);
@@ -266,14 +269,6 @@ class Parser : public ParserBase<Parser> {
location(location) {}
};
ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok);
- Statement* ParseStatement(ZoneList<const AstRawString*>* labels,
- AllowLabelledFunctionStatement allow_function,
- bool* ok);
- Statement* ParseSubStatement(ZoneList<const AstRawString*>* labels,
- AllowLabelledFunctionStatement allow_function,
- bool* ok);
- Statement* ParseStatementAsUnlabelled(ZoneList<const AstRawString*>* labels,
- bool* ok);
Statement* ParseFunctionDeclaration(bool* ok);
Statement* ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
bool default_export, bool* ok);
@@ -580,7 +575,7 @@ class Parser : public ParserBase<Parser> {
int pos);
void SetLanguageMode(Scope* scope, LanguageMode mode);
- void RaiseLanguageMode(LanguageMode mode);
+ void SetAsmModule();
V8_INLINE void MarkCollectedTailCallExpressions();
V8_INLINE void MarkTailPosition(Expression* expression);
@@ -702,6 +697,32 @@ class Parser : public ParserBase<Parser> {
return string->AsArrayIndex(index);
}
+ V8_INLINE bool IsUseStrictDirective(Statement* statement) const {
+ ExpressionStatement* e_stat = statement->AsExpressionStatement();
+ if (e_stat == nullptr) return false;
+ Literal* literal = e_stat->expression()->AsLiteral();
+ if (literal == nullptr || !literal->raw_value()->IsString()) return false;
+ return literal->raw_value()->AsString() ==
+ ast_value_factory()->use_strict_string();
+ }
+
+ V8_INLINE bool IsUseAsmDirective(Statement* statement) const {
+ ExpressionStatement* e_stat = statement->AsExpressionStatement();
+ if (e_stat == nullptr) return false;
+ Literal* literal = e_stat->expression()->AsLiteral();
+ if (literal == nullptr || !literal->raw_value()->IsString()) return false;
+ return literal->raw_value()->AsString() ==
+ ast_value_factory()->use_asm_string();
marja 2016/09/05 08:14:33 Nit: these 2 functions are almost duplicate, the o
nickie 2016/09/05 11:29:31 Done. I merged both with IsStringLiteral.
+ }
+
+ V8_INLINE bool IsStringLiteral(Statement* statement) const {
+ ExpressionStatement* e_stat = statement->AsExpressionStatement();
+ if (e_stat == nullptr) return false;
+ Literal* literal = e_stat->expression()->AsLiteral();
+ if (literal == nullptr || !literal->raw_value()->IsString()) return false;
+ return true;
+ }
+
V8_INLINE static Expression* GetPropertyValue(
ObjectLiteral::Property* property) {
return property->value();
@@ -848,7 +869,17 @@ class Parser : public ParserBase<Parser> {
V8_INLINE static ZoneList<Expression*>* NullExpressionList() {
return nullptr;
}
+ V8_INLINE static bool IsNullExpressionList(ZoneList<Expression*>* exprs) {
+ return exprs == nullptr;
+ }
V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; }
+ V8_INLINE static bool IsNullStatementList(ZoneList<Statement*>* stmts) {
+ return stmts == nullptr;
+ }
+ V8_INLINE static Statement* NullStatement() { return nullptr; }
+ V8_INLINE bool IsNullOrEmptyStatement(Statement* stmt) {
+ return stmt == nullptr || stmt->IsEmpty();
+ }
// Non-NULL empty string.
V8_INLINE const AstRawString* EmptyIdentifierString() const {
@@ -1010,7 +1041,11 @@ class Parser : public ParserBase<Parser> {
Scanner scanner_;
PreParser* reusable_preparser_;
Scope* original_scope_; // for ES5 function declarations in sloppy eval
- Target* target_stack_; // for break, continue statements
+
+ friend class ParserTarget;
+ friend class ParserTargetScope;
+ ParserTarget* target_stack_; // for break, continue statements
+
ScriptCompiler::CompileOptions compile_options_;
ParseData* cached_parse_data_;
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698