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

Unified Diff: src/ast.h

Issue 231073002: WIP: Parser: delay string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: more cleanup Created 6 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/ast.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index 5f696b584eb50951a1741093f609e77eee4274c8..ac04771633aa1ad2516c616bab34c8dd1c18b214 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -8,6 +8,7 @@
#include "v8.h"
#include "assembler.h"
+#include "ast-string-table.h"
#include "factory.h"
#include "feedback-slots.h"
#include "isolate.h"
@@ -367,11 +368,14 @@ class Expression : public AstNode {
protected:
Expression(Zone* zone, int pos)
: AstNode(pos),
+ zone_(zone),
bounds_(Bounds::Unbounded(zone)),
id_(GetNextId(zone)),
test_id_(GetNextId(zone)) {}
void set_to_boolean_types(byte types) { to_boolean_types_ = types; }
+ Zone* zone_;
+
private:
Bounds bounds_;
byte to_boolean_types_;
@@ -390,7 +394,7 @@ class BreakableStatement : public Statement {
// The labels associated with this statement. May be NULL;
// if it is != NULL, guaranteed to contain at least one entry.
- ZoneStringList* labels() const { return labels_; }
+ ZoneList<const AstString*>* labels() const { return labels_; }
// Type testing & conversion.
virtual BreakableStatement* AsBreakableStatement() V8_FINAL V8_OVERRIDE {
@@ -410,7 +414,7 @@ class BreakableStatement : public Statement {
protected:
BreakableStatement(
- Zone* zone, ZoneStringList* labels,
+ Zone* zone, ZoneList<const AstString*>* labels,
BreakableType breakable_type, int position)
: Statement(zone, position),
labels_(labels),
@@ -422,7 +426,7 @@ class BreakableStatement : public Statement {
private:
- ZoneStringList* labels_;
+ ZoneList<const AstString*>* labels_;
BreakableType breakable_type_;
Label break_target_;
const BailoutId entry_id_;
@@ -451,7 +455,7 @@ class Block V8_FINAL : public BreakableStatement {
protected:
Block(Zone* zone,
- ZoneStringList* labels,
+ ZoneList<const AstString*>* labels,
int capacity,
bool is_initializer_block,
int pos)
@@ -658,18 +662,16 @@ class ModulePath V8_FINAL : public Module {
DECLARE_NODE_TYPE(ModulePath)
Module* module() const { return module_; }
- Handle<String> name() const { return name_; }
+ Handle<String> name() const { return name_->string(); }
protected:
- ModulePath(Zone* zone, Module* module, Handle<String> name, int pos)
- : Module(zone, pos),
- module_(module),
- name_(name) {
- }
+ ModulePath(Zone* zone, Module* module, const AstString* name,
+ int pos)
+ : Module(zone, pos), module_(module), name_(name) {}
private:
Module* module_;
- Handle<String> name_;
+ const AstString* name_;
};
@@ -726,7 +728,7 @@ class IterationStatement : public BreakableStatement {
Label* continue_target() { return &continue_target_; }
protected:
- IterationStatement(Zone* zone, ZoneStringList* labels, int pos)
+ IterationStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
: BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
body_(NULL),
osr_entry_id_(GetNextId(zone)) {
@@ -760,7 +762,7 @@ class DoWhileStatement V8_FINAL : public IterationStatement {
BailoutId BackEdgeId() const { return back_edge_id_; }
protected:
- DoWhileStatement(Zone* zone, ZoneStringList* labels, int pos)
+ DoWhileStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
: IterationStatement(zone, labels, pos),
cond_(NULL),
continue_id_(GetNextId(zone)),
@@ -797,7 +799,7 @@ class WhileStatement V8_FINAL : public IterationStatement {
BailoutId BodyId() const { return body_id_; }
protected:
- WhileStatement(Zone* zone, ZoneStringList* labels, int pos)
+ WhileStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
: IterationStatement(zone, labels, pos),
cond_(NULL),
may_have_function_literal_(true),
@@ -848,7 +850,7 @@ class ForStatement V8_FINAL : public IterationStatement {
void set_loop_variable(Variable* var) { loop_variable_ = var; }
protected:
- ForStatement(Zone* zone, ZoneStringList* labels, int pos)
+ ForStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
: IterationStatement(zone, labels, pos),
init_(NULL),
cond_(NULL),
@@ -890,11 +892,8 @@ class ForEachStatement : public IterationStatement {
Expression* subject() const { return subject_; }
protected:
- ForEachStatement(Zone* zone, ZoneStringList* labels, int pos)
- : IterationStatement(zone, labels, pos),
- each_(NULL),
- subject_(NULL) {
- }
+ ForEachStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
+ : IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {}
private:
Expression* each_;
@@ -930,7 +929,7 @@ class ForInStatement V8_FINAL : public ForEachStatement,
virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; }
protected:
- ForInStatement(Zone* zone, ZoneStringList* labels, int pos)
+ ForInStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
: ForEachStatement(zone, labels, pos),
for_in_type_(SLOW_FOR_IN),
for_in_feedback_slot_(kInvalidFeedbackSlot),
@@ -993,7 +992,7 @@ class ForOfStatement V8_FINAL : public ForEachStatement {
BailoutId BackEdgeId() const { return back_edge_id_; }
protected:
- ForOfStatement(Zone* zone, ZoneStringList* labels, int pos)
+ ForOfStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
: ForEachStatement(zone, labels, pos),
assign_iterator_(NULL),
next_result_(NULL),
@@ -1153,7 +1152,7 @@ class SwitchStatement V8_FINAL : public BreakableStatement {
ZoneList<CaseClause*>* cases() const { return cases_; }
protected:
- SwitchStatement(Zone* zone, ZoneStringList* labels, int pos)
+ SwitchStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
: BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
tag_(NULL),
cases_(NULL) { }
@@ -1333,26 +1332,28 @@ class Literal V8_FINAL : public Expression {
DECLARE_NODE_TYPE(Literal)
virtual bool IsPropertyName() const V8_OVERRIDE {
- if (value_->IsInternalizedString()) {
- uint32_t ignored;
- return !String::cast(*value_)->AsArrayIndex(&ignored);
- }
- return false;
+ return value_->IsPropertyName();
}
Handle<String> AsPropertyName() {
ASSERT(IsPropertyName());
- return Handle<String>::cast(value_);
+ return Handle<String>::cast(value());
+ }
+
+ const AstString* AsRawPropertyName() {
+ ASSERT(IsPropertyName());
+ return value_->AsString();
}
virtual bool ToBooleanIsTrue() const V8_OVERRIDE {
- return value_->BooleanValue();
+ return value()->BooleanValue();
}
virtual bool ToBooleanIsFalse() const V8_OVERRIDE {
- return !value_->BooleanValue();
+ return !value()->BooleanValue();
}
- Handle<Object> value() const { return value_; }
+ Handle<Object> value() const { return value_->value(); }
+ const AstValue* raw_value() const { return value_; }
// Support for using Literal as a HashMap key. NOTE: Currently, this works
// only for string and number literals!
@@ -1367,7 +1368,7 @@ class Literal V8_FINAL : public Expression {
TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
protected:
- Literal(Zone* zone, Handle<Object> value, int position)
+ Literal(Zone* zone, const AstValue* value, int position)
: Expression(zone, position),
value_(value),
isolate_(zone->isolate()) { }
@@ -1375,7 +1376,7 @@ class Literal V8_FINAL : public Expression {
private:
Handle<String> ToString();
- Handle<Object> value_;
+ const AstValue* value_;
// TODO(dcarney): remove. this is only needed for Match and Hash.
Isolate* isolate_;
};
@@ -1446,7 +1447,8 @@ class ObjectLiteralProperty V8_FINAL : public ZoneObject {
PROTOTYPE // Property is __proto__.
};
- ObjectLiteralProperty(Zone* zone, Literal* key, Expression* value);
+ ObjectLiteralProperty(Zone* zone, AstStringTable* string_table,
+ Literal* key, Expression* value);
Literal* key() { return key_; }
Expression* value() { return value_; }
@@ -1545,13 +1547,13 @@ class RegExpLiteral V8_FINAL : public MaterializedLiteral {
public:
DECLARE_NODE_TYPE(RegExpLiteral)
- Handle<String> pattern() const { return pattern_; }
- Handle<String> flags() const { return flags_; }
+ Handle<String> pattern() const { return pattern_->string(); }
+ Handle<String> flags() const { return flags_->string(); }
protected:
RegExpLiteral(Zone* zone,
- Handle<String> pattern,
- Handle<String> flags,
+ const AstString* pattern,
+ const AstString* flags,
int literal_index,
int pos)
: MaterializedLiteral(zone, literal_index, pos),
@@ -1561,8 +1563,8 @@ class RegExpLiteral V8_FINAL : public MaterializedLiteral {
}
private:
- Handle<String> pattern_;
- Handle<String> flags_;
+ const AstString* pattern_;
+ const AstString* flags_;
};
@@ -1613,15 +1615,12 @@ class VariableProxy V8_FINAL : public Expression {
return var_ == NULL ? true : var_->IsValidReference();
}
- bool IsVariable(Handle<String> n) const {
- return !is_this() && name().is_identical_to(n);
- }
-
bool IsArguments() const { return var_ != NULL && var_->is_arguments(); }
bool IsLValue() const { return is_lvalue_; }
- Handle<String> name() const { return name_; }
+ Handle<String> name() const { return name_->string(); }
+ const AstString* raw_name() const { return name_; }
Variable* var() const { return var_; }
bool is_this() const { return is_this_; }
Interface* interface() const { return interface_; }
@@ -1637,12 +1636,12 @@ class VariableProxy V8_FINAL : public Expression {
VariableProxy(Zone* zone, Variable* var, int position);
VariableProxy(Zone* zone,
- Handle<String> name,
+ const AstString* name,
bool is_this,
Interface* interface,
int position);
- Handle<String> name_;
+ const AstString* name_;
Variable* var_; // resolved variable, or NULL
bool is_this_;
bool is_trivial_;
@@ -1888,7 +1887,8 @@ class CallRuntime V8_FINAL : public Expression {
public:
DECLARE_NODE_TYPE(CallRuntime)
- Handle<String> name() const { return name_; }
+ Handle<String> name() const { return raw_name_->string(); }
+ const AstString* raw_name() const { return raw_name_; }
const Runtime::Function* function() const { return function_; }
ZoneList<Expression*>* arguments() const { return arguments_; }
bool is_jsruntime() const { return function_ == NULL; }
@@ -1897,17 +1897,17 @@ class CallRuntime V8_FINAL : public Expression {
protected:
CallRuntime(Zone* zone,
- Handle<String> name,
+ const AstString* name,
const Runtime::Function* function,
ZoneList<Expression*>* arguments,
int pos)
: Expression(zone, pos),
- name_(name),
+ raw_name_(name),
function_(function),
arguments_(arguments) { }
private:
- Handle<String> name_;
+ const AstString* raw_name_;
const Runtime::Function* function_;
ZoneList<Expression*>* arguments_;
};
@@ -2295,7 +2295,8 @@ class FunctionLiteral V8_FINAL : public Expression {
DECLARE_NODE_TYPE(FunctionLiteral)
- Handle<String> name() const { return name_; }
+ Handle<String> name() const { return raw_name_->string(); }
+ const AstString* raw_name() const { return raw_name_; }
Scope* scope() const { return scope_; }
ZoneList<Statement*>* body() const { return body_; }
void set_function_token_position(int pos) { function_token_position_ = pos; }
@@ -2318,13 +2319,32 @@ class FunctionLiteral V8_FINAL : public Expression {
void InitializeSharedInfo(Handle<Code> code);
Handle<String> debug_name() const {
- if (name_->length() > 0) return name_;
+ if (raw_name_ != NULL && raw_name_->length() > 0) {
+ return raw_name_->string();
+ }
return inferred_name();
}
- Handle<String> inferred_name() const { return inferred_name_; }
+ Handle<String> inferred_name() const {
+ if (!inferred_name_.is_null()) {
+ ASSERT(raw_inferred_name_ == NULL);
+ return inferred_name_;
+ }
+ if (raw_inferred_name_ != NULL) {
+ return raw_inferred_name_->string();
+ }
+ UNREACHABLE();
+ return Handle<String>();
+ }
+
void set_inferred_name(Handle<String> inferred_name) {
inferred_name_ = inferred_name;
+ raw_inferred_name_ = NULL;
+ }
+
+ void set_raw_inferred_name(const AstString* raw_inferred_name) {
+ raw_inferred_name_ = raw_inferred_name;
+ inferred_name_ = Handle<String>();
}
// shared_info may be null if it's not cached in full code.
@@ -2371,7 +2391,8 @@ class FunctionLiteral V8_FINAL : public Expression {
protected:
FunctionLiteral(Zone* zone,
- Handle<String> name,
+ const AstString* name,
+ AstStringTable* string_table,
Scope* scope,
ZoneList<Statement*>* body,
int materialized_literal_count,
@@ -2385,10 +2406,10 @@ class FunctionLiteral V8_FINAL : public Expression {
IsGeneratorFlag is_generator,
int position)
: Expression(zone, position),
- name_(name),
+ raw_name_(name),
scope_(scope),
body_(body),
- inferred_name_(zone->isolate()->factory()->empty_string()),
+ raw_inferred_name_(string_table->empty_string()),
dont_optimize_reason_(kNoReason),
materialized_literal_count_(materialized_literal_count),
expected_property_count_(expected_property_count),
@@ -2406,10 +2427,12 @@ class FunctionLiteral V8_FINAL : public Expression {
}
private:
+ const AstString* raw_name_;
Handle<String> name_;
Handle<SharedFunctionInfo> shared_info_;
Scope* scope_;
ZoneList<Statement*>* body_;
+ const AstString* raw_inferred_name_;
Handle<String> inferred_name_;
AstProperties ast_properties_;
BailoutReason dont_optimize_reason_;
@@ -2435,16 +2458,16 @@ class NativeFunctionLiteral V8_FINAL : public Expression {
public:
DECLARE_NODE_TYPE(NativeFunctionLiteral)
- Handle<String> name() const { return name_; }
+ Handle<String> name() const { return name_->string(); }
v8::Extension* extension() const { return extension_; }
protected:
- NativeFunctionLiteral(
- Zone* zone, Handle<String> name, v8::Extension* extension, int pos)
+ NativeFunctionLiteral(Zone* zone, const AstString* name,
+ v8::Extension* extension, int pos)
: Expression(zone, pos), name_(name), extension_(extension) {}
private:
- Handle<String> name_;
+ const AstString* name_;
v8::Extension* extension_;
};
@@ -2936,7 +2959,8 @@ class AstNullVisitor BASE_EMBEDDED {
template<class Visitor>
class AstNodeFactory V8_FINAL BASE_EMBEDDED {
public:
- explicit AstNodeFactory(Zone* zone) : zone_(zone) { }
+ explicit AstNodeFactory(Zone* zone, AstStringTable* string_table)
+ : zone_(zone), string_table_(string_table) {}
Visitor* visitor() { return &visitor_; }
@@ -3000,8 +3024,9 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
VISIT_AND_RETURN(ModuleVariable, module)
}
- ModulePath* NewModulePath(Module* origin, Handle<String> name, int pos) {
- ModulePath* module = new(zone_) ModulePath(zone_, origin, name, pos);
+ ModulePath* NewModulePath(Module* origin,
+ const AstString* name, int pos) {
+ ModulePath* module = new (zone_) ModulePath(zone_, origin, name, pos);
VISIT_AND_RETURN(ModulePath, module)
}
@@ -3010,7 +3035,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
VISIT_AND_RETURN(ModuleUrl, module)
}
- Block* NewBlock(ZoneStringList* labels,
+ Block* NewBlock(ZoneList<const AstString*>* labels,
int capacity,
bool is_initializer_block,
int pos) {
@@ -3020,7 +3045,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
}
#define STATEMENT_WITH_LABELS(NodeType) \
- NodeType* New##NodeType(ZoneStringList* labels, int pos) { \
+ NodeType* New##NodeType(ZoneList<const AstString*>* labels, int pos) { \
NodeType* stmt = new(zone_) NodeType(zone_, labels, pos); \
VISIT_AND_RETURN(NodeType, stmt); \
}
@@ -3031,7 +3056,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
#undef STATEMENT_WITH_LABELS
ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
- ZoneStringList* labels,
+ ZoneList<const AstString*>* labels,
int pos) {
switch (visit_mode) {
case ForEachStatement::ENUMERATE: {
@@ -3128,14 +3153,40 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
VISIT_AND_RETURN(CaseClause, clause)
}
- Literal* NewLiteral(Handle<Object> handle, int pos) {
- Literal* lit = new(zone_) Literal(zone_, handle, pos);
+ Literal* NewLiteral(const AstString* string, int pos) {
+ Literal* lit =
+ new (zone_) Literal(zone_, string_table_->NewValue(string), pos);
VISIT_AND_RETURN(Literal, lit)
}
Literal* NewNumberLiteral(double number, int pos) {
- return NewLiteral(
- zone_->isolate()->factory()->NewNumber(number, TENURED), pos);
+ Literal* lit = new (zone_)
+ Literal(zone_, string_table_->NewNumberValue(number), pos);
+ VISIT_AND_RETURN(Literal, lit)
+ }
+
+ Literal* NewSmiLiteral(int number, int pos) {
+ Literal* lit =
+ new (zone_) Literal(zone_, string_table_->NewSmiValue(number), pos);
+ VISIT_AND_RETURN(Literal, lit)
+ }
+
+ Literal* NewLiteral(bool b, int pos) {
+ Literal* lit =
+ new (zone_) Literal(zone_, string_table_->NewValue(b), pos);
+ VISIT_AND_RETURN(Literal, lit)
+ }
+
+ Literal* NewLiteral(ZoneList<const AstString*>* strings,
+ int pos) {
+ Literal* lit = new (zone_)
+ Literal(zone_, string_table_->NewValue(strings), pos);
+ VISIT_AND_RETURN(Literal, lit)
+ }
+
+ Literal* NewLiteral(const AstValue* literal, int pos) {
+ Literal* lit = new (zone_) Literal(zone_, literal, pos);
+ VISIT_AND_RETURN(Literal, lit)
}
ObjectLiteral* NewObjectLiteral(
@@ -3152,7 +3203,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key,
Expression* value) {
- return new(zone_) ObjectLiteral::Property(zone_, key, value);
+ return new(zone_) ObjectLiteral::Property(zone_, string_table_, key, value);
}
ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter,
@@ -3160,12 +3211,12 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
int pos) {
ObjectLiteral::Property* prop =
new(zone_) ObjectLiteral::Property(zone_, is_getter, value);
- prop->set_key(NewLiteral(value->name(), pos));
+ prop->set_key(NewLiteral(value->raw_name(), pos));
return prop; // Not an AST node, will not be visited.
}
- RegExpLiteral* NewRegExpLiteral(Handle<String> pattern,
- Handle<String> flags,
+ RegExpLiteral* NewRegExpLiteral(const AstString* pattern,
+ const AstString* flags,
int literal_index,
int pos) {
RegExpLiteral* lit =
@@ -3187,7 +3238,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
VISIT_AND_RETURN(VariableProxy, proxy)
}
- VariableProxy* NewVariableProxy(Handle<String> name,
+ VariableProxy* NewVariableProxy(const AstString* name,
bool is_this,
Interface* interface = Interface::NewValue(),
int position = RelocInfo::kNoPosition) {
@@ -3215,7 +3266,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
VISIT_AND_RETURN(CallNew, call)
}
- CallRuntime* NewCallRuntime(Handle<String> name,
+ CallRuntime* NewCallRuntime(const AstString* name,
const Runtime::Function* function,
ZoneList<Expression*>* arguments,
int pos) {
@@ -3293,7 +3344,8 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
}
FunctionLiteral* NewFunctionLiteral(
- Handle<String> name,
+ const AstString* name,
+ AstStringTable* string_table,
Scope* scope,
ZoneList<Statement*>* body,
int materialized_literal_count,
@@ -3307,7 +3359,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
FunctionLiteral::IsGeneratorFlag is_generator,
int position) {
FunctionLiteral* lit = new(zone_) FunctionLiteral(
- zone_, name, scope, body,
+ zone_, name, string_table, scope, body,
materialized_literal_count, expected_property_count, handler_count,
parameter_count, function_type, has_duplicate_parameters, is_function,
is_parenthesized, is_generator, position);
@@ -3319,7 +3371,8 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
}
NativeFunctionLiteral* NewNativeFunctionLiteral(
- Handle<String> name, v8::Extension* extension, int pos) {
+ const AstString* name, v8::Extension* extension,
+ int pos) {
NativeFunctionLiteral* lit =
new(zone_) NativeFunctionLiteral(zone_, name, extension, pos);
VISIT_AND_RETURN(NativeFunctionLiteral, lit)
@@ -3335,6 +3388,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
private:
Zone* zone_;
Visitor visitor_;
+ AstStringTable* string_table_;
};
« no previous file with comments | « include/v8.h ('k') | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698