| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 ParserRecorder() { } | 68 ParserRecorder() { } |
| 69 virtual ~ParserRecorder() { } | 69 virtual ~ParserRecorder() { } |
| 70 | 70 |
| 71 // Logs the scope and some details of a function literal in the source. | 71 // Logs the scope and some details of a function literal in the source. |
| 72 virtual void LogFunction(int start, | 72 virtual void LogFunction(int start, |
| 73 int end, | 73 int end, |
| 74 int literals, | 74 int literals, |
| 75 int properties) = 0; | 75 int properties) = 0; |
| 76 | 76 |
| 77 // Logs a symbol creation of a literal or identifier. | 77 // Logs a symbol creation of a literal or identifier. |
| 78 virtual void LogSymbol(int start, const char* symbol, int length) = 0; | 78 virtual void LogAsciiSymbol(int start, Vector<const char> literal) { } |
| 79 virtual void LogUC16Symbol(int start, Vector<const uc16> literal) { } |
| 79 | 80 |
| 80 // Logs an error message and marks the log as containing an error. | 81 // Logs an error message and marks the log as containing an error. |
| 81 // Further logging will be ignored, and ExtractData will return a vector | 82 // Further logging will be ignored, and ExtractData will return a vector |
| 82 // representing the error only. | 83 // representing the error only. |
| 83 virtual void LogMessage(int start, | 84 virtual void LogMessage(int start, |
| 84 int end, | 85 int end, |
| 85 const char* message, | 86 const char* message, |
| 86 const char* argument_opt) = 0; | 87 const char* argument_opt) = 0; |
| 87 | 88 |
| 88 virtual int function_position() = 0; | 89 virtual int function_position() = 0; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 #endif | 159 #endif |
| 159 }; | 160 }; |
| 160 | 161 |
| 161 | 162 |
| 162 // ---------------------------------------------------------------------------- | 163 // ---------------------------------------------------------------------------- |
| 163 // PartialParserRecorder - Record only function entries | 164 // PartialParserRecorder - Record only function entries |
| 164 | 165 |
| 165 class PartialParserRecorder : public FunctionLoggingParserRecorder { | 166 class PartialParserRecorder : public FunctionLoggingParserRecorder { |
| 166 public: | 167 public: |
| 167 PartialParserRecorder() : FunctionLoggingParserRecorder() { } | 168 PartialParserRecorder() : FunctionLoggingParserRecorder() { } |
| 168 virtual void LogSymbol(int start, const char* symbol, int length) { } | 169 virtual void LogAsciiSymbol(int start, Vector<const char> literal) { } |
| 170 virtual void LogUC16Symbol(int start, Vector<const uc16> literal) { } |
| 169 virtual ~PartialParserRecorder() { } | 171 virtual ~PartialParserRecorder() { } |
| 170 virtual Vector<unsigned> ExtractData(); | 172 virtual Vector<unsigned> ExtractData(); |
| 171 virtual int symbol_position() { return 0; } | 173 virtual int symbol_position() { return 0; } |
| 172 virtual int symbol_ids() { return 0; } | 174 virtual int symbol_ids() { return 0; } |
| 173 }; | 175 }; |
| 174 | 176 |
| 175 | 177 |
| 176 // ---------------------------------------------------------------------------- | 178 // ---------------------------------------------------------------------------- |
| 177 // CompleteParserRecorder - Record both function entries and symbols. | 179 // CompleteParserRecorder - Record both function entries and symbols. |
| 178 | 180 |
| 179 class CompleteParserRecorder: public FunctionLoggingParserRecorder { | 181 class CompleteParserRecorder: public FunctionLoggingParserRecorder { |
| 180 public: | 182 public: |
| 181 CompleteParserRecorder(); | 183 CompleteParserRecorder(); |
| 182 virtual ~CompleteParserRecorder() { } | 184 virtual ~CompleteParserRecorder() { } |
| 183 | 185 |
| 184 virtual void LogSymbol(int start, const char* symbol, int length); | 186 virtual void LogAsciiSymbol(int start, Vector<const char> literal) { |
| 187 if (!is_recording_) return; |
| 188 int hash = vector_hash(literal); |
| 189 LogSymbol(start, hash, true, Vector<const byte>::cast(literal)); |
| 190 } |
| 191 |
| 192 virtual void LogUC16Symbol(int start, Vector<const uc16> literal) { |
| 193 if (!is_recording_) return; |
| 194 int hash = vector_hash(literal); |
| 195 LogSymbol(start, hash, false, Vector<const byte>::cast(literal)); |
| 196 } |
| 185 | 197 |
| 186 virtual Vector<unsigned> ExtractData(); | 198 virtual Vector<unsigned> ExtractData(); |
| 187 | 199 |
| 188 virtual int symbol_position() { return symbol_store_.size(); } | 200 virtual int symbol_position() { return symbol_store_.size(); } |
| 189 virtual int symbol_ids() { return symbol_id_; } | 201 virtual int symbol_ids() { return symbol_id_; } |
| 190 | 202 |
| 191 private: | 203 private: |
| 192 static int vector_hash(Vector<const char> string) { | 204 struct Key { |
| 205 bool is_ascii; |
| 206 Vector<const byte> literal_bytes; |
| 207 }; |
| 208 |
| 209 virtual void LogSymbol(int start, |
| 210 int hash, |
| 211 bool is_ascii, |
| 212 Vector<const byte> literal); |
| 213 |
| 214 template <typename Char> |
| 215 static int vector_hash(Vector<const Char> string) { |
| 193 int hash = 0; | 216 int hash = 0; |
| 194 for (int i = 0; i < string.length(); i++) { | 217 for (int i = 0; i < string.length(); i++) { |
| 195 int c = string[i]; | 218 int c = static_cast<int>(string[i]); |
| 196 hash += c; | 219 hash += c; |
| 197 hash += (hash << 10); | 220 hash += (hash << 10); |
| 198 hash ^= (hash >> 6); | 221 hash ^= (hash >> 6); |
| 199 } | 222 } |
| 200 return hash; | 223 return hash; |
| 201 } | 224 } |
| 202 | 225 |
| 203 static bool vector_compare(void* a, void* b) { | 226 static bool vector_compare(void* a, void* b) { |
| 204 Vector<const char>* string1 = reinterpret_cast<Vector<const char>* >(a); | 227 Key* string1 = reinterpret_cast<Key*>(a); |
| 205 Vector<const char>* string2 = reinterpret_cast<Vector<const char>* >(b); | 228 Key* string2 = reinterpret_cast<Key*>(b); |
| 206 int length = string1->length(); | 229 if (string1->is_ascii != string2->is_ascii) return false; |
| 207 if (string2->length() != length) return false; | 230 int length = string1->literal_bytes.length(); |
| 208 return memcmp(string1->start(), string2->start(), length) == 0; | 231 if (string2->literal_bytes.length() != length) return false; |
| 232 return memcmp(string1->literal_bytes.start(), |
| 233 string2->literal_bytes.start(), length) == 0; |
| 209 } | 234 } |
| 210 | 235 |
| 211 // Write a non-negative number to the symbol store. | 236 // Write a non-negative number to the symbol store. |
| 212 void WriteNumber(int number); | 237 void WriteNumber(int number); |
| 213 | 238 |
| 239 Collector<byte> literal_chars_; |
| 214 Collector<byte> symbol_store_; | 240 Collector<byte> symbol_store_; |
| 215 Collector<Vector<const char> > symbol_entries_; | 241 Collector<Key> symbol_keys_; |
| 216 HashMap symbol_table_; | 242 HashMap symbol_table_; |
| 217 int symbol_id_; | 243 int symbol_id_; |
| 218 }; | 244 }; |
| 219 | 245 |
| 220 | 246 |
| 221 } } // namespace v8::internal. | 247 } } // namespace v8::internal. |
| 222 | 248 |
| 223 #endif // V8_PREPARSER_DATA_H_ | 249 #endif // V8_PREPARSER_DATA_H_ |
| OLD | NEW |