| 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_PARSER_H_ | 5 #ifndef V8_PARSER_H_ |
| 6 #define V8_PARSER_H_ | 6 #define V8_PARSER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/compiler.h" // For CachedDataMode | 10 #include "src/compiler.h" // For CachedDataMode |
| 11 #include "src/preparse-data.h" | 11 #include "src/preparse-data.h" |
| 12 #include "src/preparse-data-format.h" | 12 #include "src/preparse-data-format.h" |
| 13 #include "src/preparser.h" | 13 #include "src/preparser.h" |
| 14 #include "src/scopes.h" | 14 #include "src/scopes.h" |
| 15 | 15 |
| 16 namespace v8 { | 16 namespace v8 { |
| 17 class ScriptCompiler; | 17 class ScriptCompiler; |
| 18 | 18 |
| 19 namespace internal { | 19 namespace internal { |
| 20 | 20 |
| 21 class CompilationInfo; | 21 class CompilationInfo; |
| 22 class ParserLog; | 22 class ParserLog; |
| 23 class PositionStack; | 23 class PositionStack; |
| 24 class Target; | 24 class Target; |
| 25 | 25 |
| 26 template <typename T> class ZoneListWrapper; | 26 template <typename T> class ZoneListWrapper; |
| 27 | 27 |
| 28 | 28 |
| 29 // An entry in ScriptData containing everything we need to know to skip over a |
| 30 // lazily-parsed function body. |
| 29 class FunctionEntry BASE_EMBEDDED { | 31 class FunctionEntry BASE_EMBEDDED { |
| 30 public: | 32 public: |
| 31 enum { | 33 enum { |
| 32 kStartPositionIndex, | 34 kStartPositionIndex, |
| 33 kEndPositionIndex, | 35 kEndPositionIndex, |
| 34 kLiteralCountIndex, | 36 kLiteralCountIndex, |
| 35 kPropertyCountIndex, | 37 kPropertyCountIndex, |
| 36 kStrictModeIndex, | 38 kStrictModeIndex, |
| 39 kCallsEvalIndex, |
| 40 kIdentifierCountIndex, |
| 37 kSize | 41 kSize |
| 38 }; | 42 }; |
| 39 | 43 |
| 40 explicit FunctionEntry(Vector<unsigned> backing) | 44 explicit FunctionEntry(Vector<unsigned> backing) |
| 41 : backing_(backing) { } | 45 : backing_(backing) { } |
| 42 | 46 |
| 43 FunctionEntry() : backing_() { } | 47 FunctionEntry() : backing_() { } |
| 44 | 48 |
| 49 // Get the length (number of unsigned ints) of this FunctionEntry. |
| 50 // This requires walking through all the identifiers in the FunctionEntry, so |
| 51 // Size() is not a trivial accessor, and is typically only called once for |
| 52 // each FunctionEntry. |
| 53 int Size(); |
| 54 |
| 55 class IdentifierIterator { |
| 56 friend class FunctionEntry; |
| 57 |
| 58 public: |
| 59 const AstRawString* Next(AstValueFactory* ast_value_factory); |
| 60 |
| 61 bool AtEnd() { return backing_.is_empty(); } |
| 62 |
| 63 private: |
| 64 explicit IdentifierIterator(Vector<unsigned> backing) : backing_(backing) {} |
| 65 |
| 66 Vector<unsigned> backing_; |
| 67 }; |
| 68 |
| 69 IdentifierIterator Identifiers() { |
| 70 return IdentifierIterator(backing_.SubVector(kSize, Size())); |
| 71 } |
| 72 |
| 45 int start_pos() { return backing_[kStartPositionIndex]; } | 73 int start_pos() { return backing_[kStartPositionIndex]; } |
| 46 int end_pos() { return backing_[kEndPositionIndex]; } | 74 int end_pos() { return backing_[kEndPositionIndex]; } |
| 47 int literal_count() { return backing_[kLiteralCountIndex]; } | 75 int literal_count() { return backing_[kLiteralCountIndex]; } |
| 48 int property_count() { return backing_[kPropertyCountIndex]; } | 76 int property_count() { return backing_[kPropertyCountIndex]; } |
| 49 StrictMode strict_mode() { | 77 StrictMode strict_mode() { |
| 50 DCHECK(backing_[kStrictModeIndex] == SLOPPY || | 78 DCHECK(backing_[kStrictModeIndex] == SLOPPY || |
| 51 backing_[kStrictModeIndex] == STRICT); | 79 backing_[kStrictModeIndex] == STRICT); |
| 52 return static_cast<StrictMode>(backing_[kStrictModeIndex]); | 80 return static_cast<StrictMode>(backing_[kStrictModeIndex]); |
| 53 } | 81 } |
| 82 bool calls_eval() { return static_cast<bool>(backing_[kCallsEvalIndex]); } |
| 83 |
| 84 int identifier_count() { return backing_[kIdentifierCountIndex]; } |
| 54 | 85 |
| 55 bool is_valid() { return !backing_.is_empty(); } | 86 bool is_valid() { return !backing_.is_empty(); } |
| 56 | 87 |
| 57 private: | 88 private: |
| 58 Vector<unsigned> backing_; | 89 Vector<unsigned> backing_; |
| 59 }; | 90 }; |
| 60 | 91 |
| 61 | 92 |
| 62 // Wrapper around ScriptData to provide parser-specific functionality. | 93 // Wrapper around ScriptData to provide parser-specific functionality. |
| 63 class ParseData { | 94 class ParseData { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 // TODO(marja): To be removed. The Traits object should contain all the data | 379 // TODO(marja): To be removed. The Traits object should contain all the data |
| 349 // it needs. | 380 // it needs. |
| 350 typedef v8::internal::Parser* Parser; | 381 typedef v8::internal::Parser* Parser; |
| 351 | 382 |
| 352 // Used by FunctionState and BlockState. | 383 // Used by FunctionState and BlockState. |
| 353 typedef v8::internal::Scope Scope; | 384 typedef v8::internal::Scope Scope; |
| 354 typedef v8::internal::Scope* ScopePtr; | 385 typedef v8::internal::Scope* ScopePtr; |
| 355 inline static Scope* ptr_to_scope(ScopePtr scope) { return scope; } | 386 inline static Scope* ptr_to_scope(ScopePtr scope) { return scope; } |
| 356 | 387 |
| 357 typedef Variable GeneratorVariable; | 388 typedef Variable GeneratorVariable; |
| 358 typedef v8::internal::Zone Zone; | |
| 359 | 389 |
| 360 typedef v8::internal::AstProperties AstProperties; | 390 typedef v8::internal::AstProperties AstProperties; |
| 361 typedef Vector<VariableProxy*> ParameterIdentifierVector; | 391 typedef Vector<VariableProxy*> ParameterIdentifierVector; |
| 362 | 392 |
| 363 // Return types for traversing functions. | 393 // Return types for traversing functions. |
| 364 typedef const AstRawString* Identifier; | 394 typedef const AstRawString* Identifier; |
| 365 typedef v8::internal::Expression* Expression; | 395 typedef v8::internal::Expression* Expression; |
| 366 typedef Yield* YieldExpression; | 396 typedef Yield* YieldExpression; |
| 367 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 397 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
| 368 typedef v8::internal::ClassLiteral* ClassLiteral; | 398 typedef v8::internal::ClassLiteral* ClassLiteral; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 471 |
| 442 // Keep track of eval() calls since they disable all local variable | 472 // Keep track of eval() calls since they disable all local variable |
| 443 // optimizations. This checks if expression is an eval call, and if yes, | 473 // optimizations. This checks if expression is an eval call, and if yes, |
| 444 // forwards the information to scope. | 474 // forwards the information to scope. |
| 445 void CheckPossibleEvalCall(Expression* expression, Scope* scope); | 475 void CheckPossibleEvalCall(Expression* expression, Scope* scope); |
| 446 | 476 |
| 447 // Determine if the expression is a variable proxy and mark it as being used | 477 // Determine if the expression is a variable proxy and mark it as being used |
| 448 // in an assignment or with a increment/decrement operator. | 478 // in an assignment or with a increment/decrement operator. |
| 449 static Expression* MarkExpressionAsAssigned(Expression* expression); | 479 static Expression* MarkExpressionAsAssigned(Expression* expression); |
| 450 | 480 |
| 481 static void RecordCurrentSymbolAsIdentifierExpression() {} |
| 482 |
| 451 // Returns true if we have a binary expression between two numeric | 483 // Returns true if we have a binary expression between two numeric |
| 452 // literals. In that case, *x will be changed to an expression which is the | 484 // literals. In that case, *x will be changed to an expression which is the |
| 453 // computed value. | 485 // computed value. |
| 454 bool ShortcutNumericLiteralBinaryExpression( | 486 bool ShortcutNumericLiteralBinaryExpression( |
| 455 Expression** x, Expression* y, Token::Value op, int pos, | 487 Expression** x, Expression* y, Token::Value op, int pos, |
| 456 AstNodeFactory<AstConstructionVisitor>* factory); | 488 AstNodeFactory<AstConstructionVisitor>* factory); |
| 457 | 489 |
| 458 // Rewrites the following types of unary expressions: | 490 // Rewrites the following types of unary expressions: |
| 459 // not <literal> -> true / false | 491 // not <literal> -> true / false |
| 460 // + <numeric literal> -> <numeric literal> | 492 // + <numeric literal> -> <numeric literal> |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 private: | 951 private: |
| 920 static const int kLiteralTypeSlot = 0; | 952 static const int kLiteralTypeSlot = 0; |
| 921 static const int kElementsSlot = 1; | 953 static const int kElementsSlot = 1; |
| 922 | 954 |
| 923 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 955 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 924 }; | 956 }; |
| 925 | 957 |
| 926 } } // namespace v8::internal | 958 } } // namespace v8::internal |
| 927 | 959 |
| 928 #endif // V8_PARSER_H_ | 960 #endif // V8_PARSER_H_ |
| OLD | NEW |