| 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, | 56 LanguageMode language_mode, bool uses_super_property, |
| 57 bool uses_super_property) = 0; | 57 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, | 80 LanguageMode language_mode, bool uses_super_property, |
| 81 bool scope_uses_super_property) { | 81 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 scope_uses_super_property_ = scope_uses_super_property; | 88 uses_super_property_ = uses_super_property; |
| 89 calls_eval_ = calls_eval; |
| 89 } | 90 } |
| 90 | 91 |
| 91 // Logs an error message and marks the log as containing an error. | 92 // Logs an error message and marks the log as containing an error. |
| 92 // Further logging will be ignored, and ExtractData will return a vector | 93 // Further logging will be ignored, and ExtractData will return a vector |
| 93 // representing the error only. | 94 // representing the error only. |
| 94 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 95 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
| 95 const char* argument_opt, ParseErrorType error_type) { | 96 const char* argument_opt, ParseErrorType error_type) { |
| 96 if (has_error_) return; | 97 if (has_error_) return; |
| 97 has_error_ = true; | 98 has_error_ = true; |
| 98 start_ = start; | 99 start_ = start; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 111 return literals_; | 112 return literals_; |
| 112 } | 113 } |
| 113 int properties() const { | 114 int properties() const { |
| 114 DCHECK(!has_error_); | 115 DCHECK(!has_error_); |
| 115 return properties_; | 116 return properties_; |
| 116 } | 117 } |
| 117 LanguageMode language_mode() const { | 118 LanguageMode language_mode() const { |
| 118 DCHECK(!has_error_); | 119 DCHECK(!has_error_); |
| 119 return language_mode_; | 120 return language_mode_; |
| 120 } | 121 } |
| 121 bool scope_uses_super_property() const { | 122 bool uses_super_property() const { |
| 122 DCHECK(!has_error_); | 123 DCHECK(!has_error_); |
| 123 return scope_uses_super_property_; | 124 return uses_super_property_; |
| 125 } |
| 126 bool calls_eval() const { |
| 127 DCHECK(!has_error_); |
| 128 return calls_eval_; |
| 124 } | 129 } |
| 125 ParseErrorType error_type() const { | 130 ParseErrorType error_type() const { |
| 126 DCHECK(has_error_); | 131 DCHECK(has_error_); |
| 127 return error_type_; | 132 return error_type_; |
| 128 } | 133 } |
| 129 MessageTemplate::Template message() { | 134 MessageTemplate::Template message() { |
| 130 DCHECK(has_error_); | 135 DCHECK(has_error_); |
| 131 return message_; | 136 return message_; |
| 132 } | 137 } |
| 133 const char* argument_opt() const { | 138 const char* argument_opt() const { |
| 134 DCHECK(has_error_); | 139 DCHECK(has_error_); |
| 135 return argument_opt_; | 140 return argument_opt_; |
| 136 } | 141 } |
| 137 | 142 |
| 138 private: | 143 private: |
| 139 bool has_error_; | 144 bool has_error_; |
| 140 int start_; | 145 int start_; |
| 141 int end_; | 146 int end_; |
| 142 // For function entries. | 147 // For function entries. |
| 143 int literals_; | 148 int literals_; |
| 144 int properties_; | 149 int properties_; |
| 145 LanguageMode language_mode_; | 150 LanguageMode language_mode_; |
| 146 bool scope_uses_super_property_; | 151 bool uses_super_property_; |
| 152 bool calls_eval_; |
| 147 // For error messages. | 153 // For error messages. |
| 148 MessageTemplate::Template message_; | 154 MessageTemplate::Template message_; |
| 149 const char* argument_opt_; | 155 const char* argument_opt_; |
| 150 ParseErrorType error_type_; | 156 ParseErrorType error_type_; |
| 151 }; | 157 }; |
| 152 | 158 |
| 153 | 159 |
| 154 class CompleteParserRecorder : public ParserRecorder { | 160 class CompleteParserRecorder : public ParserRecorder { |
| 155 public: | 161 public: |
| 156 struct Key { | 162 struct Key { |
| 157 bool is_one_byte; | 163 bool is_one_byte; |
| 158 Vector<const byte> literal_bytes; | 164 Vector<const byte> literal_bytes; |
| 159 }; | 165 }; |
| 160 | 166 |
| 161 CompleteParserRecorder(); | 167 CompleteParserRecorder(); |
| 162 virtual ~CompleteParserRecorder() {} | 168 virtual ~CompleteParserRecorder() {} |
| 163 | 169 |
| 164 virtual void LogFunction(int start, int end, int literals, int properties, | 170 virtual void LogFunction(int start, int end, int literals, int properties, |
| 165 LanguageMode language_mode, | 171 LanguageMode language_mode, bool uses_super_property, |
| 166 bool scope_uses_super_property) { | 172 bool calls_eval) { |
| 167 function_store_.Add(start); | 173 function_store_.Add(start); |
| 168 function_store_.Add(end); | 174 function_store_.Add(end); |
| 169 function_store_.Add(literals); | 175 function_store_.Add(literals); |
| 170 function_store_.Add(properties); | 176 function_store_.Add(properties); |
| 171 function_store_.Add(language_mode); | 177 function_store_.Add(language_mode); |
| 172 function_store_.Add(scope_uses_super_property); | 178 function_store_.Add(uses_super_property); |
| 179 function_store_.Add(calls_eval); |
| 173 } | 180 } |
| 174 | 181 |
| 175 // Logs an error message and marks the log as containing an error. | 182 // Logs an error message and marks the log as containing an error. |
| 176 // Further logging will be ignored, and ExtractData will return a vector | 183 // Further logging will be ignored, and ExtractData will return a vector |
| 177 // representing the error only. | 184 // representing the error only. |
| 178 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 185 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
| 179 const char* argument_opt, ParseErrorType error_type); | 186 const char* argument_opt, ParseErrorType error_type); |
| 180 ScriptData* GetScriptData(); | 187 ScriptData* GetScriptData(); |
| 181 | 188 |
| 182 bool HasError() { | 189 bool HasError() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 195 | 202 |
| 196 #ifdef DEBUG | 203 #ifdef DEBUG |
| 197 int prev_start_; | 204 int prev_start_; |
| 198 #endif | 205 #endif |
| 199 }; | 206 }; |
| 200 | 207 |
| 201 | 208 |
| 202 } } // namespace v8::internal. | 209 } } // namespace v8::internal. |
| 203 | 210 |
| 204 #endif // V8_PREPARSE_DATA_H_ | 211 #endif // V8_PREPARSE_DATA_H_ |
| OLD | NEW |