| 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/messages.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // Abstract interface for preparse data recorder. | 48 // Abstract interface for preparse data recorder. |
| 49 class ParserRecorder { | 49 class ParserRecorder { |
| 50 public: | 50 public: |
| 51 ParserRecorder() { } | 51 ParserRecorder() { } |
| 52 virtual ~ParserRecorder() { } | 52 virtual ~ParserRecorder() { } |
| 53 | 53 |
| 54 // 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. |
| 55 virtual void LogFunction(int start, int end, int literals, int properties, | 55 virtual void LogFunction(int start, int end, int literals, int properties, |
| 56 LanguageMode language_mode, bool uses_super_property, | 56 LanguageMode language_mode, AsmMode asm_mode, |
| 57 bool calls_eval) = 0; | 57 bool uses_super_property, bool calls_eval) = 0; |
| 58 | 58 |
| 59 // 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. |
| 60 // Further logging will be ignored, and ExtractData will return a vector | 60 // Further logging will be ignored, and ExtractData will return a vector |
| 61 // representing the error only. | 61 // representing the error only. |
| 62 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 62 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
| 63 const char* argument_opt, | 63 const char* argument_opt, |
| 64 ParseErrorType error_type) = 0; | 64 ParseErrorType error_type) = 0; |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); | 67 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 | 70 |
| 71 class SingletonLogger : public ParserRecorder { | 71 class SingletonLogger : public ParserRecorder { |
| 72 public: | 72 public: |
| 73 SingletonLogger() | 73 SingletonLogger() |
| 74 : has_error_(false), start_(-1), end_(-1), error_type_(kSyntaxError) {} | 74 : has_error_(false), start_(-1), end_(-1), error_type_(kSyntaxError) {} |
| 75 virtual ~SingletonLogger() {} | 75 virtual ~SingletonLogger() {} |
| 76 | 76 |
| 77 void Reset() { has_error_ = false; } | 77 void Reset() { has_error_ = false; } |
| 78 | 78 |
| 79 virtual void LogFunction(int start, int end, int literals, int properties, | 79 virtual void LogFunction(int start, int end, int literals, int properties, |
| 80 LanguageMode language_mode, bool uses_super_property, | 80 LanguageMode language_mode, AsmMode asm_mode, |
| 81 bool calls_eval) { | 81 bool uses_super_property, bool calls_eval) { |
| 82 DCHECK(!has_error_); | 82 DCHECK(!has_error_); |
| 83 start_ = start; | 83 start_ = start; |
| 84 end_ = end; | 84 end_ = end; |
| 85 literals_ = literals; | 85 literals_ = literals; |
| 86 properties_ = properties; | 86 properties_ = properties; |
| 87 language_mode_ = language_mode; | 87 language_mode_ = language_mode; |
| 88 asm_mode_ = asm_mode, |
| 88 uses_super_property_ = uses_super_property; | 89 uses_super_property_ = uses_super_property; |
| 89 calls_eval_ = calls_eval; | 90 calls_eval_ = calls_eval; |
| 90 } | 91 } |
| 91 | 92 |
| 92 // Logs an error message and marks the log as containing an error. | 93 // Logs an error message and marks the log as containing an error. |
| 93 // Further logging will be ignored, and ExtractData will return a vector | 94 // Further logging will be ignored, and ExtractData will return a vector |
| 94 // representing the error only. | 95 // representing the error only. |
| 95 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 96 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
| 96 const char* argument_opt, ParseErrorType error_type) { | 97 const char* argument_opt, ParseErrorType error_type) { |
| 97 if (has_error_) return; | 98 if (has_error_) return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 112 return literals_; | 113 return literals_; |
| 113 } | 114 } |
| 114 int properties() const { | 115 int properties() const { |
| 115 DCHECK(!has_error_); | 116 DCHECK(!has_error_); |
| 116 return properties_; | 117 return properties_; |
| 117 } | 118 } |
| 118 LanguageMode language_mode() const { | 119 LanguageMode language_mode() const { |
| 119 DCHECK(!has_error_); | 120 DCHECK(!has_error_); |
| 120 return language_mode_; | 121 return language_mode_; |
| 121 } | 122 } |
| 123 AsmMode asm_mode() const { |
| 124 DCHECK(!has_error_); |
| 125 return asm_mode_; |
| 126 } |
| 122 bool uses_super_property() const { | 127 bool uses_super_property() const { |
| 123 DCHECK(!has_error_); | 128 DCHECK(!has_error_); |
| 124 return uses_super_property_; | 129 return uses_super_property_; |
| 125 } | 130 } |
| 126 bool calls_eval() const { | 131 bool calls_eval() const { |
| 127 DCHECK(!has_error_); | 132 DCHECK(!has_error_); |
| 128 return calls_eval_; | 133 return calls_eval_; |
| 129 } | 134 } |
| 130 ParseErrorType error_type() const { | 135 ParseErrorType error_type() const { |
| 131 DCHECK(has_error_); | 136 DCHECK(has_error_); |
| 132 return error_type_; | 137 return error_type_; |
| 133 } | 138 } |
| 134 MessageTemplate::Template message() { | 139 MessageTemplate::Template message() { |
| 135 DCHECK(has_error_); | 140 DCHECK(has_error_); |
| 136 return message_; | 141 return message_; |
| 137 } | 142 } |
| 138 const char* argument_opt() const { | 143 const char* argument_opt() const { |
| 139 DCHECK(has_error_); | 144 DCHECK(has_error_); |
| 140 return argument_opt_; | 145 return argument_opt_; |
| 141 } | 146 } |
| 142 | 147 |
| 143 private: | 148 private: |
| 144 bool has_error_; | 149 bool has_error_; |
| 145 int start_; | 150 int start_; |
| 146 int end_; | 151 int end_; |
| 147 // For function entries. | 152 // For function entries. |
| 148 int literals_; | 153 int literals_; |
| 149 int properties_; | 154 int properties_; |
| 150 LanguageMode language_mode_; | 155 LanguageMode language_mode_; |
| 156 AsmMode asm_mode_; |
| 151 bool uses_super_property_; | 157 bool uses_super_property_; |
| 152 bool calls_eval_; | 158 bool calls_eval_; |
| 153 // For error messages. | 159 // For error messages. |
| 154 MessageTemplate::Template message_; | 160 MessageTemplate::Template message_; |
| 155 const char* argument_opt_; | 161 const char* argument_opt_; |
| 156 ParseErrorType error_type_; | 162 ParseErrorType error_type_; |
| 157 }; | 163 }; |
| 158 | 164 |
| 159 | 165 |
| 160 class CompleteParserRecorder : public ParserRecorder { | 166 class CompleteParserRecorder : public ParserRecorder { |
| 161 public: | 167 public: |
| 162 struct Key { | 168 struct Key { |
| 163 bool is_one_byte; | 169 bool is_one_byte; |
| 164 Vector<const byte> literal_bytes; | 170 Vector<const byte> literal_bytes; |
| 165 }; | 171 }; |
| 166 | 172 |
| 167 CompleteParserRecorder(); | 173 CompleteParserRecorder(); |
| 168 virtual ~CompleteParserRecorder() {} | 174 virtual ~CompleteParserRecorder() {} |
| 169 | 175 |
| 170 virtual void LogFunction(int start, int end, int literals, int properties, | 176 virtual void LogFunction(int start, int end, int literals, int properties, |
| 171 LanguageMode language_mode, bool uses_super_property, | 177 LanguageMode language_mode, AsmMode asm_mode, |
| 172 bool calls_eval) { | 178 bool uses_super_property, bool calls_eval) { |
| 173 function_store_.Add(start); | 179 function_store_.Add(start); |
| 174 function_store_.Add(end); | 180 function_store_.Add(end); |
| 175 function_store_.Add(literals); | 181 function_store_.Add(literals); |
| 176 function_store_.Add(properties); | 182 function_store_.Add(properties); |
| 177 function_store_.Add(language_mode); | 183 function_store_.Add(language_mode); |
| 184 function_store_.Add(asm_mode); |
| 178 function_store_.Add(uses_super_property); | 185 function_store_.Add(uses_super_property); |
| 179 function_store_.Add(calls_eval); | 186 function_store_.Add(calls_eval); |
| 180 } | 187 } |
| 181 | 188 |
| 182 // Logs an error message and marks the log as containing an error. | 189 // Logs an error message and marks the log as containing an error. |
| 183 // Further logging will be ignored, and ExtractData will return a vector | 190 // Further logging will be ignored, and ExtractData will return a vector |
| 184 // representing the error only. | 191 // representing the error only. |
| 185 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 192 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
| 186 const char* argument_opt, ParseErrorType error_type); | 193 const char* argument_opt, ParseErrorType error_type); |
| 187 ScriptData* GetScriptData(); | 194 ScriptData* GetScriptData(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 202 | 209 |
| 203 #ifdef DEBUG | 210 #ifdef DEBUG |
| 204 int prev_start_; | 211 int prev_start_; |
| 205 #endif | 212 #endif |
| 206 }; | 213 }; |
| 207 | 214 |
| 208 | 215 |
| 209 } } // namespace v8::internal. | 216 } } // namespace v8::internal. |
| 210 | 217 |
| 211 #endif // V8_PREPARSE_DATA_H_ | 218 #endif // V8_PREPARSE_DATA_H_ |
| OLD | NEW |