| 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/preparse-data-format.h" | 10 #include "src/preparse-data-format.h" |
| 11 #include "src/utils-inl.h" | 11 #include "src/utils-inl.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 class ScriptData; | 16 class ScriptData; |
| 17 | 17 |
| 18 | 18 |
| 19 // Abstract interface for preparse data recorder. | 19 // Abstract interface for preparse data recorder. |
| 20 class ParserRecorder { | 20 class ParserRecorder { |
| 21 public: | 21 public: |
| 22 ParserRecorder() { } | 22 ParserRecorder() { } |
| 23 virtual ~ParserRecorder() { } | 23 virtual ~ParserRecorder() { } |
| 24 | 24 |
| 25 // Logs the scope and some details of a function literal in the source. | 25 // Logs the scope and some details of a function literal in the source. |
| 26 virtual void LogFunction(int start, int end, int literals, int properties, | 26 virtual void LogFunction(int start, int end, int literals, int properties, |
| 27 LanguageMode language_mode) = 0; | 27 LanguageMode language_mode, |
| 28 bool uses_super_property) = 0; |
| 28 | 29 |
| 29 // Logs an error message and marks the log as containing an error. | 30 // Logs an error message and marks the log as containing an error. |
| 30 // Further logging will be ignored, and ExtractData will return a vector | 31 // Further logging will be ignored, and ExtractData will return a vector |
| 31 // representing the error only. | 32 // representing the error only. |
| 32 virtual void LogMessage(int start, | 33 virtual void LogMessage(int start, |
| 33 int end, | 34 int end, |
| 34 const char* message, | 35 const char* message, |
| 35 const char* argument_opt, | 36 const char* argument_opt, |
| 36 bool is_reference_error) = 0; | 37 bool is_reference_error) = 0; |
| 37 private: | 38 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); | 39 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 | 42 |
| 42 class SingletonLogger : public ParserRecorder { | 43 class SingletonLogger : public ParserRecorder { |
| 43 public: | 44 public: |
| 44 SingletonLogger() | 45 SingletonLogger() |
| 45 : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {} | 46 : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {} |
| 46 virtual ~SingletonLogger() {} | 47 virtual ~SingletonLogger() {} |
| 47 | 48 |
| 48 void Reset() { has_error_ = false; } | 49 void Reset() { has_error_ = false; } |
| 49 | 50 |
| 50 virtual void LogFunction(int start, int end, int literals, int properties, | 51 virtual void LogFunction(int start, int end, int literals, int properties, |
| 51 LanguageMode language_mode) { | 52 LanguageMode language_mode, |
| 53 bool scope_uses_super_property) { |
| 52 DCHECK(!has_error_); | 54 DCHECK(!has_error_); |
| 53 start_ = start; | 55 start_ = start; |
| 54 end_ = end; | 56 end_ = end; |
| 55 literals_ = literals; | 57 literals_ = literals; |
| 56 properties_ = properties; | 58 properties_ = properties; |
| 57 language_mode_ = language_mode; | 59 language_mode_ = language_mode; |
| 60 scope_uses_super_property_ = scope_uses_super_property; |
| 58 } | 61 } |
| 59 | 62 |
| 60 // Logs an error message and marks the log as containing an error. | 63 // Logs an error message and marks the log as containing an error. |
| 61 // Further logging will be ignored, and ExtractData will return a vector | 64 // Further logging will be ignored, and ExtractData will return a vector |
| 62 // representing the error only. | 65 // representing the error only. |
| 63 virtual void LogMessage(int start, | 66 virtual void LogMessage(int start, |
| 64 int end, | 67 int end, |
| 65 const char* message, | 68 const char* message, |
| 66 const char* argument_opt, | 69 const char* argument_opt, |
| 67 bool is_reference_error) { | 70 bool is_reference_error) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 return literals_; | 86 return literals_; |
| 84 } | 87 } |
| 85 int properties() const { | 88 int properties() const { |
| 86 DCHECK(!has_error_); | 89 DCHECK(!has_error_); |
| 87 return properties_; | 90 return properties_; |
| 88 } | 91 } |
| 89 LanguageMode language_mode() const { | 92 LanguageMode language_mode() const { |
| 90 DCHECK(!has_error_); | 93 DCHECK(!has_error_); |
| 91 return language_mode_; | 94 return language_mode_; |
| 92 } | 95 } |
| 96 bool scope_uses_super_property() const { |
| 97 DCHECK(!has_error_); |
| 98 return scope_uses_super_property_; |
| 99 } |
| 93 int is_reference_error() const { return is_reference_error_; } | 100 int is_reference_error() const { return is_reference_error_; } |
| 94 const char* message() { | 101 const char* message() { |
| 95 DCHECK(has_error_); | 102 DCHECK(has_error_); |
| 96 return message_; | 103 return message_; |
| 97 } | 104 } |
| 98 const char* argument_opt() const { | 105 const char* argument_opt() const { |
| 99 DCHECK(has_error_); | 106 DCHECK(has_error_); |
| 100 return argument_opt_; | 107 return argument_opt_; |
| 101 } | 108 } |
| 102 | 109 |
| 103 private: | 110 private: |
| 104 bool has_error_; | 111 bool has_error_; |
| 105 int start_; | 112 int start_; |
| 106 int end_; | 113 int end_; |
| 107 // For function entries. | 114 // For function entries. |
| 108 int literals_; | 115 int literals_; |
| 109 int properties_; | 116 int properties_; |
| 110 LanguageMode language_mode_; | 117 LanguageMode language_mode_; |
| 118 bool scope_uses_super_property_; |
| 111 // For error messages. | 119 // For error messages. |
| 112 const char* message_; | 120 const char* message_; |
| 113 const char* argument_opt_; | 121 const char* argument_opt_; |
| 114 bool is_reference_error_; | 122 bool is_reference_error_; |
| 115 }; | 123 }; |
| 116 | 124 |
| 117 | 125 |
| 118 class CompleteParserRecorder : public ParserRecorder { | 126 class CompleteParserRecorder : public ParserRecorder { |
| 119 public: | 127 public: |
| 120 struct Key { | 128 struct Key { |
| 121 bool is_one_byte; | 129 bool is_one_byte; |
| 122 Vector<const byte> literal_bytes; | 130 Vector<const byte> literal_bytes; |
| 123 }; | 131 }; |
| 124 | 132 |
| 125 CompleteParserRecorder(); | 133 CompleteParserRecorder(); |
| 126 virtual ~CompleteParserRecorder() {} | 134 virtual ~CompleteParserRecorder() {} |
| 127 | 135 |
| 128 virtual void LogFunction(int start, int end, int literals, int properties, | 136 virtual void LogFunction(int start, int end, int literals, int properties, |
| 129 LanguageMode language_mode) { | 137 LanguageMode language_mode, |
| 138 bool scope_uses_super_property) { |
| 130 function_store_.Add(start); | 139 function_store_.Add(start); |
| 131 function_store_.Add(end); | 140 function_store_.Add(end); |
| 132 function_store_.Add(literals); | 141 function_store_.Add(literals); |
| 133 function_store_.Add(properties); | 142 function_store_.Add(properties); |
| 134 function_store_.Add(language_mode); | 143 function_store_.Add(language_mode); |
| 144 function_store_.Add(scope_uses_super_property); |
| 135 } | 145 } |
| 136 | 146 |
| 137 // Logs an error message and marks the log as containing an error. | 147 // Logs an error message and marks the log as containing an error. |
| 138 // Further logging will be ignored, and ExtractData will return a vector | 148 // Further logging will be ignored, and ExtractData will return a vector |
| 139 // representing the error only. | 149 // representing the error only. |
| 140 virtual void LogMessage(int start, | 150 virtual void LogMessage(int start, |
| 141 int end, | 151 int end, |
| 142 const char* message, | 152 const char* message, |
| 143 const char* argument_opt, | 153 const char* argument_opt, |
| 144 bool is_reference_error_); | 154 bool is_reference_error_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 163 | 173 |
| 164 #ifdef DEBUG | 174 #ifdef DEBUG |
| 165 int prev_start_; | 175 int prev_start_; |
| 166 #endif | 176 #endif |
| 167 }; | 177 }; |
| 168 | 178 |
| 169 | 179 |
| 170 } } // namespace v8::internal. | 180 } } // namespace v8::internal. |
| 171 | 181 |
| 172 #endif // V8_PREPARSE_DATA_H_ | 182 #endif // V8_PREPARSE_DATA_H_ |
| OLD | NEW |