| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_PREPARSE_DATA_H_ | 5 #ifndef V8_PREPARSE_DATA_H_ |
| 6 #define V8_PREPARSE_DATA_H_ | 6 #define V8_PREPARSE_DATA_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/hashmap.h" | 9 #include "src/hashmap.h" |
| 10 #include "src/messages.h" |
| 10 #include "src/preparse-data-format.h" | 11 #include "src/preparse-data-format.h" |
| 11 | 12 |
| 12 namespace v8 { | 13 namespace v8 { |
| 13 namespace internal { | 14 namespace internal { |
| 14 | 15 |
| 15 class ScriptData { | 16 class ScriptData { |
| 16 public: | 17 public: |
| 17 ScriptData(const byte* data, int length); | 18 ScriptData(const byte* data, int length); |
| 18 ~ScriptData() { | 19 ~ScriptData() { |
| 19 if (owns_data_) DeleteArray(data_); | 20 if (owns_data_) DeleteArray(data_); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 virtual ~ParserRecorder() { } | 52 virtual ~ParserRecorder() { } |
| 52 | 53 |
| 53 // Logs the scope and some details of a function literal in the source. | 54 // Logs the scope and some details of a function literal in the source. |
| 54 virtual void LogFunction(int start, int end, int literals, int properties, | 55 virtual void LogFunction(int start, int end, int literals, int properties, |
| 55 LanguageMode language_mode, | 56 LanguageMode language_mode, |
| 56 bool uses_super_property) = 0; | 57 bool uses_super_property) = 0; |
| 57 | 58 |
| 58 // Logs an error message and marks the log as containing an error. | 59 // Logs an error message and marks the log as containing an error. |
| 59 // Further logging will be ignored, and ExtractData will return a vector | 60 // Further logging will be ignored, and ExtractData will return a vector |
| 60 // representing the error only. | 61 // representing the error only. |
| 61 virtual void LogMessage(int start, int end, const char* message, | 62 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
| 62 const char* argument_opt, | 63 const char* argument_opt, |
| 63 ParseErrorType error_type) = 0; | 64 ParseErrorType error_type) = 0; |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); | 67 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 | 70 |
| 70 class SingletonLogger : public ParserRecorder { | 71 class SingletonLogger : public ParserRecorder { |
| 71 public: | 72 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 83 end_ = end; | 84 end_ = end; |
| 84 literals_ = literals; | 85 literals_ = literals; |
| 85 properties_ = properties; | 86 properties_ = properties; |
| 86 language_mode_ = language_mode; | 87 language_mode_ = language_mode; |
| 87 scope_uses_super_property_ = scope_uses_super_property; | 88 scope_uses_super_property_ = scope_uses_super_property; |
| 88 } | 89 } |
| 89 | 90 |
| 90 // Logs an error message and marks the log as containing an error. | 91 // Logs an error message and marks the log as containing an error. |
| 91 // Further logging will be ignored, and ExtractData will return a vector | 92 // Further logging will be ignored, and ExtractData will return a vector |
| 92 // representing the error only. | 93 // representing the error only. |
| 93 virtual void LogMessage(int start, int end, const char* message, | 94 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
| 94 const char* argument_opt, ParseErrorType error_type) { | 95 const char* argument_opt, ParseErrorType error_type) { |
| 95 if (has_error_) return; | 96 if (has_error_) return; |
| 96 has_error_ = true; | 97 has_error_ = true; |
| 97 start_ = start; | 98 start_ = start; |
| 98 end_ = end; | 99 end_ = end; |
| 99 message_ = message; | 100 message_ = message; |
| 100 argument_opt_ = argument_opt; | 101 argument_opt_ = argument_opt; |
| 101 error_type_ = error_type; | 102 error_type_ = error_type; |
| 102 } | 103 } |
| 103 | 104 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 118 return language_mode_; | 119 return language_mode_; |
| 119 } | 120 } |
| 120 bool scope_uses_super_property() const { | 121 bool scope_uses_super_property() const { |
| 121 DCHECK(!has_error_); | 122 DCHECK(!has_error_); |
| 122 return scope_uses_super_property_; | 123 return scope_uses_super_property_; |
| 123 } | 124 } |
| 124 ParseErrorType error_type() const { | 125 ParseErrorType error_type() const { |
| 125 DCHECK(has_error_); | 126 DCHECK(has_error_); |
| 126 return error_type_; | 127 return error_type_; |
| 127 } | 128 } |
| 128 const char* message() { | 129 MessageTemplate::Template message() { |
| 129 DCHECK(has_error_); | 130 DCHECK(has_error_); |
| 130 return message_; | 131 return message_; |
| 131 } | 132 } |
| 132 const char* argument_opt() const { | 133 const char* argument_opt() const { |
| 133 DCHECK(has_error_); | 134 DCHECK(has_error_); |
| 134 return argument_opt_; | 135 return argument_opt_; |
| 135 } | 136 } |
| 136 | 137 |
| 137 private: | 138 private: |
| 138 bool has_error_; | 139 bool has_error_; |
| 139 int start_; | 140 int start_; |
| 140 int end_; | 141 int end_; |
| 141 // For function entries. | 142 // For function entries. |
| 142 int literals_; | 143 int literals_; |
| 143 int properties_; | 144 int properties_; |
| 144 LanguageMode language_mode_; | 145 LanguageMode language_mode_; |
| 145 bool scope_uses_super_property_; | 146 bool scope_uses_super_property_; |
| 146 // For error messages. | 147 // For error messages. |
| 147 const char* message_; | 148 MessageTemplate::Template message_; |
| 148 const char* argument_opt_; | 149 const char* argument_opt_; |
| 149 ParseErrorType error_type_; | 150 ParseErrorType error_type_; |
| 150 }; | 151 }; |
| 151 | 152 |
| 152 | 153 |
| 153 class CompleteParserRecorder : public ParserRecorder { | 154 class CompleteParserRecorder : public ParserRecorder { |
| 154 public: | 155 public: |
| 155 struct Key { | 156 struct Key { |
| 156 bool is_one_byte; | 157 bool is_one_byte; |
| 157 Vector<const byte> literal_bytes; | 158 Vector<const byte> literal_bytes; |
| 158 }; | 159 }; |
| 159 | 160 |
| 160 CompleteParserRecorder(); | 161 CompleteParserRecorder(); |
| 161 virtual ~CompleteParserRecorder() {} | 162 virtual ~CompleteParserRecorder() {} |
| 162 | 163 |
| 163 virtual void LogFunction(int start, int end, int literals, int properties, | 164 virtual void LogFunction(int start, int end, int literals, int properties, |
| 164 LanguageMode language_mode, | 165 LanguageMode language_mode, |
| 165 bool scope_uses_super_property) { | 166 bool scope_uses_super_property) { |
| 166 function_store_.Add(start); | 167 function_store_.Add(start); |
| 167 function_store_.Add(end); | 168 function_store_.Add(end); |
| 168 function_store_.Add(literals); | 169 function_store_.Add(literals); |
| 169 function_store_.Add(properties); | 170 function_store_.Add(properties); |
| 170 function_store_.Add(language_mode); | 171 function_store_.Add(language_mode); |
| 171 function_store_.Add(scope_uses_super_property); | 172 function_store_.Add(scope_uses_super_property); |
| 172 } | 173 } |
| 173 | 174 |
| 174 // Logs an error message and marks the log as containing an error. | 175 // Logs an error message and marks the log as containing an error. |
| 175 // Further logging will be ignored, and ExtractData will return a vector | 176 // Further logging will be ignored, and ExtractData will return a vector |
| 176 // representing the error only. | 177 // representing the error only. |
| 177 virtual void LogMessage(int start, int end, const char* message, | 178 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
| 178 const char* argument_opt, ParseErrorType error_type); | 179 const char* argument_opt, ParseErrorType error_type); |
| 179 ScriptData* GetScriptData(); | 180 ScriptData* GetScriptData(); |
| 180 | 181 |
| 181 bool HasError() { | 182 bool HasError() { |
| 182 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); | 183 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); |
| 183 } | 184 } |
| 184 Vector<unsigned> ErrorMessageData() { | 185 Vector<unsigned> ErrorMessageData() { |
| 185 DCHECK(HasError()); | 186 DCHECK(HasError()); |
| 186 return function_store_.ToVector(); | 187 return function_store_.ToVector(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 private: | 190 private: |
| 190 void WriteString(Vector<const char> str); | 191 void WriteString(Vector<const char> str); |
| 191 | 192 |
| 192 // Write a non-negative number to the symbol store. | |
| 193 void WriteNumber(int number); | |
| 194 | |
| 195 Collector<unsigned> function_store_; | 193 Collector<unsigned> function_store_; |
| 196 unsigned preamble_[PreparseDataConstants::kHeaderSize]; | 194 unsigned preamble_[PreparseDataConstants::kHeaderSize]; |
| 197 | 195 |
| 198 #ifdef DEBUG | 196 #ifdef DEBUG |
| 199 int prev_start_; | 197 int prev_start_; |
| 200 #endif | 198 #endif |
| 201 }; | 199 }; |
| 202 | 200 |
| 203 | 201 |
| 204 } } // namespace v8::internal. | 202 } } // namespace v8::internal. |
| 205 | 203 |
| 206 #endif // V8_PREPARSE_DATA_H_ | 204 #endif // V8_PREPARSE_DATA_H_ |
| OLD | NEW |