| OLD | NEW | 
|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 16 matching lines...) Expand all  Loading... | 
| 27 | 27 | 
| 28 // Features shared by parsing and pre-parsing scanners. | 28 // Features shared by parsing and pre-parsing scanners. | 
| 29 | 29 | 
| 30 #ifndef V8_SCANNER_H_ | 30 #ifndef V8_SCANNER_H_ | 
| 31 #define V8_SCANNER_H_ | 31 #define V8_SCANNER_H_ | 
| 32 | 32 | 
| 33 #include "allocation.h" | 33 #include "allocation.h" | 
| 34 #include "char-predicates.h" | 34 #include "char-predicates.h" | 
| 35 #include "checks.h" | 35 #include "checks.h" | 
| 36 #include "globals.h" | 36 #include "globals.h" | 
| 37 #include "hashmap.h" |  | 
| 38 #include "list.h" |  | 
| 39 #include "token.h" | 37 #include "token.h" | 
| 40 #include "unicode-inl.h" | 38 #include "unicode-inl.h" | 
| 41 #include "utils.h" | 39 #include "utils.h" | 
| 42 | 40 | 
| 43 namespace v8 { | 41 namespace v8 { | 
| 44 namespace internal { | 42 namespace internal { | 
| 45 | 43 | 
| 46 | 44 | 
| 47 // Returns the value (0 .. 15) of a hexadecimal character c. | 45 // Returns the value (0 .. 15) of a hexadecimal character c. | 
| 48 // If c is not a legal hexadecimal character, returns a value < 0. | 46 // If c is not a legal hexadecimal character, returns a value < 0. | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 116   // are more code_units available, return true. | 114   // are more code_units available, return true. | 
| 117   virtual bool ReadBlock() = 0; | 115   virtual bool ReadBlock() = 0; | 
| 118   virtual unsigned SlowSeekForward(unsigned code_unit_count) = 0; | 116   virtual unsigned SlowSeekForward(unsigned code_unit_count) = 0; | 
| 119 | 117 | 
| 120   const uc16* buffer_cursor_; | 118   const uc16* buffer_cursor_; | 
| 121   const uc16* buffer_end_; | 119   const uc16* buffer_end_; | 
| 122   unsigned pos_; | 120   unsigned pos_; | 
| 123 }; | 121 }; | 
| 124 | 122 | 
| 125 | 123 | 
|  | 124 class UnicodeCache { | 
| 126 // --------------------------------------------------------------------- | 125 // --------------------------------------------------------------------- | 
| 127 // Caching predicates used by scanners. | 126 // Caching predicates used by scanners. | 
| 128 |  | 
| 129 class UnicodeCache { |  | 
| 130  public: | 127  public: | 
| 131   UnicodeCache() {} | 128   UnicodeCache() {} | 
| 132   typedef unibrow::Utf8Decoder<512> Utf8Decoder; | 129   typedef unibrow::Utf8Decoder<512> Utf8Decoder; | 
| 133 | 130 | 
| 134   StaticResource<Utf8Decoder>* utf8_decoder() { | 131   StaticResource<Utf8Decoder>* utf8_decoder() { | 
| 135     return &utf8_decoder_; | 132     return &utf8_decoder_; | 
| 136   } | 133   } | 
| 137 | 134 | 
| 138   bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); } | 135   bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); } | 
| 139   bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); } | 136   bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); } | 
| 140   bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); } | 137   bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); } | 
| 141   bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); } | 138   bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); } | 
| 142 | 139 | 
| 143  private: | 140  private: | 
| 144   unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart; | 141   unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart; | 
| 145   unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart; | 142   unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart; | 
| 146   unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator; | 143   unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator; | 
| 147   unibrow::Predicate<unibrow::WhiteSpace, 128> kIsWhiteSpace; | 144   unibrow::Predicate<unibrow::WhiteSpace, 128> kIsWhiteSpace; | 
| 148   StaticResource<Utf8Decoder> utf8_decoder_; | 145   StaticResource<Utf8Decoder> utf8_decoder_; | 
| 149 | 146 | 
| 150   DISALLOW_COPY_AND_ASSIGN(UnicodeCache); | 147   DISALLOW_COPY_AND_ASSIGN(UnicodeCache); | 
| 151 }; | 148 }; | 
| 152 | 149 | 
| 153 | 150 | 
| 154 // --------------------------------------------------------------------- |  | 
| 155 // DuplicateFinder discovers duplicate symbols. |  | 
| 156 |  | 
| 157 class DuplicateFinder { |  | 
| 158  public: |  | 
| 159   explicit DuplicateFinder(UnicodeCache* constants) |  | 
| 160       : unicode_constants_(constants), |  | 
| 161         backing_store_(16), |  | 
| 162         map_(&Match) { } |  | 
| 163 |  | 
| 164   int AddAsciiSymbol(Vector<const char> key, int value); |  | 
| 165   int AddUtf16Symbol(Vector<const uint16_t> key, int value); |  | 
| 166   // Add a a number literal by converting it (if necessary) |  | 
| 167   // to the string that ToString(ToNumber(literal)) would generate. |  | 
| 168   // and then adding that string with AddAsciiSymbol. |  | 
| 169   // This string is the actual value used as key in an object literal, |  | 
| 170   // and the one that must be different from the other keys. |  | 
| 171   int AddNumber(Vector<const char> key, int value); |  | 
| 172 |  | 
| 173  private: |  | 
| 174   int AddSymbol(Vector<const byte> key, bool is_ascii, int value); |  | 
| 175   // Backs up the key and its length in the backing store. |  | 
| 176   // The backup is stored with a base 127 encoding of the |  | 
| 177   // length (plus a bit saying whether the string is ASCII), |  | 
| 178   // followed by the bytes of the key. |  | 
| 179   byte* BackupKey(Vector<const byte> key, bool is_ascii); |  | 
| 180 |  | 
| 181   // Compare two encoded keys (both pointing into the backing store) |  | 
| 182   // for having the same base-127 encoded lengths and ASCII-ness, |  | 
| 183   // and then having the same 'length' bytes following. |  | 
| 184   static bool Match(void* first, void* second); |  | 
| 185   // Creates a hash from a sequence of bytes. |  | 
| 186   static uint32_t Hash(Vector<const byte> key, bool is_ascii); |  | 
| 187   // Checks whether a string containing a JS number is its canonical |  | 
| 188   // form. |  | 
| 189   static bool IsNumberCanonical(Vector<const char> key); |  | 
| 190 |  | 
| 191   // Size of buffer. Sufficient for using it to call DoubleToCString in |  | 
| 192   // from conversions.h. |  | 
| 193   static const int kBufferSize = 100; |  | 
| 194 |  | 
| 195   UnicodeCache* unicode_constants_; |  | 
| 196   // Backing store used to store strings used as hashmap keys. |  | 
| 197   SequenceCollector<unsigned char> backing_store_; |  | 
| 198   HashMap map_; |  | 
| 199   // Buffer used for string->number->canonical string conversions. |  | 
| 200   char number_buffer_[kBufferSize]; |  | 
| 201 }; |  | 
| 202 |  | 
| 203 |  | 
| 204 // ---------------------------------------------------------------------------- | 151 // ---------------------------------------------------------------------------- | 
| 205 // LiteralBuffer -  Collector of chars of literals. | 152 // LiteralBuffer -  Collector of chars of literals. | 
| 206 | 153 | 
| 207 class LiteralBuffer { | 154 class LiteralBuffer { | 
| 208  public: | 155  public: | 
| 209   LiteralBuffer() : is_ascii_(true), position_(0), backing_store_() { } | 156   LiteralBuffer() : is_ascii_(true), position_(0), backing_store_() { } | 
| 210 | 157 | 
| 211   ~LiteralBuffer() { | 158   ~LiteralBuffer() { | 
| 212     if (backing_store_.length() > 0) { | 159     if (backing_store_.length() > 0) { | 
| 213       backing_store_.Dispose(); | 160       backing_store_.Dispose(); | 
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 615   bool harmony_scoping_; | 562   bool harmony_scoping_; | 
| 616   // Whether we scan 'module', 'import', 'export' as keywords. | 563   // Whether we scan 'module', 'import', 'export' as keywords. | 
| 617   bool harmony_modules_; | 564   bool harmony_modules_; | 
| 618   // Whether we scan 0o777 and 0b111 as numbers. | 565   // Whether we scan 0o777 and 0b111 as numbers. | 
| 619   bool harmony_numeric_literals_; | 566   bool harmony_numeric_literals_; | 
| 620 }; | 567 }; | 
| 621 | 568 | 
| 622 } }  // namespace v8::internal | 569 } }  // namespace v8::internal | 
| 623 | 570 | 
| 624 #endif  // V8_SCANNER_H_ | 571 #endif  // V8_SCANNER_H_ | 
| OLD | NEW | 
|---|