| 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_PARSING_PREPARSE_DATA_H_ | 5 #ifndef V8_PARSING_PREPARSE_DATA_H_ |
| 6 #define V8_PARSING_PREPARSE_DATA_H_ | 6 #define V8_PARSING_PREPARSE_DATA_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
| 10 #include "src/collector.h" | 10 #include "src/collector.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 bool rejected_ : 1; | 42 bool rejected_ : 1; |
| 43 const byte* data_; | 43 const byte* data_; |
| 44 int length_; | 44 int length_; |
| 45 | 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(ScriptData); | 46 DISALLOW_COPY_AND_ASSIGN(ScriptData); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class PreParserLogger final { | 49 class PreParserLogger final { |
| 50 public: | 50 public: |
| 51 PreParserLogger() | 51 PreParserLogger() |
| 52 : has_error_(false), | 52 : end_(-1), |
| 53 start_(-1), | |
| 54 end_(-1), | |
| 55 num_parameters_(-1), | 53 num_parameters_(-1), |
| 56 function_length_(-1), | 54 function_length_(-1), |
| 57 has_duplicate_parameters_(false), | 55 has_duplicate_parameters_(false) {} |
| 58 error_type_(kSyntaxError) {} | |
| 59 | 56 |
| 60 void LogFunction(int end, int num_parameters, int function_length, | 57 void LogFunction(int end, int num_parameters, int function_length, |
| 61 bool has_duplicate_parameters, int literals, | 58 bool has_duplicate_parameters, int literals, |
| 62 int properties) { | 59 int properties) { |
| 63 DCHECK(!has_error_); | |
| 64 end_ = end; | 60 end_ = end; |
| 65 num_parameters_ = num_parameters; | 61 num_parameters_ = num_parameters; |
| 66 function_length_ = function_length; | 62 function_length_ = function_length; |
| 67 has_duplicate_parameters_ = has_duplicate_parameters; | 63 has_duplicate_parameters_ = has_duplicate_parameters; |
| 68 literals_ = literals; | 64 literals_ = literals; |
| 69 properties_ = properties; | 65 properties_ = properties; |
| 70 } | 66 } |
| 71 | 67 |
| 72 // Logs an error message and marks the log as containing an error. | |
| 73 // Further logging will be ignored, and ExtractData will return a vector | |
| 74 // representing the error only. | |
| 75 void LogMessage(int start, int end, MessageTemplate::Template message, | |
| 76 const char* argument_opt, ParseErrorType error_type) { | |
| 77 if (has_error_) return; | |
| 78 has_error_ = true; | |
| 79 start_ = start; | |
| 80 end_ = end; | |
| 81 message_ = message; | |
| 82 argument_opt_ = argument_opt; | |
| 83 error_type_ = error_type; | |
| 84 } | |
| 85 | |
| 86 bool has_error() const { return has_error_; } | |
| 87 | |
| 88 int start() const { return start_; } | |
| 89 int end() const { return end_; } | 68 int end() const { return end_; } |
| 90 int num_parameters() const { | 69 int num_parameters() const { |
| 91 DCHECK(!has_error_); | |
| 92 return num_parameters_; | 70 return num_parameters_; |
| 93 } | 71 } |
| 94 int function_length() const { | 72 int function_length() const { |
| 95 DCHECK(!has_error_); | |
| 96 return function_length_; | 73 return function_length_; |
| 97 } | 74 } |
| 98 bool has_duplicate_parameters() const { | 75 bool has_duplicate_parameters() const { |
| 99 DCHECK(!has_error_); | |
| 100 return has_duplicate_parameters_; | 76 return has_duplicate_parameters_; |
| 101 } | 77 } |
| 102 int literals() const { | 78 int literals() const { |
| 103 DCHECK(!has_error_); | |
| 104 return literals_; | 79 return literals_; |
| 105 } | 80 } |
| 106 int properties() const { | 81 int properties() const { |
| 107 DCHECK(!has_error_); | |
| 108 return properties_; | 82 return properties_; |
| 109 } | 83 } |
| 110 ParseErrorType error_type() const { | |
| 111 DCHECK(has_error_); | |
| 112 return error_type_; | |
| 113 } | |
| 114 MessageTemplate::Template message() { | |
| 115 DCHECK(has_error_); | |
| 116 return message_; | |
| 117 } | |
| 118 const char* argument_opt() const { | |
| 119 DCHECK(has_error_); | |
| 120 return argument_opt_; | |
| 121 } | |
| 122 | 84 |
| 123 private: | 85 private: |
| 124 bool has_error_; | |
| 125 int start_; | |
| 126 int end_; | 86 int end_; |
| 127 // For function entries. | 87 // For function entries. |
| 128 int num_parameters_; | 88 int num_parameters_; |
| 129 int function_length_; | 89 int function_length_; |
| 130 bool has_duplicate_parameters_; | 90 bool has_duplicate_parameters_; |
| 131 int literals_; | 91 int literals_; |
| 132 int properties_; | 92 int properties_; |
| 133 // For error messages. | |
| 134 MessageTemplate::Template message_; | |
| 135 const char* argument_opt_; | |
| 136 ParseErrorType error_type_; | |
| 137 }; | 93 }; |
| 138 | 94 |
| 139 class ParserLogger final { | 95 class ParserLogger final { |
| 140 public: | 96 public: |
| 141 struct Key { | |
| 142 bool is_one_byte; | |
| 143 Vector<const byte> literal_bytes; | |
| 144 }; | |
| 145 | |
| 146 ParserLogger(); | 97 ParserLogger(); |
| 147 | 98 |
| 148 void LogFunction(int start, int end, int num_parameters, int function_length, | 99 void LogFunction(int start, int end, int num_parameters, int function_length, |
| 149 bool has_duplicate_parameters, int literals, int properties, | 100 bool has_duplicate_parameters, int literals, int properties, |
| 150 LanguageMode language_mode, bool uses_super_property, | 101 LanguageMode language_mode, bool uses_super_property, |
| 151 bool calls_eval); | 102 bool calls_eval); |
| 152 | 103 |
| 153 // Logs an error message and marks the log as containing an error. | |
| 154 // Further logging will be ignored, and ExtractData will return a vector | |
| 155 // representing the error only. | |
| 156 void LogMessage(int start, int end, MessageTemplate::Template message, | |
| 157 const char* argument_opt, ParseErrorType error_type); | |
| 158 ScriptData* GetScriptData(); | 104 ScriptData* GetScriptData(); |
| 159 | 105 |
| 160 bool HasError() { | |
| 161 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); | |
| 162 } | |
| 163 Vector<unsigned> ErrorMessageData() { | |
| 164 DCHECK(HasError()); | |
| 165 return function_store_.ToVector(); | |
| 166 } | |
| 167 | |
| 168 private: | 106 private: |
| 169 void WriteString(Vector<const char> str); | |
| 170 | |
| 171 Collector<unsigned> function_store_; | 107 Collector<unsigned> function_store_; |
| 172 unsigned preamble_[PreparseDataConstants::kHeaderSize]; | 108 unsigned preamble_[PreparseDataConstants::kHeaderSize]; |
| 173 | 109 |
| 174 #ifdef DEBUG | 110 #ifdef DEBUG |
| 175 int prev_start_; | 111 int prev_start_; |
| 176 #endif | 112 #endif |
| 177 }; | 113 }; |
| 178 | 114 |
| 179 | 115 |
| 180 } // namespace internal | 116 } // namespace internal |
| 181 } // namespace v8. | 117 } // namespace v8. |
| 182 | 118 |
| 183 #endif // V8_PARSING_PREPARSE_DATA_H_ | 119 #endif // V8_PARSING_PREPARSE_DATA_H_ |
| OLD | NEW |