| 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 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 bool is_valid() { return !backing_.is_empty(); } | 55 bool is_valid() { return !backing_.is_empty(); } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 Vector<unsigned> backing_; | 58 Vector<unsigned> backing_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 | 61 |
| 62 // Wrapper around ScriptData to provide parser-specific functionality. | 62 // Wrapper around ScriptData to provide parser-specific functionality. |
| 63 class ParseData { | 63 class ParseData { |
| 64 public: | 64 public: |
| 65 explicit ParseData(ScriptData* script_data) : script_data_(script_data) { | 65 static ParseData* FromCachedData(ScriptData* cached_data) { |
| 66 CHECK(IsAligned(script_data->length(), sizeof(unsigned))); | 66 ParseData* pd = new ParseData(cached_data); |
| 67 CHECK(IsSane()); | 67 if (pd->IsSane()) return pd; |
| 68 cached_data->Reject(); |
| 69 delete pd; |
| 70 return NULL; |
| 68 } | 71 } |
| 72 |
| 69 void Initialize(); | 73 void Initialize(); |
| 70 FunctionEntry GetFunctionEntry(int start); | 74 FunctionEntry GetFunctionEntry(int start); |
| 71 int FunctionCount(); | 75 int FunctionCount(); |
| 72 | 76 |
| 73 bool HasError(); | 77 bool HasError(); |
| 74 | 78 |
| 75 unsigned* Data() { // Writable data as unsigned int array. | 79 unsigned* Data() { // Writable data as unsigned int array. |
| 76 return reinterpret_cast<unsigned*>(const_cast<byte*>(script_data_->data())); | 80 return reinterpret_cast<unsigned*>(const_cast<byte*>(script_data_->data())); |
| 77 } | 81 } |
| 78 | 82 |
| 79 private: | 83 private: |
| 84 explicit ParseData(ScriptData* script_data) : script_data_(script_data) {} |
| 85 |
| 80 bool IsSane(); | 86 bool IsSane(); |
| 81 unsigned Magic(); | 87 unsigned Magic(); |
| 82 unsigned Version(); | 88 unsigned Version(); |
| 83 int FunctionsSize(); | 89 int FunctionsSize(); |
| 84 int Length() const { | 90 int Length() const { |
| 85 // Script data length is already checked to be a multiple of unsigned size. | 91 // Script data length is already checked to be a multiple of unsigned size. |
| 86 return script_data_->length() / sizeof(unsigned); | 92 return script_data_->length() / sizeof(unsigned); |
| 87 } | 93 } |
| 88 | 94 |
| 89 ScriptData* script_data_; | 95 ScriptData* script_data_; |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 // Called by ParseProgram after setting up the scanner. | 721 // Called by ParseProgram after setting up the scanner. |
| 716 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope, | 722 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope, |
| 717 Scope** ad_hoc_eval_scope); | 723 Scope** ad_hoc_eval_scope); |
| 718 | 724 |
| 719 void SetCachedData(); | 725 void SetCachedData(); |
| 720 | 726 |
| 721 bool inside_with() const { return scope_->inside_with(); } | 727 bool inside_with() const { return scope_->inside_with(); } |
| 722 ScriptCompiler::CompileOptions compile_options() const { | 728 ScriptCompiler::CompileOptions compile_options() const { |
| 723 return info_->compile_options(); | 729 return info_->compile_options(); |
| 724 } | 730 } |
| 731 bool consume_cached_parse_data() const { |
| 732 return compile_options() == ScriptCompiler::kConsumeParserCache && |
| 733 cached_parse_data_ != NULL; |
| 734 } |
| 735 bool produce_cached_parse_data() const { |
| 736 return compile_options() == ScriptCompiler::kProduceParserCache; |
| 737 } |
| 725 Scope* DeclarationScope(VariableMode mode) { | 738 Scope* DeclarationScope(VariableMode mode) { |
| 726 return IsLexicalVariableMode(mode) | 739 return IsLexicalVariableMode(mode) |
| 727 ? scope_ : scope_->DeclarationScope(); | 740 ? scope_ : scope_->DeclarationScope(); |
| 728 } | 741 } |
| 729 | 742 |
| 730 // All ParseXXX functions take as the last argument an *ok parameter | 743 // All ParseXXX functions take as the last argument an *ok parameter |
| 731 // which is set to false if parsing failed; it is unchanged otherwise. | 744 // which is set to false if parsing failed; it is unchanged otherwise. |
| 732 // By making the 'exception handling' explicit, we are forced to check | 745 // By making the 'exception handling' explicit, we are forced to check |
| 733 // for failure at the call sites. | 746 // for failure at the call sites. |
| 734 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 747 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 } | 1003 } |
| 991 | 1004 |
| 992 | 1005 |
| 993 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, | 1006 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, |
| 994 int start, Expression* tag) { | 1007 int start, Expression* tag) { |
| 995 return parser_->CloseTemplateLiteral(state, start, tag); | 1008 return parser_->CloseTemplateLiteral(state, start, tag); |
| 996 } | 1009 } |
| 997 } } // namespace v8::internal | 1010 } } // namespace v8::internal |
| 998 | 1011 |
| 999 #endif // V8_PARSER_H_ | 1012 #endif // V8_PARSER_H_ |
| OLD | NEW |