28 #ifndef V8_AST_AST_VALUE_FACTORY_H_ 29 #define V8_AST_AST_VALUE_FACTORY_H_ 31 #include <forward_list> 33 #include "src/base/hashmap.h" 34 #include "src/conversions.h" 35 #include "src/globals.h" 36 #include "src/heap/factory.h" 37 #include "src/isolate.h" 38 #include "src/utils.h" 50 bool IsEmpty()
const {
return literal_bytes_.length() == 0; }
52 return is_one_byte() ? literal_bytes_.length()
53 : literal_bytes_.length() / 2;
55 bool AsArrayIndex(
uint32_t* index)
const;
56 bool IsOneByteEqualTo(
const char* data)
const;
57 uint16_t FirstCharacter()
const;
59 void Internalize(
Isolate* isolate);
62 bool is_one_byte()
const {
return is_one_byte_; }
63 int byte_length()
const {
return literal_bytes_.length(); }
64 const unsigned char* raw_data()
const {
65 return literal_bytes_.start();
69 uint32_t hash_field()
const {
return hash_field_; }
70 uint32_t Hash()
const {
return hash_field_ >> Name::kHashShift; }
74 DCHECK_NOT_NULL(string_);
85 static bool Compare(
void* a,
void* b);
89 literal_bytes_(literal_bytes),
90 hash_field_(hash_field),
91 is_one_byte_(is_one_byte) {}
102 DCHECK(!
string.is_null());
103 DCHECK(!has_string_);
104 string_ =
string.location();
124 bool has_string_ =
false;
131 if (s->IsEmpty())
return this;
135 Segment* tmp =
new (zone->New(
sizeof(Segment))) Segment;
143 bool IsEmpty()
const {
144 DCHECK_IMPLIES(segment_.string ==
nullptr, segment_.next ==
nullptr);
145 DCHECK_IMPLIES(segment_.string !=
nullptr, !segment_.string->IsEmpty());
146 return segment_.string ==
nullptr;
149 void Internalize(
Isolate* isolate);
152 DCHECK_NOT_NULL(string_);
156 std::forward_list<const AstRawString*> ToRawStrings()
const;
161 AstConsString() : next_(
nullptr), segment_({
nullptr,
nullptr}) {}
168 void set_string(
Handle<String> string) { string_ =
string.location(); }
176 AstConsString::Segment* next;
181 enum class AstSymbol : uint8_t { kHomeObjectSymbol };
188 explicit AstBigInt(
const char* bigint) : bigint_(bigint) {}
190 const char* c_str()
const {
return bigint_; }
197 #define AST_STRING_CONSTANTS(F) \ 198 F(anonymous, "anonymous") \ 199 F(anonymous_function, "(anonymous function)") \ 200 F(arguments, "arguments") \ 204 F(bigint, "bigint") \ 205 F(boolean, "boolean") \ 206 F(constructor, "constructor") \ 207 F(default, "default") \ 211 F(dot_generator_object, ".generator_object") \ 212 F(dot_iterator, ".iterator") \ 213 F(dot_promise, ".promise") \ 214 F(dot_result, ".result") \ 215 F(dot_switch_tag, ".switch_tag") \ 216 F(dot_catch, ".catch") \ 220 F(function, "function") \ 222 F(get_space, "get ") \ 223 F(length, "length") \ 227 F(native, "native") \ 228 F(new_target, ".new.target") \ 230 F(number, "number") \ 231 F(object, "object") \ 233 F(private_constructor, "#constructor") \ 234 F(proto, "__proto__") \ 235 F(prototype, "prototype") \ 236 F(return, "return") \ 238 F(set_space, "set ") \ 239 F(star_default_star, "*default*") \ 240 F(string, "string") \ 241 F(symbol, "symbol") \ 242 F(target, "target") \ 244 F(this_function, ".this_function") \ 246 F(undefined, "undefined") \ 253 #define F(name, str) \ 254 const AstRawString* name##_string() const { return name##_string_; } 255 AST_STRING_CONSTANTS(F)
258 uint64_t hash_seed()
const {
return hash_seed_; }
259 const base::CustomMatcherHashMap* string_table()
const {
260 return &string_table_;
265 base::CustomMatcherHashMap string_table_;
268 #define F(name, str) AstRawString* name##_string_; 269 AST_STRING_CONSTANTS(F)
279 : string_table_(string_constants->string_table()),
281 strings_end_(&strings_),
282 cons_strings_(
nullptr),
283 cons_strings_end_(&cons_strings_),
284 string_constants_(string_constants),
285 empty_cons_string_(
nullptr),
287 hash_seed_(hash_seed) {
288 DCHECK_EQ(hash_seed, string_constants->hash_seed());
289 std::fill(one_character_strings_,
290 one_character_strings_ + arraysize(one_character_strings_),
292 empty_cons_string_ = NewConsString();
295 Zone* zone()
const {
return zone_; }
298 return GetOneByteStringInternal(literal);
300 const AstRawString* GetOneByteString(
const char*
string) {
302 reinterpret_cast<const uint8_t*>(
string), StrLength(
string)));
305 return GetTwoByteStringInternal(literal);
318 V8_EXPORT_PRIVATE
void Internalize(
Isolate* isolate);
320 #define F(name, str) \ 321 const AstRawString* name##_string() const { \ 322 return string_constants_->name##_string(); \ 324 AST_STRING_CONSTANTS(F)
326 const AstConsString* empty_cons_string()
const {
return empty_cons_string_; }
330 *strings_end_ = string;
331 strings_end_ =
string->next_location();
335 *cons_strings_end_ = string;
336 cons_strings_end_ =
string->next_location();
339 void ResetStrings() {
341 strings_end_ = &strings_;
342 cons_strings_ =
nullptr;
343 cons_strings_end_ = &cons_strings_;
345 V8_EXPORT_PRIVATE
AstRawString* GetOneByteStringInternal(
352 base::CustomMatcherHashMap string_table_;
366 static const int kMaxOneCharStringValue = 128;
367 AstRawString* one_character_strings_[kMaxOneCharStringValue];
376 #endif // V8_AST_AST_VALUE_FACTORY_H_