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

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

Issue 657893003: AstValueFactory: make true, false, null, undefined and "the hole" unique values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: oops Created 6 years, 1 month 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 | « no previous file | 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 bool bool_; 231 bool bool_;
232 ZoneList<const AstRawString*>* strings_; 232 ZoneList<const AstRawString*>* strings_;
233 const char* symbol_name_; 233 const char* symbol_name_;
234 }; 234 };
235 235
236 // Internalized value (empty before internalized). 236 // Internalized value (empty before internalized).
237 Handle<Object> value_; 237 Handle<Object> value_;
238 }; 238 };
239 239
240 240
241 // For generating string constants. 241 // For generating constants.
242 #define STRING_CONSTANTS(F) \ 242 #define STRING_CONSTANTS(F) \
243 F(anonymous_function, "(anonymous function)") \ 243 F(anonymous_function, "(anonymous function)") \
244 F(arguments, "arguments") \ 244 F(arguments, "arguments") \
245 F(constructor, "constructor") \ 245 F(constructor, "constructor") \
246 F(done, "done") \ 246 F(done, "done") \
247 F(dot, ".") \ 247 F(dot, ".") \
248 F(dot_for, ".for") \ 248 F(dot_for, ".for") \
249 F(dot_generator, ".generator") \ 249 F(dot_generator, ".generator") \
250 F(dot_generator_object, ".generator_object") \ 250 F(dot_generator_object, ".generator_object") \
251 F(dot_iterator, ".iterator") \ 251 F(dot_iterator, ".iterator") \
252 F(dot_module, ".module") \ 252 F(dot_module, ".module") \
253 F(dot_result, ".result") \ 253 F(dot_result, ".result") \
254 F(empty, "") \ 254 F(empty, "") \
255 F(eval, "eval") \ 255 F(eval, "eval") \
256 F(initialize_const_global, "initializeConstGlobal") \ 256 F(initialize_const_global, "initializeConstGlobal") \
257 F(initialize_var_global, "initializeVarGlobal") \ 257 F(initialize_var_global, "initializeVarGlobal") \
258 F(make_reference_error, "MakeReferenceError") \ 258 F(make_reference_error, "MakeReferenceError") \
259 F(make_syntax_error, "MakeSyntaxError") \ 259 F(make_syntax_error, "MakeSyntaxError") \
260 F(make_type_error, "MakeTypeError") \ 260 F(make_type_error, "MakeTypeError") \
261 F(module, "module") \ 261 F(module, "module") \
262 F(native, "native") \ 262 F(native, "native") \
263 F(next, "next") \ 263 F(next, "next") \
264 F(proto, "__proto__") \ 264 F(proto, "__proto__") \
265 F(prototype, "prototype") \ 265 F(prototype, "prototype") \
266 F(this, "this") \ 266 F(this, "this") \
267 F(use_asm, "use asm") \ 267 F(use_asm, "use asm") \
268 F(use_strict, "use strict") \ 268 F(use_strict, "use strict") \
269 F(value, "value") 269 F(value, "value")
270 270
271 #define OTHER_CONSTANTS(F) \
272 F(true_value) \
273 F(false_value) \
274 F(null_value) \
275 F(undefined_value) \
276 F(the_hole_value)
271 277
272 class AstValueFactory { 278 class AstValueFactory {
273 public: 279 public:
274 AstValueFactory(Zone* zone, uint32_t hash_seed) 280 AstValueFactory(Zone* zone, uint32_t hash_seed)
275 : string_table_(AstRawString::Compare), 281 : string_table_(AstRawString::Compare),
276 zone_(zone), 282 zone_(zone),
277 isolate_(NULL), 283 isolate_(NULL),
278 hash_seed_(hash_seed) { 284 hash_seed_(hash_seed) {
279 #define F(name, str) \ 285 #define F(name, str) name##_string_ = NULL;
280 name##_string_ = NULL;
281 STRING_CONSTANTS(F) 286 STRING_CONSTANTS(F)
282 #undef F 287 #undef F
288 #define F(name) name##_ = NULL;
289 OTHER_CONSTANTS(F)
290 #undef F
283 } 291 }
284 292
285 Zone* zone() const { return zone_; } 293 Zone* zone() const { return zone_; }
286 294
287 const AstRawString* GetOneByteString(Vector<const uint8_t> literal); 295 const AstRawString* GetOneByteString(Vector<const uint8_t> literal);
288 const AstRawString* GetOneByteString(const char* string) { 296 const AstRawString* GetOneByteString(const char* string) {
289 return GetOneByteString(Vector<const uint8_t>( 297 return GetOneByteString(Vector<const uint8_t>(
290 reinterpret_cast<const uint8_t*>(string), StrLength(string))); 298 reinterpret_cast<const uint8_t*>(string), StrLength(string)));
291 } 299 }
292 const AstRawString* GetTwoByteString(Vector<const uint16_t> literal); 300 const AstRawString* GetTwoByteString(Vector<const uint16_t> literal);
293 const AstRawString* GetString(Handle<String> literal); 301 const AstRawString* GetString(Handle<String> literal);
294 const AstConsString* NewConsString(const AstString* left, 302 const AstConsString* NewConsString(const AstString* left,
295 const AstString* right); 303 const AstString* right);
296 304
297 void Internalize(Isolate* isolate); 305 void Internalize(Isolate* isolate);
298 bool IsInternalized() { 306 bool IsInternalized() {
299 return isolate_ != NULL; 307 return isolate_ != NULL;
300 } 308 }
301 309
302 #define F(name, str) \ 310 #define F(name, str) \
303 const AstRawString* name##_string() { \ 311 const AstRawString* name##_string() { \
304 if (name##_string_ == NULL) { \ 312 if (name##_string_ == NULL) { \
305 const char* data = str; \ 313 const char* data = str; \
306 name##_string_ = GetOneByteString( \ 314 name##_string_ = GetOneByteString( \
307 Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), \ 315 Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), \
308 static_cast<int>(strlen(data)))); \ 316 static_cast<int>(strlen(data)))); \
309 } \ 317 } \
310 return name##_string_; \ 318 return name##_string_; \
311 } 319 }
312 STRING_CONSTANTS(F) 320 STRING_CONSTANTS(F)
313 #undef F 321 #undef F
314 322
315 const AstValue* NewString(const AstRawString* string); 323 const AstValue* NewString(const AstRawString* string);
316 // A JavaScript symbol (ECMA-262 edition 6). 324 // A JavaScript symbol (ECMA-262 edition 6).
317 const AstValue* NewSymbol(const char* name); 325 const AstValue* NewSymbol(const char* name);
318 const AstValue* NewNumber(double number); 326 const AstValue* NewNumber(double number);
319 const AstValue* NewSmi(int number); 327 const AstValue* NewSmi(int number);
320 const AstValue* NewBoolean(bool b); 328 const AstValue* NewBoolean(bool b);
(...skipping 10 matching lines...) Expand all
331 HashMap string_table_; 339 HashMap string_table_;
332 // For keeping track of all AstValues and AstRawStrings we've created (so that 340 // For keeping track of all AstValues and AstRawStrings we've created (so that
333 // they can be internalized later). 341 // they can be internalized later).
334 List<AstValue*> values_; 342 List<AstValue*> values_;
335 List<AstString*> strings_; 343 List<AstString*> strings_;
336 Zone* zone_; 344 Zone* zone_;
337 Isolate* isolate_; 345 Isolate* isolate_;
338 346
339 uint32_t hash_seed_; 347 uint32_t hash_seed_;
340 348
341 #define F(name, str) \ 349 #define F(name, str) const AstRawString* name##_string_;
342 const AstRawString* name##_string_;
343 STRING_CONSTANTS(F) 350 STRING_CONSTANTS(F)
344 #undef F 351 #undef F
352
353 #define F(name) AstValue* name##_;
354 OTHER_CONSTANTS(F)
355 #undef F
345 }; 356 };
346 357
347 358
348 bool AstRawString::IsArguments(AstValueFactory* ast_value_factory) const { 359 bool AstRawString::IsArguments(AstValueFactory* ast_value_factory) const {
349 return ast_value_factory->arguments_string() == this; 360 return ast_value_factory->arguments_string() == this;
350 } 361 }
351 } } // namespace v8::internal 362 } } // namespace v8::internal
352 363
353 #undef STRING_CONSTANTS 364 #undef STRING_CONSTANTS
365 #undef OTHER_CONSTANTS
354 366
355 #endif // V8_AST_VALUE_FACTORY_H_ 367 #endif // V8_AST_VALUE_FACTORY_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast-value-factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698