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 = NULL; | |
vogelheim
2014/11/13 13:01:15
Memory leak?
Who owns/deletes (*cached_data)?
| |
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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 // Called by ParseProgram after setting up the scanner. | 687 // Called by ParseProgram after setting up the scanner. |
682 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope, | 688 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope, |
683 Scope** ad_hoc_eval_scope); | 689 Scope** ad_hoc_eval_scope); |
684 | 690 |
685 void SetCachedData(); | 691 void SetCachedData(); |
686 | 692 |
687 bool inside_with() const { return scope_->inside_with(); } | 693 bool inside_with() const { return scope_->inside_with(); } |
688 ScriptCompiler::CompileOptions compile_options() const { | 694 ScriptCompiler::CompileOptions compile_options() const { |
689 return info_->compile_options(); | 695 return info_->compile_options(); |
690 } | 696 } |
697 bool consume_cached_parse_data() const { | |
698 return compile_options() == ScriptCompiler::kConsumeParserCache && | |
699 cached_parse_data_ != NULL; | |
700 } | |
701 bool produce_cached_parse_data() const { | |
702 return compile_options() == ScriptCompiler::kProduceParserCache; | |
703 } | |
691 Scope* DeclarationScope(VariableMode mode) { | 704 Scope* DeclarationScope(VariableMode mode) { |
692 return IsLexicalVariableMode(mode) | 705 return IsLexicalVariableMode(mode) |
693 ? scope_ : scope_->DeclarationScope(); | 706 ? scope_ : scope_->DeclarationScope(); |
694 } | 707 } |
695 | 708 |
696 // All ParseXXX functions take as the last argument an *ok parameter | 709 // All ParseXXX functions take as the last argument an *ok parameter |
697 // which is set to false if parsing failed; it is unchanged otherwise. | 710 // which is set to false if parsing failed; it is unchanged otherwise. |
698 // By making the 'exception handling' explicit, we are forced to check | 711 // By making the 'exception handling' explicit, we are forced to check |
699 // for failure at the call sites. | 712 // for failure at the call sites. |
700 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 713 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 private: | 935 private: |
923 static const int kLiteralTypeSlot = 0; | 936 static const int kLiteralTypeSlot = 0; |
924 static const int kElementsSlot = 1; | 937 static const int kElementsSlot = 1; |
925 | 938 |
926 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 939 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
927 }; | 940 }; |
928 | 941 |
929 } } // namespace v8::internal | 942 } } // namespace v8::internal |
930 | 943 |
931 #endif // V8_PARSER_H_ | 944 #endif // V8_PARSER_H_ |
OLD | NEW |