Commit ec90b3f5 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[ast] Replace AstSymbols from char* to enum

Cleans up the internalization. Also, clean up no-longer-used ast
symbols, iterator and hasInstance, which were left behind after other
refactors. Having an enum here should keep this clean in the future.

Change-Id: Id526784b0361c7a2242b21ecf2af72b0403c6ad8
Reviewed-on: https://chromium-review.googlesource.com/440204Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43069}
parent eb5915b4
...@@ -184,14 +184,10 @@ void AstValue::Internalize(Isolate* isolate) { ...@@ -184,14 +184,10 @@ void AstValue::Internalize(Isolate* isolate) {
DCHECK(!string_->string().is_null()); DCHECK(!string_->string().is_null());
break; break;
case SYMBOL: case SYMBOL:
if (symbol_name_[0] == 'i') { switch (symbol_) {
DCHECK_EQ(0, strcmp(symbol_name_, "iterator_symbol")); case AstSymbol::kHomeObjectSymbol:
set_value(isolate->factory()->iterator_symbol()); set_value(isolate->factory()->home_object_symbol());
} else if (strcmp(symbol_name_, "hasInstance_symbol") == 0) { break;
set_value(isolate->factory()->has_instance_symbol());
} else {
DCHECK_EQ(0, strcmp(symbol_name_, "home_object_symbol"));
set_value(isolate->factory()->home_object_symbol());
} }
break; break;
case NUMBER_WITH_DOT: case NUMBER_WITH_DOT:
...@@ -295,9 +291,8 @@ const AstValue* AstValueFactory::NewString(const AstRawString* string) { ...@@ -295,9 +291,8 @@ const AstValue* AstValueFactory::NewString(const AstRawString* string) {
return AddValue(value); return AddValue(value);
} }
const AstValue* AstValueFactory::NewSymbol(AstSymbol symbol) {
const AstValue* AstValueFactory::NewSymbol(const char* name) { AstValue* value = new (zone_) AstValue(symbol);
AstValue* value = new (zone_) AstValue(name);
return AddValue(value); return AddValue(value);
} }
......
...@@ -152,15 +152,18 @@ class AstConsString final : public AstString { ...@@ -152,15 +152,18 @@ class AstConsString final : public AstString {
const AstString* right_; const AstString* right_;
}; };
enum class AstSymbol : uint8_t { kHomeObjectSymbol };
// AstValue is either a string, a number, a string array, a boolean, or a // AstValue is either a string, a symbol, a number, a string array, a boolean,
// special value (null, undefined, the hole). // or a special value (null, undefined, the hole).
class AstValue : public ZoneObject { class AstValue : public ZoneObject {
public: public:
bool IsString() const { bool IsString() const {
return type_ == STRING; return type_ == STRING;
} }
bool IsSymbol() const { return type_ == SYMBOL; }
bool IsNumber() const { return IsSmi() || IsHeapNumber(); } bool IsNumber() const { return IsSmi() || IsHeapNumber(); }
bool ContainsDot() const { bool ContainsDot() const {
...@@ -172,6 +175,11 @@ class AstValue : public ZoneObject { ...@@ -172,6 +175,11 @@ class AstValue : public ZoneObject {
return string_; return string_;
} }
AstSymbol AsSymbol() const {
CHECK_EQ(SYMBOL, type_);
return symbol_;
}
double AsNumber() const { double AsNumber() const {
if (IsHeapNumber()) return number_; if (IsHeapNumber()) return number_;
if (IsSmi()) return smi_; if (IsSmi()) return smi_;
...@@ -249,8 +257,8 @@ class AstValue : public ZoneObject { ...@@ -249,8 +257,8 @@ class AstValue : public ZoneObject {
string_ = s; string_ = s;
} }
explicit AstValue(const char* name) : type_(SYMBOL), next_(nullptr) { explicit AstValue(AstSymbol symbol) : type_(SYMBOL), next_(nullptr) {
symbol_name_ = name; symbol_ = symbol;
} }
explicit AstValue(double n, bool with_dot) : next_(nullptr) { explicit AstValue(double n, bool with_dot) : next_(nullptr) {
...@@ -290,7 +298,7 @@ class AstValue : public ZoneObject { ...@@ -290,7 +298,7 @@ class AstValue : public ZoneObject {
double number_; double number_;
int smi_; int smi_;
bool bool_; bool bool_;
const char* symbol_name_; AstSymbol symbol_;
}; };
}; };
...@@ -428,7 +436,7 @@ class AstValueFactory { ...@@ -428,7 +436,7 @@ class AstValueFactory {
const AstValue* NewString(const AstRawString* string); const AstValue* NewString(const AstRawString* string);
// A JavaScript symbol (ECMA-262 edition 6). // A JavaScript symbol (ECMA-262 edition 6).
const AstValue* NewSymbol(const char* name); const AstValue* NewSymbol(AstSymbol symbol);
const AstValue* NewNumber(double number, bool with_dot = false); const AstValue* NewNumber(double number, bool with_dot = false);
const AstValue* NewSmi(uint32_t number); const AstValue* NewSmi(uint32_t number);
const AstValue* NewBoolean(bool b); const AstValue* NewBoolean(bool b);
......
...@@ -3291,8 +3291,8 @@ class AstNodeFactory final BASE_EMBEDDED { ...@@ -3291,8 +3291,8 @@ class AstNodeFactory final BASE_EMBEDDED {
} }
// A JavaScript symbol (ECMA-262 edition 6). // A JavaScript symbol (ECMA-262 edition 6).
Literal* NewSymbolLiteral(const char* name, int pos) { Literal* NewSymbolLiteral(AstSymbol symbol, int pos) {
return new (zone_) Literal(ast_value_factory_->NewSymbol(name), pos); return new (zone_) Literal(ast_value_factory_->NewSymbol(symbol), pos);
} }
Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) { Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) {
......
...@@ -388,8 +388,8 @@ Expression* Parser::NewSuperPropertyReference(int pos) { ...@@ -388,8 +388,8 @@ Expression* Parser::NewSuperPropertyReference(int pos) {
// this_function[home_object_symbol] // this_function[home_object_symbol]
VariableProxy* this_function_proxy = VariableProxy* this_function_proxy =
NewUnresolved(ast_value_factory()->this_function_string(), pos); NewUnresolved(ast_value_factory()->this_function_string(), pos);
Expression* home_object_symbol_literal = Expression* home_object_symbol_literal = factory()->NewSymbolLiteral(
factory()->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); AstSymbol::kHomeObjectSymbol, kNoSourcePosition);
Expression* home_object = factory()->NewProperty( Expression* home_object = factory()->NewProperty(
this_function_proxy, home_object_symbol_literal, pos); this_function_proxy, home_object_symbol_literal, pos);
return factory()->NewSuperPropertyReference( return factory()->NewSuperPropertyReference(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment