VariableProxy::VariableProxy(Zone* zone, Variable* var, int position,
IdGen* id_gen)
: Expression(zone, position, id_gen),
- name_(var->raw_name()),
- var_(NULL), // Will be set by the call to BindTo.
+ raw_name_(var->raw_name()),
+ interface_(var->interface()),
+ variable_feedback_slot_(kInvalidFeedbackSlot),
is_this_(var->is_this()),
is_assigned_(false),
- interface_(var->interface()),
- variable_feedback_slot_(kInvalidFeedbackSlot) {
+ is_resolved_(false) {
BindTo(var);
}
VariableProxy::VariableProxy(Zone* zone, const AstRawString* name, bool is_this,
Interface* interface, int position, IdGen* id_gen)
: Expression(zone, position, id_gen),
- name_(name),
- var_(NULL),
+ raw_name_(name),
+ interface_(interface),
+ variable_feedback_slot_(kInvalidFeedbackSlot),
is_this_(is_this),
is_assigned_(false),
- interface_(interface),
- variable_feedback_slot_(kInvalidFeedbackSlot) {}
+ is_resolved_(false) {}
void VariableProxy::BindTo(Variable* var) {
- DCHECK(var_ == NULL); // must be bound only once
- DCHECK(var != NULL); // must bind
DCHECK(!FLAG_harmony_modules || interface_->IsUnified(var->interface()));
- DCHECK((is_this() && var->is_this()) || name_ == var->raw_name());
+ DCHECK((is_this() && var->is_this()) || raw_name() == var->raw_name());
// Ideally CONST-ness should match. However, this is very hard to achieve
// because we don't know the exact semantics of conflicting (const and
// non-const) multiple variable declarations, const vars introduced via
// eval() etc. Const-ness and variable declarations are a complete mess
// in JS. Sigh...
- var_ = var;
+ set_var(var);
+ set_is_resolved();
var->set_is_used();
}
DECLARE_NODE_TYPE(VariableProxy)
virtual bool IsValidReferenceExpression() const OVERRIDE {
- return var_ == NULL ? true : var_->IsValidReference();
+ return !is_resolved() || var()->IsValidReference();
}
- bool IsArguments() const { return var_ != NULL && var_->is_arguments(); }
+ bool IsArguments() const { return is_resolved() && var()->is_arguments(); }
+
+ Handle<String> name() const { return raw_name()->string(); }
+ const AstRawString* raw_name() const {
+ return is_resolved() ? var_->raw_name() : raw_name_;
+ }
+
+ Variable* var() const {
+ DCHECK(is_resolved());
+ return var_;
+ }
+ void set_var(Variable* v) {
+ DCHECK(!is_resolved());
+ DCHECK_NOT_NULL(v);
+ var_ = v;
+ }
- Handle<String> name() const { return name_->string(); }
- const AstRawString* raw_name() const { return name_; }
- Variable* var() const { return var_; }
bool is_this() const { return is_this_; }
- Interface* interface() const { return interface_; }
bool is_assigned() const { return is_assigned_; }
void set_is_assigned() { is_assigned_ = true; }
+ bool is_resolved() const { return is_resolved_; }
+ void set_is_resolved() { is_resolved_ = true; }
+
+ Interface* interface() const { return interface_; }
+
// Bind this proxy to the variable var. Interfaces must match.
void BindTo(Variable* var);
VariableProxy(Zone* zone, const AstRawString* name, bool is_this,
Interface* interface, int position, IdGen* id_gen);
- const AstRawString* name_;
- Variable* var_; // resolved variable, or NULL
- bool is_this_;
- bool is_assigned_;
+ union {
+ const AstRawString* raw_name_; // if !is_resolved_
+ Variable* var_; // if is_resolved_
+ };
Interface* interface_;
int variable_feedback_slot_;
+ bool is_this_ : 1;
+ bool is_assigned_ : 1;
+ bool is_resolved_ : 1;
};
}
// Record the end position of the initializer.
- if (proxy->var() != NULL) {
+ if (proxy->is_resolved()) {
proxy->var()->set_initializer_position(position());
}
// the end position of the function generated for executing the eval code
// coincides with the end of the with scope which is the position of '1'.
int pos = function->end_position();
- VariableProxy* result_proxy = processor.factory()->NewVariableProxy(
- result->raw_name(), false, result->interface(), pos);
- result_proxy->BindTo(result);
+ VariableProxy* result_proxy =
+ processor.factory()->NewVariableProxy(result, pos);
Statement* result_statement =
processor.factory()->NewReturnStatement(result_proxy, pos);
body->Add(result_statement, info->zone());
// If the proxy is already resolved there's nothing to do
// (functions and consts may be resolved by the parser).
- if (proxy->var() != NULL) return true;
+ if (proxy->is_resolved()) return true;
// Otherwise, try to resolve the variable.
BindingKind binding_kind;