Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 274 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| 279 bool default_export, bool* ok); | 275 bool default_export, bool* ok); |
| 280 Statement* ParseNativeDeclaration(bool* ok); | 276 Statement* ParseNativeDeclaration(bool* ok); |
| 281 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, | 277 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, |
| 282 ZoneList<const AstRawString*>* names, | 278 ZoneList<const AstRawString*>* names, |
| 283 bool* ok); | 279 bool* ok); |
| 284 void DeclareAndInitializeVariables( | 280 void DeclareAndInitializeVariables( |
| 285 Block* block, const DeclarationDescriptor* declaration_descriptor, | 281 Block* block, const DeclarationDescriptor* declaration_descriptor, |
| 286 const DeclarationParsingResult::Declaration* declaration, | 282 const DeclarationParsingResult::Declaration* declaration, |
| 287 ZoneList<const AstRawString*>* names, bool* ok); | 283 ZoneList<const AstRawString*>* names, bool* ok); |
| 284 ZoneList<const AstRawString*>* DeclareLabel( | |
| 285 ZoneList<const AstRawString*>* labels, Expression* expr, bool* ok); | |
| 286 bool ContainsLabel(ZoneList<const AstRawString*>* labels, | |
| 287 const AstRawString* label); | |
| 288 Expression* RewriteReturn(Expression* return_value, int pos); | |
| 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> { |
| 293 public: | 294 public: |
| 294 static void DeclareAndInitializeVariables( | 295 static void DeclareAndInitializeVariables( |
| 295 Parser* parser, Block* block, | 296 Parser* parser, Block* block, |
| 296 const DeclarationDescriptor* declaration_descriptor, | 297 const DeclarationDescriptor* declaration_descriptor, |
| 297 const DeclarationParsingResult::Declaration* declaration, | 298 const DeclarationParsingResult::Declaration* declaration, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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, | |
| 635 // excluding the case of 'this' which has been converted to | |
| 636 // 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(); |
|
adamk
2016/09/08 18:33:19
Can you add a TODO to remove this null check now t
nickie
2016/09/09 09:42:27
The DCHECK is for a non-existent AST node. I thin
adamk
2016/09/09 17:14:47
Ah, indeed, I forgot how AsWhatever works, this is
| |
| 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 |
| 654 V8_INLINE bool IsPrototype(const AstRawString* identifier) const { | 648 V8_INLINE bool IsPrototype(const AstRawString* identifier) const { |
| 655 return identifier == ast_value_factory()->prototype_string(); | 649 return identifier == ast_value_factory()->prototype_string(); |
| 656 } | 650 } |
| 657 | 651 |
| 658 V8_INLINE bool IsConstructor(const AstRawString* identifier) const { | 652 V8_INLINE bool IsConstructor(const AstRawString* identifier) const { |
| 659 return identifier == ast_value_factory()->constructor_string(); | 653 return identifier == ast_value_factory()->constructor_string(); |
| 660 } | 654 } |
| 661 | 655 |
| 662 V8_INLINE bool IsDirectEvalCall(Expression* expression) const { | 656 V8_INLINE bool IsDirectEvalCall(Expression* expression) const { |
| 663 if (!expression->IsCall()) return false; | 657 if (!expression->IsCall()) return false; |
| 664 expression = expression->AsCall()->expression(); | 658 expression = expression->AsCall()->expression(); |
| 665 return IsIdentifier(expression) && IsEval(AsIdentifier(expression)); | 659 return IsIdentifier(expression) && IsEval(AsIdentifier(expression)); |
| 666 } | 660 } |
| 667 | 661 |
| 668 V8_INLINE static bool IsBoilerplateProperty( | 662 V8_INLINE static bool IsBoilerplateProperty( |
| 669 ObjectLiteral::Property* property) { | 663 ObjectLiteral::Property* property) { |
| 670 return ObjectLiteral::IsBoilerplateProperty(property); | 664 return ObjectLiteral::IsBoilerplateProperty(property); |
| 671 } | 665 } |
| 672 | 666 |
| 667 V8_INLINE bool IsNative(Expression* expr) const { | |
| 668 return expr != nullptr && expr->AsVariableProxy() != nullptr && | |
|
adamk
2016/09/08 18:33:19
Can expr actually be NULL here?
marja
2016/09/09 08:44:59
Style nit:
How about:
expr->IsVariableProxy() &&
nickie
2016/09/09 09:42:26
Done. I also removed the !scanner()->literal_cont
nickie
2016/09/09 09:42:27
The DCHECK_NOT_NULL that I just introduced says no
adamk
2016/09/09 17:14:47
I'm fine without a TODO, this has very few callers
| |
| 669 expr->AsVariableProxy()->raw_name() == | |
| 670 ast_value_factory()->native_string() && | |
| 671 !scanner()->literal_contains_escapes(); | |
| 672 } | |
| 673 | |
| 673 V8_INLINE static bool IsArrayIndex(const AstRawString* string, | 674 V8_INLINE static bool IsArrayIndex(const AstRawString* string, |
| 674 uint32_t* index) { | 675 uint32_t* index) { |
| 675 return string->AsArrayIndex(index); | 676 return string->AsArrayIndex(index); |
| 676 } | 677 } |
| 677 | 678 |
| 678 V8_INLINE bool IsUseStrictDirective(Statement* statement) const { | 679 V8_INLINE bool IsUseStrictDirective(Statement* statement) const { |
| 679 return IsStringLiteral(statement, ast_value_factory()->use_strict_string()); | 680 return IsStringLiteral(statement, ast_value_factory()->use_strict_string()); |
| 680 } | 681 } |
| 681 | 682 |
| 682 V8_INLINE bool IsUseAsmDirective(Statement* statement) const { | 683 V8_INLINE bool IsUseAsmDirective(Statement* statement) const { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 // and we want to report the stack overflow later. | 817 // and we want to report the stack overflow later. |
| 817 return; | 818 return; |
| 818 } | 819 } |
| 819 pending_error_handler_.ReportMessageAt(source_location.beg_pos, | 820 pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
| 820 source_location.end_pos, message, | 821 source_location.end_pos, message, |
| 821 arg, error_type); | 822 arg, error_type); |
| 822 } | 823 } |
| 823 | 824 |
| 824 // "null" return type creators. | 825 // "null" return type creators. |
| 825 V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; } | 826 V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; } |
| 827 V8_INLINE static bool IsEmptyIdentifier(const AstRawString* name) { | |
| 828 return name == nullptr; | |
| 829 } | |
| 826 V8_INLINE static Expression* EmptyExpression() { return nullptr; } | 830 V8_INLINE static Expression* EmptyExpression() { return nullptr; } |
| 827 V8_INLINE static Literal* EmptyLiteral() { return nullptr; } | 831 V8_INLINE static Literal* EmptyLiteral() { return nullptr; } |
| 828 V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() { | 832 V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() { |
| 829 return nullptr; | 833 return nullptr; |
| 830 } | 834 } |
| 831 V8_INLINE static ClassLiteralProperty* EmptyClassLiteralProperty() { | 835 V8_INLINE static ClassLiteralProperty* EmptyClassLiteralProperty() { |
| 832 return nullptr; | 836 return nullptr; |
| 833 } | 837 } |
| 834 V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; } | 838 V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; } |
| 835 V8_INLINE static Block* NullBlock() { return nullptr; } | 839 V8_INLINE static Block* NullBlock() { return nullptr; } |
| 836 | 840 |
| 837 V8_INLINE static bool IsEmptyExpression(Expression* expr) { | 841 V8_INLINE static bool IsEmptyExpression(Expression* expr) { |
| 838 return expr == nullptr; | 842 return expr == nullptr; |
| 839 } | 843 } |
| 840 | 844 |
| 841 // Used in error return values. | 845 // Used in error return values. |
| 842 V8_INLINE static ZoneList<Expression*>* NullExpressionList() { | 846 V8_INLINE static ZoneList<Expression*>* NullExpressionList() { |
| 843 return nullptr; | 847 return nullptr; |
| 844 } | 848 } |
| 845 V8_INLINE static bool IsNullExpressionList(ZoneList<Expression*>* exprs) { | 849 V8_INLINE static bool IsNullExpressionList(ZoneList<Expression*>* exprs) { |
| 846 return exprs == nullptr; | 850 return exprs == nullptr; |
| 847 } | 851 } |
| 848 V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; } | 852 V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; } |
| 849 V8_INLINE static bool IsNullStatementList(ZoneList<Statement*>* stmts) { | 853 V8_INLINE static bool IsNullStatementList(ZoneList<Statement*>* stmts) { |
| 850 return stmts == nullptr; | 854 return stmts == nullptr; |
| 851 } | 855 } |
| 852 V8_INLINE static Statement* NullStatement() { return nullptr; } | 856 V8_INLINE static Statement* NullStatement() { return nullptr; } |
| 857 V8_INLINE bool IsNullStatement(Statement* stmt) { return stmt == nullptr; } | |
| 853 V8_INLINE bool IsNullOrEmptyStatement(Statement* stmt) { | 858 V8_INLINE bool IsNullOrEmptyStatement(Statement* stmt) { |
| 854 return stmt == nullptr || stmt->IsEmpty(); | 859 return stmt == nullptr || stmt->IsEmpty(); |
| 855 } | 860 } |
| 856 | 861 |
| 857 // Non-NULL empty string. | 862 // Non-NULL empty string. |
| 858 V8_INLINE const AstRawString* EmptyIdentifierString() const { | 863 V8_INLINE const AstRawString* EmptyIdentifierString() const { |
| 859 return ast_value_factory()->empty_string(); | 864 return ast_value_factory()->empty_string(); |
| 860 } | 865 } |
| 861 | 866 |
| 862 // Odd-ball literal creators. | 867 // Odd-ball literal creators. |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1049 | 1054 |
| 1050 #ifdef DEBUG | 1055 #ifdef DEBUG |
| 1051 void Print(AstNode* node); | 1056 void Print(AstNode* node); |
| 1052 #endif // DEBUG | 1057 #endif // DEBUG |
| 1053 }; | 1058 }; |
| 1054 | 1059 |
| 1055 } // namespace internal | 1060 } // namespace internal |
| 1056 } // namespace v8 | 1061 } // namespace v8 |
| 1057 | 1062 |
| 1058 #endif // V8_PARSING_PARSER_H_ | 1063 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |