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

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: fix 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; }
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)
157 return number_; 159 return number_;
158 if (type_ == SMI) 160 if (type_ == SMI)
159 return smi_; 161 return smi_;
160 UNREACHABLE(); 162 UNREACHABLE();
161 return 0; 163 return 0;
162 } 164 }
163 165
164 bool EqualsString(const AstRawString* string) const { 166 bool EqualsString(const AstRawString* string) const {
165 return type_ == STRING && string_ == string; 167 return type_ == STRING && string_ == string;
166 } 168 }
(...skipping 15 matching lines...) Expand all
182 return value_; 184 return value_;
183 } 185 }
184 186
185 private: 187 private:
186 friend class AstValueFactory; 188 friend class AstValueFactory;
187 189
188 enum Type { 190 enum Type {
189 STRING, 191 STRING,
190 SYMBOL, 192 SYMBOL,
191 NUMBER, 193 NUMBER,
194 NUMBER_WITH_DOT,
192 SMI, 195 SMI,
193 BOOLEAN, 196 BOOLEAN,
194 NULL_TYPE, 197 NULL_TYPE,
195 UNDEFINED, 198 UNDEFINED,
196 THE_HOLE 199 THE_HOLE
197 }; 200 };
198 201
199 explicit AstValue(const AstRawString* s) : type_(STRING) { string_ = s; } 202 explicit AstValue(const AstRawString* s) : type_(STRING) { string_ = s; }
200 203
201 explicit AstValue(const char* name) : type_(SYMBOL) { symbol_name_ = name; } 204 explicit AstValue(const char* name) : type_(SYMBOL) { symbol_name_ = name; }
202 205
203 explicit AstValue(double n) : type_(NUMBER) { number_ = n; } 206 explicit AstValue(double n, bool with_dot) {
207 if (with_dot) {
208 type_ = NUMBER_WITH_DOT;
209 } else {
210 type_ = NUMBER;
211 }
212 number_ = n;
213 }
204 214
205 AstValue(Type t, int i) : type_(t) { 215 AstValue(Type t, int i) : type_(t) {
206 DCHECK(type_ == SMI); 216 DCHECK(type_ == SMI);
207 smi_ = i; 217 smi_ = i;
208 } 218 }
209 219
210 explicit AstValue(bool b) : type_(BOOLEAN) { bool_ = b; } 220 explicit AstValue(bool b) : type_(BOOLEAN) { bool_ = b; }
211 221
212 explicit AstValue(Type t) : type_(t) { 222 explicit AstValue(Type t) : type_(t) {
213 DCHECK(t == NULL_TYPE || t == UNDEFINED || t == THE_HOLE); 223 DCHECK(t == NULL_TYPE || t == UNDEFINED || t == THE_HOLE);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 static_cast<int>(strlen(data)))); \ 337 static_cast<int>(strlen(data)))); \
328 } \ 338 } \
329 return name##_string_; \ 339 return name##_string_; \
330 } 340 }
331 STRING_CONSTANTS(F) 341 STRING_CONSTANTS(F)
332 #undef F 342 #undef F
333 343
334 const AstValue* NewString(const AstRawString* string); 344 const AstValue* NewString(const AstRawString* string);
335 // A JavaScript symbol (ECMA-262 edition 6). 345 // A JavaScript symbol (ECMA-262 edition 6).
336 const AstValue* NewSymbol(const char* name); 346 const AstValue* NewSymbol(const char* name);
337 const AstValue* NewNumber(double number); 347 const AstValue* NewNumber(double number, bool with_dot = false);
338 const AstValue* NewSmi(int number); 348 const AstValue* NewSmi(int number);
339 const AstValue* NewBoolean(bool b); 349 const AstValue* NewBoolean(bool b);
340 const AstValue* NewStringList(ZoneList<const AstRawString*>* strings); 350 const AstValue* NewStringList(ZoneList<const AstRawString*>* strings);
341 const AstValue* NewNull(); 351 const AstValue* NewNull();
342 const AstValue* NewUndefined(); 352 const AstValue* NewUndefined();
343 const AstValue* NewTheHole(); 353 const AstValue* NewTheHole();
344 354
345 private: 355 private:
346 AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal); 356 AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal);
347 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); 357 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal);
(...skipping 20 matching lines...) Expand all
368 #define F(name) AstValue* name##_; 378 #define F(name) AstValue* name##_;
369 OTHER_CONSTANTS(F) 379 OTHER_CONSTANTS(F)
370 #undef F 380 #undef F
371 }; 381 };
372 } } // namespace v8::internal 382 } } // namespace v8::internal
373 383
374 #undef STRING_CONSTANTS 384 #undef STRING_CONSTANTS
375 #undef OTHER_CONSTANTS 385 #undef OTHER_CONSTANTS
376 386
377 #endif // V8_AST_VALUE_FACTORY_H_ 387 #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