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) {
DCHECK(!string_->string().is_null());
break;
case SYMBOL:
if (symbol_name_[0] == 'i') {
DCHECK_EQ(0, strcmp(symbol_name_, "iterator_symbol"));
set_value(isolate->factory()->iterator_symbol());
} else if (strcmp(symbol_name_, "hasInstance_symbol") == 0) {
set_value(isolate->factory()->has_instance_symbol());
} else {
DCHECK_EQ(0, strcmp(symbol_name_, "home_object_symbol"));
set_value(isolate->factory()->home_object_symbol());
switch (symbol_) {
case AstSymbol::kHomeObjectSymbol:
set_value(isolate->factory()->home_object_symbol());
break;
}
break;
case NUMBER_WITH_DOT:
......@@ -295,9 +291,8 @@ const AstValue* AstValueFactory::NewString(const AstRawString* string) {
return AddValue(value);
}
const AstValue* AstValueFactory::NewSymbol(const char* name) {
AstValue* value = new (zone_) AstValue(name);
const AstValue* AstValueFactory::NewSymbol(AstSymbol symbol) {
AstValue* value = new (zone_) AstValue(symbol);
return AddValue(value);
}
......
......@@ -152,15 +152,18 @@ class AstConsString final : public AstString {
const AstString* right_;
};
enum class AstSymbol : uint8_t { kHomeObjectSymbol };
// AstValue is either a string, a number, a string array, a boolean, or a
// special value (null, undefined, the hole).
// AstValue is either a string, a symbol, a number, a string array, a boolean,
// or a special value (null, undefined, the hole).
class AstValue : public ZoneObject {
public:
bool IsString() const {
return type_ == STRING;
}
bool IsSymbol() const { return type_ == SYMBOL; }
bool IsNumber() const { return IsSmi() || IsHeapNumber(); }
bool ContainsDot() const {
......@@ -172,6 +175,11 @@ class AstValue : public ZoneObject {
return string_;
}
AstSymbol AsSymbol() const {
CHECK_EQ(SYMBOL, type_);
return symbol_;
}
double AsNumber() const {
if (IsHeapNumber()) return number_;
if (IsSmi()) return smi_;
......@@ -249,8 +257,8 @@ class AstValue : public ZoneObject {
string_ = s;
}
explicit AstValue(const char* name) : type_(SYMBOL), next_(nullptr) {
symbol_name_ = name;
explicit AstValue(AstSymbol symbol) : type_(SYMBOL), next_(nullptr) {
symbol_ = symbol;
}
explicit AstValue(double n, bool with_dot) : next_(nullptr) {
......@@ -290,7 +298,7 @@ class AstValue : public ZoneObject {
double number_;
int smi_;
bool bool_;
const char* symbol_name_;
AstSymbol symbol_;
};
};
......@@ -428,7 +436,7 @@ class AstValueFactory {
const AstValue* NewString(const AstRawString* string);
// 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* NewSmi(uint32_t number);
const AstValue* NewBoolean(bool b);
......
......@@ -3291,8 +3291,8 @@ class AstNodeFactory final BASE_EMBEDDED {
}
// A JavaScript symbol (ECMA-262 edition 6).
Literal* NewSymbolLiteral(const char* name, int pos) {
return new (zone_) Literal(ast_value_factory_->NewSymbol(name), pos);
Literal* NewSymbolLiteral(AstSymbol symbol, int pos) {
return new (zone_) Literal(ast_value_factory_->NewSymbol(symbol), pos);
}
Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) {
......
......@@ -388,8 +388,8 @@ Expression* Parser::NewSuperPropertyReference(int pos) {
// this_function[home_object_symbol]
VariableProxy* this_function_proxy =
NewUnresolved(ast_value_factory()->this_function_string(), pos);
Expression* home_object_symbol_literal =
factory()->NewSymbolLiteral("home_object_symbol", kNoSourcePosition);
Expression* home_object_symbol_literal = factory()->NewSymbolLiteral(
AstSymbol::kHomeObjectSymbol, kNoSourcePosition);
Expression* home_object = factory()->NewProperty(
this_function_proxy, home_object_symbol_literal, pos);
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