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

Side by Side Diff: src/parsing/parser.h

Issue 2323763002: [parser] Refactor of Parse*Statement*, part 4 (Closed)
Patch Set: Rebase 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PARSING_PARSER_H_ 5 #ifndef V8_PARSING_PARSER_H_
6 #define V8_PARSING_PARSER_H_ 6 #define V8_PARSING_PARSER_H_
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/parsing/parser-base.h" 10 #include "src/parsing/parser-base.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 typedef v8::internal::Expression* Expression; 150 typedef v8::internal::Expression* Expression;
151 typedef v8::internal::FunctionLiteral* FunctionLiteral; 151 typedef v8::internal::FunctionLiteral* FunctionLiteral;
152 typedef ObjectLiteral::Property* ObjectLiteralProperty; 152 typedef ObjectLiteral::Property* ObjectLiteralProperty;
153 typedef ClassLiteral::Property* ClassLiteralProperty; 153 typedef ClassLiteral::Property* ClassLiteralProperty;
154 typedef ZoneList<v8::internal::Expression*>* ExpressionList; 154 typedef ZoneList<v8::internal::Expression*>* ExpressionList;
155 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; 155 typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
156 typedef ParserFormalParameters FormalParameters; 156 typedef ParserFormalParameters FormalParameters;
157 typedef v8::internal::Statement* Statement; 157 typedef v8::internal::Statement* Statement;
158 typedef ZoneList<v8::internal::Statement*>* StatementList; 158 typedef ZoneList<v8::internal::Statement*>* StatementList;
159 typedef v8::internal::Block* Block; 159 typedef v8::internal::Block* Block;
160 typedef v8::internal::BreakableStatement* BreakableStatementT;
161 typedef v8::internal::IterationStatement* IterationStatementT;
160 162
161 // For constructing objects returned by the traversing functions. 163 // For constructing objects returned by the traversing functions.
162 typedef AstNodeFactory Factory; 164 typedef AstNodeFactory Factory;
163 165
164 typedef ParserTarget Target; 166 typedef ParserTarget Target;
165 typedef ParserTargetScope TargetScope; 167 typedef ParserTargetScope TargetScope;
166 }; 168 };
167 169
168 class Parser : public ParserBase<Parser> { 170 class Parser : public ParserBase<Parser> {
169 public: 171 public:
(...skipping 26 matching lines...) Expand all
196 198
197 // Runtime encoding of different completion modes. 199 // Runtime encoding of different completion modes.
198 enum CompletionKind { 200 enum CompletionKind {
199 kNormalCompletion, 201 kNormalCompletion,
200 kThrowCompletion, 202 kThrowCompletion,
201 kAbruptCompletion 203 kAbruptCompletion
202 }; 204 };
203 205
204 enum class FunctionBodyType { kNormal, kSingleExpression }; 206 enum class FunctionBodyType { kNormal, kSingleExpression };
205 207
206 DeclarationScope* GetDeclarationScope() const {
207 return scope()->GetDeclarationScope();
208 }
209 DeclarationScope* GetClosureScope() const {
210 return scope()->GetClosureScope();
211 }
212 Variable* NewTemporary(const AstRawString* name) { 208 Variable* NewTemporary(const AstRawString* name) {
213 return scope()->NewTemporary(name); 209 return scope()->NewTemporary(name);
214 } 210 }
215 211
216 // Limit the allowed number of local variables in a function. The hard limit 212 // Limit the allowed number of local variables in a function. The hard limit
217 // is that offsets computed by FullCodeGenerator::StackOperand and similar 213 // is that offsets computed by FullCodeGenerator::StackOperand and similar
218 // functions are ints, and they should not overflow. In addition, accessing 214 // functions are ints, and they should not overflow. In addition, accessing
219 // local variables creates user-controlled constants in the generated code, 215 // local variables creates user-controlled constants in the generated code,
220 // and we don't want too much user-controlled memory inside the code (this was 216 // and we don't want too much user-controlled memory inside the code (this was
221 // the reason why this limit was introduced in the first place; see 217 // the reason why this limit was introduced in the first place; see
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, 269 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names,
274 bool default_export, bool* ok); 270 bool default_export, bool* ok);
275 Statement* ParseNativeDeclaration(bool* ok); 271 Statement* ParseNativeDeclaration(bool* ok);
276 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, 272 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result,
277 ZoneList<const AstRawString*>* names, 273 ZoneList<const AstRawString*>* names,
278 bool* ok); 274 bool* ok);
279 void DeclareAndInitializeVariables( 275 void DeclareAndInitializeVariables(
280 Block* block, const DeclarationDescriptor* declaration_descriptor, 276 Block* block, const DeclarationDescriptor* declaration_descriptor,
281 const DeclarationParsingResult::Declaration* declaration, 277 const DeclarationParsingResult::Declaration* declaration,
282 ZoneList<const AstRawString*>* names, bool* ok); 278 ZoneList<const AstRawString*>* names, bool* ok);
279 ZoneList<const AstRawString*>* DeclareLabel(
280 ZoneList<const AstRawString*>* labels, VariableProxy* expr, bool* ok);
281 bool ContainsLabel(ZoneList<const AstRawString*>* labels,
282 const AstRawString* label);
283 Expression* RewriteReturn(Expression* return_value, int pos);
283 284
284 Statement* DeclareFunction(const AstRawString* variable_name, 285 Statement* DeclareFunction(const AstRawString* variable_name,
285 FunctionLiteral* function, int pos, 286 FunctionLiteral* function, int pos,
286 bool is_generator, bool is_async, 287 bool is_generator, bool is_async,
287 ZoneList<const AstRawString*>* names, bool* ok); 288 ZoneList<const AstRawString*>* names, bool* ok);
288 289
289 DoExpression* ParseDoExpression(bool* ok); 290 DoExpression* ParseDoExpression(bool* ok);
290 Expression* ParseYieldStarExpression(bool* ok); 291 Expression* ParseYieldStarExpression(bool* ok);
291 292
292 class PatternRewriter final : public AstVisitor<PatternRewriter> { 293 class PatternRewriter final : public AstVisitor<PatternRewriter> {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 Block* block_; 364 Block* block_;
364 const DeclarationDescriptor* descriptor_; 365 const DeclarationDescriptor* descriptor_;
365 ZoneList<const AstRawString*>* names_; 366 ZoneList<const AstRawString*>* names_;
366 Expression* current_value_; 367 Expression* current_value_;
367 int recursion_level_; 368 int recursion_level_;
368 bool* ok_; 369 bool* ok_;
369 370
370 DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW() 371 DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW()
371 }; 372 };
372 373
373 Statement* ParseExpressionOrLabelledStatement(
374 ZoneList<const AstRawString*>* labels,
375 AllowLabelledFunctionStatement allow_function, bool* ok);
376 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels,
377 bool* ok);
378 Statement* ParseContinueStatement(bool* ok);
379 Statement* ParseBreakStatement(ZoneList<const AstRawString*>* labels,
380 bool* ok);
381 Statement* ParseReturnStatement(bool* ok);
382 Statement* ParseWithStatement(ZoneList<const AstRawString*>* labels,
383 bool* ok);
384 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); 374 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok);
385 Statement* ParseSwitchStatement(ZoneList<const AstRawString*>* labels, 375 Statement* ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
386 bool* ok); 376 bool* ok);
387 DoWhileStatement* ParseDoWhileStatement(ZoneList<const AstRawString*>* labels, 377 DoWhileStatement* ParseDoWhileStatement(ZoneList<const AstRawString*>* labels,
388 bool* ok); 378 bool* ok);
389 WhileStatement* ParseWhileStatement(ZoneList<const AstRawString*>* labels, 379 WhileStatement* ParseWhileStatement(ZoneList<const AstRawString*>* labels,
390 bool* ok); 380 bool* ok);
391 Statement* ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok); 381 Statement* ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok);
392 Statement* ParseThrowStatement(bool* ok); 382 Statement* ParseThrowStatement(bool* ok);
393 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); 383 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value);
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 } 624 }
635 625
636 // Returns true if the expression is of type "this.foo". 626 // Returns true if the expression is of type "this.foo".
637 V8_INLINE static bool IsThisProperty(Expression* expression) { 627 V8_INLINE static bool IsThisProperty(Expression* expression) {
638 DCHECK(expression != NULL); 628 DCHECK(expression != NULL);
639 Property* property = expression->AsProperty(); 629 Property* property = expression->AsProperty();
640 return property != NULL && property->obj()->IsVariableProxy() && 630 return property != NULL && property->obj()->IsVariableProxy() &&
641 property->obj()->AsVariableProxy()->is_this(); 631 property->obj()->AsVariableProxy()->is_this();
642 } 632 }
643 633
634 // This returns true if the expression is an indentifier (wrapped
635 // inside a variable proxy). We exclude the case of 'this', which
636 // has been converted to a variable proxy.
644 V8_INLINE static bool IsIdentifier(Expression* expression) { 637 V8_INLINE static bool IsIdentifier(Expression* expression) {
638 DCHECK_NOT_NULL(expression);
645 VariableProxy* operand = expression->AsVariableProxy(); 639 VariableProxy* operand = expression->AsVariableProxy();
646 return operand != NULL && !operand->is_this(); 640 return operand != nullptr && !operand->is_this();
647 } 641 }
648 642
649 V8_INLINE static const AstRawString* AsIdentifier(Expression* expression) { 643 V8_INLINE static const AstRawString* AsIdentifier(Expression* expression) {
650 DCHECK(IsIdentifier(expression)); 644 DCHECK(IsIdentifier(expression));
651 return expression->AsVariableProxy()->raw_name(); 645 return expression->AsVariableProxy()->raw_name();
652 } 646 }
653 647
648 V8_INLINE VariableProxy* AsIdentifierExpression(Expression* expression) {
649 return expression->AsVariableProxy();
650 }
651
654 V8_INLINE bool IsPrototype(const AstRawString* identifier) const { 652 V8_INLINE bool IsPrototype(const AstRawString* identifier) const {
655 return identifier == ast_value_factory()->prototype_string(); 653 return identifier == ast_value_factory()->prototype_string();
656 } 654 }
657 655
658 V8_INLINE bool IsConstructor(const AstRawString* identifier) const { 656 V8_INLINE bool IsConstructor(const AstRawString* identifier) const {
659 return identifier == ast_value_factory()->constructor_string(); 657 return identifier == ast_value_factory()->constructor_string();
660 } 658 }
661 659
662 V8_INLINE bool IsDirectEvalCall(Expression* expression) const { 660 V8_INLINE bool IsDirectEvalCall(Expression* expression) const {
663 if (!expression->IsCall()) return false; 661 if (!expression->IsCall()) return false;
664 expression = expression->AsCall()->expression(); 662 expression = expression->AsCall()->expression();
665 return IsIdentifier(expression) && IsEval(AsIdentifier(expression)); 663 return IsIdentifier(expression) && IsEval(AsIdentifier(expression));
666 } 664 }
667 665
668 V8_INLINE static bool IsBoilerplateProperty( 666 V8_INLINE static bool IsBoilerplateProperty(
669 ObjectLiteral::Property* property) { 667 ObjectLiteral::Property* property) {
670 return ObjectLiteral::IsBoilerplateProperty(property); 668 return ObjectLiteral::IsBoilerplateProperty(property);
671 } 669 }
672 670
671 V8_INLINE bool IsNative(Expression* expr) const {
672 DCHECK_NOT_NULL(expr);
673 return expr->IsVariableProxy() &&
674 expr->AsVariableProxy()->raw_name() ==
675 ast_value_factory()->native_string();
676 }
677
673 V8_INLINE static bool IsArrayIndex(const AstRawString* string, 678 V8_INLINE static bool IsArrayIndex(const AstRawString* string,
674 uint32_t* index) { 679 uint32_t* index) {
675 return string->AsArrayIndex(index); 680 return string->AsArrayIndex(index);
676 } 681 }
677 682
678 V8_INLINE bool IsUseStrictDirective(Statement* statement) const { 683 V8_INLINE bool IsUseStrictDirective(Statement* statement) const {
679 return IsStringLiteral(statement, ast_value_factory()->use_strict_string()); 684 return IsStringLiteral(statement, ast_value_factory()->use_strict_string());
680 } 685 }
681 686
682 V8_INLINE bool IsUseAsmDirective(Statement* statement) const { 687 V8_INLINE bool IsUseAsmDirective(Statement* statement) const {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // and we want to report the stack overflow later. 833 // and we want to report the stack overflow later.
829 return; 834 return;
830 } 835 }
831 pending_error_handler_.ReportMessageAt(source_location.beg_pos, 836 pending_error_handler_.ReportMessageAt(source_location.beg_pos,
832 source_location.end_pos, message, 837 source_location.end_pos, message,
833 arg, error_type); 838 arg, error_type);
834 } 839 }
835 840
836 // "null" return type creators. 841 // "null" return type creators.
837 V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; } 842 V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; }
843 V8_INLINE static bool IsEmptyIdentifier(const AstRawString* name) {
844 return name == nullptr;
845 }
838 V8_INLINE static Expression* EmptyExpression() { return nullptr; } 846 V8_INLINE static Expression* EmptyExpression() { return nullptr; }
839 V8_INLINE static Literal* EmptyLiteral() { return nullptr; } 847 V8_INLINE static Literal* EmptyLiteral() { return nullptr; }
840 V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() { 848 V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() {
841 return nullptr; 849 return nullptr;
842 } 850 }
843 V8_INLINE static ClassLiteralProperty* EmptyClassLiteralProperty() { 851 V8_INLINE static ClassLiteralProperty* EmptyClassLiteralProperty() {
844 return nullptr; 852 return nullptr;
845 } 853 }
846 V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; } 854 V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; }
847 V8_INLINE static Block* NullBlock() { return nullptr; } 855 V8_INLINE static Block* NullBlock() { return nullptr; }
848 856
849 V8_INLINE static bool IsEmptyExpression(Expression* expr) { 857 V8_INLINE static bool IsEmptyExpression(Expression* expr) {
850 return expr == nullptr; 858 return expr == nullptr;
851 } 859 }
852 860
853 // Used in error return values. 861 // Used in error return values.
854 V8_INLINE static ZoneList<Expression*>* NullExpressionList() { 862 V8_INLINE static ZoneList<Expression*>* NullExpressionList() {
855 return nullptr; 863 return nullptr;
856 } 864 }
857 V8_INLINE static bool IsNullExpressionList(ZoneList<Expression*>* exprs) { 865 V8_INLINE static bool IsNullExpressionList(ZoneList<Expression*>* exprs) {
858 return exprs == nullptr; 866 return exprs == nullptr;
859 } 867 }
860 V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; } 868 V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; }
861 V8_INLINE static bool IsNullStatementList(ZoneList<Statement*>* stmts) { 869 V8_INLINE static bool IsNullStatementList(ZoneList<Statement*>* stmts) {
862 return stmts == nullptr; 870 return stmts == nullptr;
863 } 871 }
864 V8_INLINE static Statement* NullStatement() { return nullptr; } 872 V8_INLINE static Statement* NullStatement() { return nullptr; }
865 V8_INLINE bool IsNullOrEmptyStatement(Statement* stmt) { 873 V8_INLINE bool IsNullStatement(Statement* stmt) { return stmt == nullptr; }
866 return stmt == nullptr || stmt->IsEmpty(); 874 V8_INLINE bool IsEmptyStatement(Statement* stmt) {
875 DCHECK_NOT_NULL(stmt);
876 return stmt->IsEmpty();
867 } 877 }
868 878
869 // Non-NULL empty string. 879 // Non-NULL empty string.
870 V8_INLINE const AstRawString* EmptyIdentifierString() const { 880 V8_INLINE const AstRawString* EmptyIdentifierString() const {
871 return ast_value_factory()->empty_string(); 881 return ast_value_factory()->empty_string();
872 } 882 }
873 883
874 // Odd-ball literal creators. 884 // Odd-ball literal creators.
875 V8_INLINE Literal* GetLiteralTheHole(int position) { 885 V8_INLINE Literal* GetLiteralTheHole(int position) {
876 return factory()->NewTheHoleLiteral(kNoSourcePosition); 886 return factory()->NewTheHoleLiteral(kNoSourcePosition);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 1071
1062 #ifdef DEBUG 1072 #ifdef DEBUG
1063 void Print(AstNode* node); 1073 void Print(AstNode* node);
1064 #endif // DEBUG 1074 #endif // DEBUG
1065 }; 1075 };
1066 1076
1067 } // namespace internal 1077 } // namespace internal
1068 } // namespace v8 1078 } // namespace v8
1069 1079
1070 #endif // V8_PARSING_PARSER_H_ 1080 #endif // V8_PARSING_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698