Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: src/scanner.h

Issue 25755002: Unify and fix checkers for duplicate object literal properties. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.cc ('k') | src/scanner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
37 #include "token.h" 39 #include "token.h"
38 #include "unicode-inl.h" 40 #include "unicode-inl.h"
39 #include "utils.h" 41 #include "utils.h"
40 42
41 namespace v8 { 43 namespace v8 {
42 namespace internal { 44 namespace internal {
43 45
44 46
45 // Returns the value (0 .. 15) of a hexadecimal character c. 47 // Returns the value (0 .. 15) of a hexadecimal character c.
46 // If c is not a legal hexadecimal character, returns a value < 0. 48 // If c is not a legal hexadecimal character, returns a value < 0.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // are more code_units available, return true. 116 // are more code_units available, return true.
115 virtual bool ReadBlock() = 0; 117 virtual bool ReadBlock() = 0;
116 virtual unsigned SlowSeekForward(unsigned code_unit_count) = 0; 118 virtual unsigned SlowSeekForward(unsigned code_unit_count) = 0;
117 119
118 const uc16* buffer_cursor_; 120 const uc16* buffer_cursor_;
119 const uc16* buffer_end_; 121 const uc16* buffer_end_;
120 unsigned pos_; 122 unsigned pos_;
121 }; 123 };
122 124
123 125
124 class UnicodeCache {
125 // --------------------------------------------------------------------- 126 // ---------------------------------------------------------------------
126 // Caching predicates used by scanners. 127 // Caching predicates used by scanners.
128
129 class UnicodeCache {
127 public: 130 public:
128 UnicodeCache() {} 131 UnicodeCache() {}
129 typedef unibrow::Utf8Decoder<512> Utf8Decoder; 132 typedef unibrow::Utf8Decoder<512> Utf8Decoder;
130 133
131 StaticResource<Utf8Decoder>* utf8_decoder() { 134 StaticResource<Utf8Decoder>* utf8_decoder() {
132 return &utf8_decoder_; 135 return &utf8_decoder_;
133 } 136 }
134 137
135 bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); } 138 bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); }
136 bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); } 139 bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); }
137 bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); } 140 bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); }
138 bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); } 141 bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); }
139 142
140 private: 143 private:
141 unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart; 144 unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart;
142 unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart; 145 unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart;
143 unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator; 146 unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator;
144 unibrow::Predicate<unibrow::WhiteSpace, 128> kIsWhiteSpace; 147 unibrow::Predicate<unibrow::WhiteSpace, 128> kIsWhiteSpace;
145 StaticResource<Utf8Decoder> utf8_decoder_; 148 StaticResource<Utf8Decoder> utf8_decoder_;
146 149
147 DISALLOW_COPY_AND_ASSIGN(UnicodeCache); 150 DISALLOW_COPY_AND_ASSIGN(UnicodeCache);
148 }; 151 };
149 152
150 153
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
151 // ---------------------------------------------------------------------------- 204 // ----------------------------------------------------------------------------
152 // LiteralBuffer - Collector of chars of literals. 205 // LiteralBuffer - Collector of chars of literals.
153 206
154 class LiteralBuffer { 207 class LiteralBuffer {
155 public: 208 public:
156 LiteralBuffer() : is_ascii_(true), position_(0), backing_store_() { } 209 LiteralBuffer() : is_ascii_(true), position_(0), backing_store_() { }
157 210
158 ~LiteralBuffer() { 211 ~LiteralBuffer() {
159 if (backing_store_.length() > 0) { 212 if (backing_store_.length() > 0) {
160 backing_store_.Dispose(); 213 backing_store_.Dispose();
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 bool harmony_scoping_; 615 bool harmony_scoping_;
563 // Whether we scan 'module', 'import', 'export' as keywords. 616 // Whether we scan 'module', 'import', 'export' as keywords.
564 bool harmony_modules_; 617 bool harmony_modules_;
565 // Whether we scan 0o777 and 0b111 as numbers. 618 // Whether we scan 0o777 and 0b111 as numbers.
566 bool harmony_numeric_literals_; 619 bool harmony_numeric_literals_;
567 }; 620 };
568 621
569 } } // namespace v8::internal 622 } } // namespace v8::internal
570 623
571 #endif // V8_SCANNER_H_ 624 #endif // V8_SCANNER_H_
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | src/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698