| OLD | NEW |
| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 #ifdef DEBUG | 119 #ifdef DEBUG |
| 120 // (Debug-only:) Verify the object life-cylce: Some functions may only be | 120 // (Debug-only:) Verify the object life-cylce: Some functions may only be |
| 121 // called after internalization (that is, after a v8::internal::String has | 121 // called after internalization (that is, after a v8::internal::String has |
| 122 // been set); some only before. | 122 // been set); some only before. |
| 123 bool has_string_ = false; | 123 bool has_string_ = false; |
| 124 #endif | 124 #endif |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 class AstConsString final : public ZoneObject { | 127 class AstConsString final : public ZoneObject { |
| 128 public: | 128 public: |
| 129 AstConsString* AddString(const AstRawString* s) { | 129 AstConsString* AddString(Zone* zone, const AstRawString* s) { |
| 130 if (s && !s->IsEmpty()) strings_.push_back(s); | 130 if (s->IsEmpty()) return this; |
| 131 if (!IsEmpty()) { |
| 132 // We're putting the new string to the head of the list, meaning |
| 133 // the string segments will be in reverse order. |
| 134 Segment* tmp = new (zone->New(sizeof(Segment))) Segment; |
| 135 *tmp = segment_; |
| 136 segment_.next = tmp; |
| 137 } |
| 138 segment_.string = s; |
| 131 return this; | 139 return this; |
| 132 } | 140 } |
| 133 | 141 |
| 134 bool IsEmpty() const { return strings_.empty(); } | 142 bool IsEmpty() const { |
| 143 DCHECK_IMPLIES(segment_.string == nullptr, segment_.next == nullptr); |
| 144 DCHECK_IMPLIES(segment_.string != nullptr, !segment_.string->IsEmpty()); |
| 145 return segment_.string == nullptr; |
| 146 } |
| 135 | 147 |
| 136 void Internalize(Isolate* isolate); | 148 void Internalize(Isolate* isolate); |
| 137 | 149 |
| 138 V8_INLINE Handle<String> string() const { | 150 V8_INLINE Handle<String> string() const { |
| 139 DCHECK_NOT_NULL(string_); | 151 DCHECK_NOT_NULL(string_); |
| 140 return Handle<String>(string_); | 152 return Handle<String>(string_); |
| 141 } | 153 } |
| 142 | 154 |
| 143 private: | 155 private: |
| 144 friend class AstValueFactory; | 156 friend class AstValueFactory; |
| 145 | 157 |
| 146 explicit AstConsString(Zone* zone) : next_(nullptr), strings_(zone) {} | 158 AstConsString() : next_(nullptr), segment_({nullptr, nullptr}) {} |
| 147 | 159 |
| 148 AstConsString* next() const { return next_; } | 160 AstConsString* next() const { return next_; } |
| 149 AstConsString** next_location() { return &next_; } | 161 AstConsString** next_location() { return &next_; } |
| 150 | 162 |
| 151 // {string_} is stored as String** instead of a Handle<String> so it can be | 163 // {string_} is stored as String** instead of a Handle<String> so it can be |
| 152 // stored in a union with {next_}. | 164 // stored in a union with {next_}. |
| 153 void set_string(Handle<String> string) { string_ = string.location(); } | 165 void set_string(Handle<String> string) { string_ = string.location(); } |
| 154 union { | 166 union { |
| 155 AstConsString* next_; | 167 AstConsString* next_; |
| 156 String** string_; | 168 String** string_; |
| 157 }; | 169 }; |
| 158 | 170 |
| 159 ZoneLinkedList<const AstRawString*> strings_; | 171 struct Segment { |
| 172 const AstRawString* string; |
| 173 AstConsString::Segment* next; |
| 174 }; |
| 175 Segment segment_; |
| 160 }; | 176 }; |
| 161 | 177 |
| 162 enum class AstSymbol : uint8_t { kHomeObjectSymbol }; | 178 enum class AstSymbol : uint8_t { kHomeObjectSymbol }; |
| 163 | 179 |
| 164 // AstValue is either a string, a symbol, a number, a string array, a boolean, | 180 // AstValue is either a string, a symbol, a number, a string array, a boolean, |
| 165 // or a special value (null, undefined, the hole). | 181 // or a special value (null, undefined, the hole). |
| 166 class AstValue : public ZoneObject { | 182 class AstValue : public ZoneObject { |
| 167 public: | 183 public: |
| 168 bool IsString() const { | 184 bool IsString() const { |
| 169 return type_ == STRING; | 185 return type_ == STRING; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 OTHER_CONSTANTS(F) | 552 OTHER_CONSTANTS(F) |
| 537 #undef F | 553 #undef F |
| 538 }; | 554 }; |
| 539 } // namespace internal | 555 } // namespace internal |
| 540 } // namespace v8 | 556 } // namespace v8 |
| 541 | 557 |
| 542 #undef STRING_CONSTANTS | 558 #undef STRING_CONSTANTS |
| 543 #undef OTHER_CONSTANTS | 559 #undef OTHER_CONSTANTS |
| 544 | 560 |
| 545 #endif // V8_AST_AST_VALUE_FACTORY_H_ | 561 #endif // V8_AST_AST_VALUE_FACTORY_H_ |
| OLD | NEW |