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

Side by Side Diff: src/ast-value-factory.h

Issue 1201783003: Allow numeric literals to be checked for a decimal point. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge Created 5 years, 5 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
« no previous file with comments | « src/ast.h ('k') | src/ast-value-factory.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 // AstValue is either a string, a number, a string array, a boolean, or a 136 // AstValue is either a string, a number, a string array, a boolean, or a
137 // special value (null, undefined, the hole). 137 // special value (null, undefined, the hole).
138 class AstValue : public ZoneObject { 138 class AstValue : public ZoneObject {
139 public: 139 public:
140 bool IsString() const { 140 bool IsString() const {
141 return type_ == STRING; 141 return type_ == STRING;
142 } 142 }
143 143
144 bool IsNumber() const { 144 bool IsNumber() const {
145 return type_ == NUMBER || type_ == SMI; 145 return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI;
146 } 146 }
147 147
148 bool ContainsDot() const { return type_ == NUMBER_WITH_DOT; }
rossberg 2015/06/30 12:07:01 Nit: IsFloating perhaps?
titzer 2015/06/30 12:22:41 I'd actually prefer to keep it the way it is, beca
rossberg 2015/06/30 12:29:32 OK, fair enough.
bradn 2015/06/30 20:03:46 Left as is as per discussion.
149
148 const AstRawString* AsString() const { 150 const AstRawString* AsString() const {
149 if (type_ == STRING) 151 if (type_ == STRING)
150 return string_; 152 return string_;
151 UNREACHABLE(); 153 UNREACHABLE();
152 return 0; 154 return 0;
153 } 155 }
154 156
155 double AsNumber() const { 157 double AsNumber() const {
156 if (type_ == NUMBER) 158 if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) return number_;
157 return number_;
158 if (type_ == SMI) 159 if (type_ == SMI)
159 return smi_; 160 return smi_;
rossberg 2015/06/30 12:07:01 Nit: keep layout consistent
bradn 2015/06/30 20:03:47 Done. (Was a product of the git cl format autofor
160 UNREACHABLE(); 161 UNREACHABLE();
161 return 0; 162 return 0;
162 } 163 }
163 164
164 bool EqualsString(const AstRawString* string) const { 165 bool EqualsString(const AstRawString* string) const {
165 return type_ == STRING && string_ == string; 166 return type_ == STRING && string_ == string;
166 } 167 }
167 168
168 bool IsPropertyName() const; 169 bool IsPropertyName() const;
169 170
(...skipping 12 matching lines...) Expand all
182 return value_; 183 return value_;
183 } 184 }
184 185
185 private: 186 private:
186 friend class AstValueFactory; 187 friend class AstValueFactory;
187 188
188 enum Type { 189 enum Type {
189 STRING, 190 STRING,
190 SYMBOL, 191 SYMBOL,
191 NUMBER, 192 NUMBER,
193 NUMBER_WITH_DOT,
rossberg 2015/06/30 12:07:01 Nit: can we call this FLOATING?
bradn 2015/06/30 20:03:46 Sticking with WITH_DOT as per discussion.
192 SMI, 194 SMI,
193 BOOLEAN, 195 BOOLEAN,
194 NULL_TYPE, 196 NULL_TYPE,
195 UNDEFINED, 197 UNDEFINED,
196 THE_HOLE 198 THE_HOLE
197 }; 199 };
198 200
199 explicit AstValue(const AstRawString* s) : type_(STRING) { string_ = s; } 201 explicit AstValue(const AstRawString* s) : type_(STRING) { string_ = s; }
200 202
201 explicit AstValue(const char* name) : type_(SYMBOL) { symbol_name_ = name; } 203 explicit AstValue(const char* name) : type_(SYMBOL) { symbol_name_ = name; }
202 204
203 explicit AstValue(double n) : type_(NUMBER) { number_ = n; } 205 explicit AstValue(double n) : type_(NUMBER) { number_ = n; }
204 206
205 AstValue(Type t, int i) : type_(t) { 207 AstValue(Type t, int i) : type_(t) {
206 DCHECK(type_ == SMI); 208 DCHECK(type_ == SMI);
207 smi_ = i; 209 smi_ = i;
208 } 210 }
209 211
210 explicit AstValue(bool b) : type_(BOOLEAN) { bool_ = b; } 212 explicit AstValue(bool b) : type_(BOOLEAN) { bool_ = b; }
211 213
212 explicit AstValue(Type t) : type_(t) { 214 explicit AstValue(Type t) : type_(t) {
213 DCHECK(t == NULL_TYPE || t == UNDEFINED || t == THE_HOLE); 215 DCHECK(t == NULL_TYPE || t == UNDEFINED || t == THE_HOLE);
214 } 216 }
215 217
218 void MarkWithDot() {
rossberg 2015/06/30 12:07:01 Get rid of this method and add an is_float flag pa
bradn 2015/06/30 20:03:46 Done, but with with_dot as per discussion.
219 DCHECK(type_ == NUMBER);
220 type_ = NUMBER_WITH_DOT;
221 }
222
216 Type type_; 223 Type type_;
217 224
218 // Uninternalized value. 225 // Uninternalized value.
219 union { 226 union {
220 const AstRawString* string_; 227 const AstRawString* string_;
221 double number_; 228 double number_;
222 int smi_; 229 int smi_;
223 bool bool_; 230 bool bool_;
224 ZoneList<const AstRawString*>* strings_; 231 ZoneList<const AstRawString*>* strings_;
225 const char* symbol_name_; 232 const char* symbol_name_;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 static_cast<int>(strlen(data)))); \ 334 static_cast<int>(strlen(data)))); \
328 } \ 335 } \
329 return name##_string_; \ 336 return name##_string_; \
330 } 337 }
331 STRING_CONSTANTS(F) 338 STRING_CONSTANTS(F)
332 #undef F 339 #undef F
333 340
334 const AstValue* NewString(const AstRawString* string); 341 const AstValue* NewString(const AstRawString* string);
335 // A JavaScript symbol (ECMA-262 edition 6). 342 // A JavaScript symbol (ECMA-262 edition 6).
336 const AstValue* NewSymbol(const char* name); 343 const AstValue* NewSymbol(const char* name);
337 const AstValue* NewNumber(double number); 344 const AstValue* NewNumber(double number, bool with_dot = false);
rossberg 2015/06/30 12:07:01 Nit: is_float?
bradn 2015/06/30 20:03:46 Sticking with with_dot as per discussion.
338 const AstValue* NewSmi(int number); 345 const AstValue* NewSmi(int number);
339 const AstValue* NewBoolean(bool b); 346 const AstValue* NewBoolean(bool b);
340 const AstValue* NewStringList(ZoneList<const AstRawString*>* strings); 347 const AstValue* NewStringList(ZoneList<const AstRawString*>* strings);
341 const AstValue* NewNull(); 348 const AstValue* NewNull();
342 const AstValue* NewUndefined(); 349 const AstValue* NewUndefined();
343 const AstValue* NewTheHole(); 350 const AstValue* NewTheHole();
344 351
345 private: 352 private:
346 AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal); 353 AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal);
347 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); 354 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal);
(...skipping 20 matching lines...) Expand all
368 #define F(name) AstValue* name##_; 375 #define F(name) AstValue* name##_;
369 OTHER_CONSTANTS(F) 376 OTHER_CONSTANTS(F)
370 #undef F 377 #undef F
371 }; 378 };
372 } } // namespace v8::internal 379 } } // namespace v8::internal
373 380
374 #undef STRING_CONSTANTS 381 #undef STRING_CONSTANTS
375 #undef OTHER_CONSTANTS 382 #undef OTHER_CONSTANTS
376 383
377 #endif // V8_AST_VALUE_FACTORY_H_ 384 #endif // V8_AST_VALUE_FACTORY_H_
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/ast-value-factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698