OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "hashmap.h" | 32 #include "hashmap.h" |
33 #include "utils-inl.h" | 33 #include "utils-inl.h" |
34 | 34 |
35 namespace v8 { | 35 namespace v8 { |
36 namespace internal { | 36 namespace internal { |
37 | 37 |
38 | 38 |
39 // Abstract interface for preparse data recorder. | 39 // Abstract interface for preparse data recorder. |
40 class ParserRecorder { | 40 class ParserRecorder { |
41 public: | 41 public: |
42 ParserRecorder() : should_log_symbols_(false) { } | 42 ParserRecorder() { } |
43 virtual ~ParserRecorder() { } | 43 virtual ~ParserRecorder() { } |
44 | 44 |
45 // Logs the scope and some details of a function literal in the source. | 45 // Logs the scope and some details of a function literal in the source. |
46 virtual void LogFunction(int start, | 46 virtual void LogFunction(int start, |
47 int end, | 47 int end, |
48 int literals, | 48 int literals, |
49 int properties, | 49 int properties, |
50 StrictMode strict_mode) = 0; | 50 StrictMode strict_mode) = 0; |
51 | 51 |
52 // Logs an error message and marks the log as containing an error. | 52 // Logs an error message and marks the log as containing an error. |
53 // Further logging will be ignored, and ExtractData will return a vector | 53 // Further logging will be ignored, and ExtractData will return a vector |
54 // representing the error only. | 54 // representing the error only. |
55 virtual void LogMessage(int start, | 55 virtual void LogMessage(int start, |
56 int end, | 56 int end, |
57 const char* message, | 57 const char* message, |
58 const char* argument_opt, | 58 const char* argument_opt, |
59 bool is_reference_error) = 0; | 59 bool is_reference_error) = 0; |
60 | 60 |
61 // Logs a symbol creation of a literal or identifier. | |
62 bool ShouldLogSymbols() { return should_log_symbols_; } | |
63 // The following functions are only callable on CompleteParserRecorder | 61 // The following functions are only callable on CompleteParserRecorder |
64 // and are guarded by calls to ShouldLogSymbols. | 62 // and are guarded by calls to ShouldLogSymbols. |
65 virtual void LogOneByteSymbol(int start, Vector<const uint8_t> literal) { | 63 virtual void LogOneByteSymbol(int start, Vector<const uint8_t> literal) { |
66 UNREACHABLE(); | 64 UNREACHABLE(); |
67 } | 65 } |
68 virtual void LogTwoByteSymbol(int start, Vector<const uint16_t> literal) { | 66 virtual void LogTwoByteSymbol(int start, Vector<const uint16_t> literal) { |
69 UNREACHABLE(); | 67 UNREACHABLE(); |
70 } | 68 } |
71 virtual void PauseRecording() { UNREACHABLE(); } | |
72 virtual void ResumeRecording() { UNREACHABLE(); } | |
73 | |
74 protected: | |
75 bool should_log_symbols_; | |
76 | 69 |
77 private: | 70 private: |
78 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); | 71 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); |
79 }; | 72 }; |
80 | 73 |
81 | 74 |
82 class SingletonLogger : public ParserRecorder { | 75 class SingletonLogger : public ParserRecorder { |
83 public: | 76 public: |
84 SingletonLogger() | 77 SingletonLogger() |
85 : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {} | 78 : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {} |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 175 |
183 // Logs an error message and marks the log as containing an error. | 176 // Logs an error message and marks the log as containing an error. |
184 // Further logging will be ignored, and ExtractData will return a vector | 177 // Further logging will be ignored, and ExtractData will return a vector |
185 // representing the error only. | 178 // representing the error only. |
186 virtual void LogMessage(int start, | 179 virtual void LogMessage(int start, |
187 int end, | 180 int end, |
188 const char* message, | 181 const char* message, |
189 const char* argument_opt, | 182 const char* argument_opt, |
190 bool is_reference_error_); | 183 bool is_reference_error_); |
191 | 184 |
192 virtual void PauseRecording() { | |
193 ASSERT(should_log_symbols_); | |
194 should_log_symbols_ = false; | |
195 } | |
196 | |
197 virtual void ResumeRecording() { | |
198 ASSERT(!should_log_symbols_); | |
199 should_log_symbols_ = !has_error(); | |
200 } | |
201 | |
202 virtual void LogOneByteSymbol(int start, Vector<const uint8_t> literal); | 185 virtual void LogOneByteSymbol(int start, Vector<const uint8_t> literal); |
203 virtual void LogTwoByteSymbol(int start, Vector<const uint16_t> literal); | 186 virtual void LogTwoByteSymbol(int start, Vector<const uint16_t> literal); |
204 Vector<unsigned> ExtractData(); | 187 Vector<unsigned> ExtractData(); |
205 | 188 |
206 private: | 189 private: |
207 bool has_error() { | 190 bool has_error() { |
208 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); | 191 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); |
209 } | 192 } |
210 | 193 |
211 void WriteString(Vector<const char> str); | 194 void WriteString(Vector<const char> str); |
(...skipping 20 matching lines...) Expand all Loading... |
232 Collector<byte> symbol_store_; | 215 Collector<byte> symbol_store_; |
233 Collector<Key> symbol_keys_; | 216 Collector<Key> symbol_keys_; |
234 HashMap string_table_; | 217 HashMap string_table_; |
235 int symbol_id_; | 218 int symbol_id_; |
236 }; | 219 }; |
237 | 220 |
238 | 221 |
239 } } // namespace v8::internal. | 222 } } // namespace v8::internal. |
240 | 223 |
241 #endif // V8_PREPARSE_DATA_H_ | 224 #endif // V8_PREPARSE_DATA_H_ |
OLD | NEW |