Move the Location class into the AST Expression class as a member.

Since it is (currently) only an enum, change it to an enum (for now).

Review URL: http://codereview.chromium.org/342035

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3181 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 143b4b87
This diff is collapsed.
......@@ -28,7 +28,6 @@
#ifndef V8_AST_H_
#define V8_AST_H_
#include "location.h"
#include "execution.h"
#include "factory.h"
#include "jsregexp.h"
......@@ -162,7 +161,13 @@ class Statement: public AstNode {
class Expression: public AstNode {
public:
Expression() : location_(Location::Uninitialized()) {}
enum Context {
kUninitialized,
kEffect,
kValue
};
Expression() : context_(kUninitialized) {}
virtual Expression* AsExpression() { return this; }
......@@ -177,12 +182,12 @@ class Expression: public AstNode {
// Static type information for this expression.
SmiAnalysis* type() { return &type_; }
Location location() { return location_; }
void set_location(Location loc) { location_ = loc; }
Context context() { return context_; }
void set_context(Context context) { context_ = context; }
private:
SmiAnalysis type_;
Location location_;
Context context_;
};
......
......@@ -48,23 +48,24 @@ class CodeGenSelector: public AstVisitor {
CodeGenSelector()
: has_supported_syntax_(true),
location_(Location::Uninitialized()) {
context_(Expression::kUninitialized) {
}
CodeGenTag Select(FunctionLiteral* fun);
private:
// Visit an expression in a given expression context.
void ProcessExpression(Expression* expr, Expression::Context context) {
Expression::Context saved = context_;
context_ = context;
Visit(expr);
expr->set_context(context);
context_ = saved;
}
void VisitDeclarations(ZoneList<Declaration*>* decls);
void VisitStatements(ZoneList<Statement*>* stmts);
// Visit an expression in effect context with a desired location of
// nowhere.
void VisitAsEffect(Expression* expr);
// Visit an expression in value context with a desired location of
// temporary.
void VisitAsValue(Expression* expr);
// AST node visit functions.
#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT)
......@@ -72,8 +73,8 @@ class CodeGenSelector: public AstVisitor {
bool has_supported_syntax_;
// The desired location of the currently visited expression.
Location location_;
// The desired expression context of the currently visited expression.
Expression::Context context_;
DISALLOW_COPY_AND_ASSIGN(CodeGenSelector);
};
......@@ -513,30 +514,6 @@ void CodeGenSelector::VisitStatements(ZoneList<Statement*>* stmts) {
}
void CodeGenSelector::VisitAsEffect(Expression* expr) {
if (location_.is_effect()) {
Visit(expr);
} else {
Location saved = location_;
location_ = Location::Effect();
Visit(expr);
location_ = saved;
}
}
void CodeGenSelector::VisitAsValue(Expression* expr) {
if (location_.is_value()) {
Visit(expr);
} else {
Location saved = location_;
location_ = Location::Value();
Visit(expr);
location_ = saved;
}
}
void CodeGenSelector::VisitDeclaration(Declaration* decl) {
Variable* var = decl->proxy()->var();
if (!var->is_global() || var->mode() == Variable::CONST) {
......@@ -551,7 +528,7 @@ void CodeGenSelector::VisitBlock(Block* stmt) {
void CodeGenSelector::VisitExpressionStatement(ExpressionStatement* stmt) {
VisitAsEffect(stmt->expression());
ProcessExpression(stmt->expression(), Expression::kEffect);
}
......@@ -576,7 +553,7 @@ void CodeGenSelector::VisitBreakStatement(BreakStatement* stmt) {
void CodeGenSelector::VisitReturnStatement(ReturnStatement* stmt) {
VisitAsValue(stmt->expression());
ProcessExpression(stmt->expression(), Expression::kValue);
}
......@@ -634,7 +611,6 @@ void CodeGenSelector::VisitFunctionLiteral(FunctionLiteral* expr) {
if (!expr->AllowsLazyCompilation()) {
BAILOUT("FunctionLiteral does not allow lazy compilation");
}
expr->set_location(location_);
}
......@@ -671,17 +647,16 @@ void CodeGenSelector::VisitVariableProxy(VariableProxy* expr) {
BAILOUT("non-parameter/non-local slot reference");
}
}
expr->set_location(location_);
}
void CodeGenSelector::VisitLiteral(Literal* expr) {
expr->set_location(location_);
/* Nothing to do. */
}
void CodeGenSelector::VisitRegExpLiteral(RegExpLiteral* expr) {
expr->set_location(location_);
/* Nothing to do. */
}
......@@ -711,14 +686,13 @@ void CodeGenSelector::VisitObjectLiteral(ObjectLiteral* expr) {
case ObjectLiteral::Property::GETTER: // Fall through.
case ObjectLiteral::Property::SETTER: // Fall through.
case ObjectLiteral::Property::PROTOTYPE:
VisitAsValue(property->key());
ProcessExpression(property->key(), Expression::kValue);
CHECK_BAILOUT;
break;
}
VisitAsValue(property->value());
ProcessExpression(property->value(), Expression::kValue);
CHECK_BAILOUT;
}
expr->set_location(location_);
}
......@@ -728,10 +702,9 @@ void CodeGenSelector::VisitArrayLiteral(ArrayLiteral* expr) {
Expression* subexpr = subexprs->at(i);
if (subexpr->AsLiteral() != NULL) continue;
if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
VisitAsValue(subexpr);
ProcessExpression(subexpr, Expression::kValue);
CHECK_BAILOUT;
}
expr->set_location(location_);
}
......@@ -758,9 +731,9 @@ void CodeGenSelector::VisitAssignment(Assignment* expr) {
if (var == NULL) {
Property* prop = expr->target()->AsProperty();
if (prop == NULL) BAILOUT("non-variable, non-property assignment");
VisitAsValue(prop->obj());
ProcessExpression(prop->obj(), Expression::kValue);
CHECK_BAILOUT;
VisitAsValue(prop->key());
ProcessExpression(prop->key(), Expression::kValue);
} else if (!var->is_global()) {
if (var->slot() == NULL) BAILOUT("Assigment with an unsupported LHS.");
Slot::Type type = var->slot()->type();
......@@ -769,8 +742,7 @@ void CodeGenSelector::VisitAssignment(Assignment* expr) {
}
}
VisitAsValue(expr->value());
expr->set_location(location_);
ProcessExpression(expr->value(), Expression::kValue);
}
......@@ -780,10 +752,9 @@ void CodeGenSelector::VisitThrow(Throw* expr) {
void CodeGenSelector::VisitProperty(Property* expr) {
VisitAsValue(expr->obj());
ProcessExpression(expr->obj(), Expression::kValue);
CHECK_BAILOUT;
VisitAsValue(expr->key());
expr->set_location(location_);
ProcessExpression(expr->key(), Expression::kValue);
}
......@@ -804,23 +775,21 @@ void CodeGenSelector::VisitCall(Call* expr) {
}
// Check all arguments to the call. (Relies on TEMP meaning STACK.)
for (int i = 0; i < args->length(); i++) {
VisitAsValue(args->at(i));
ProcessExpression(args->at(i), Expression::kValue);
CHECK_BAILOUT;
}
expr->set_location(location_);
}
void CodeGenSelector::VisitCallNew(CallNew* expr) {
VisitAsValue(expr->expression());
ProcessExpression(expr->expression(), Expression::kValue);
CHECK_BAILOUT;
ZoneList<Expression*>* args = expr->arguments();
// Check all arguments to the call
for (int i = 0; i < args->length(); i++) {
VisitAsValue(args->at(i));
ProcessExpression(args->at(i), Expression::kValue);
CHECK_BAILOUT;
}
expr->set_location(location_);
}
......@@ -834,10 +803,9 @@ void CodeGenSelector::VisitCallRuntime(CallRuntime* expr) {
}
// Check all arguments to the call. (Relies on TEMP meaning STACK.)
for (int i = 0; i < expr->arguments()->length(); i++) {
VisitAsValue(expr->arguments()->at(i));
ProcessExpression(expr->arguments()->at(i), Expression::kValue);
CHECK_BAILOUT;
}
expr->set_location(location_);
}
......@@ -854,17 +822,15 @@ void CodeGenSelector::VisitCountOperation(CountOperation* expr) {
void CodeGenSelector::VisitBinaryOperation(BinaryOperation* expr) {
switch (expr->op()) {
case Token::COMMA:
VisitAsEffect(expr->left());
ProcessExpression(expr->left(), Expression::kEffect);
CHECK_BAILOUT;
Visit(expr->right()); // Location is the same as the parent location.
ProcessExpression(expr->right(), context_);
break;
case Token::OR:
VisitAsValue(expr->left());
ProcessExpression(expr->left(), Expression::kValue);
CHECK_BAILOUT;
// The location for the right subexpression is the same as for the
// whole expression so we call Visit directly.
Visit(expr->right());
ProcessExpression(expr->right(), context_);
break;
case Token::ADD:
......@@ -878,15 +844,14 @@ void CodeGenSelector::VisitBinaryOperation(BinaryOperation* expr) {
case Token::SHL:
case Token::SHR:
case Token::SAR:
VisitAsValue(expr->left());
ProcessExpression(expr->left(), Expression::kValue);
CHECK_BAILOUT;
VisitAsValue(expr->right());
ProcessExpression(expr->right(), Expression::kValue);
break;
default:
BAILOUT("Unsupported binary operation");
}
expr->set_location(location_);
}
......
......@@ -73,32 +73,19 @@ int FastCodeGenerator::SlotOffset(Slot* slot) {
// All platform macro assemblers in {ia32,x64,arm} have a push(Register)
// function.
void FastCodeGenerator::Move(Location destination, Register source) {
switch (destination.type()) {
case Location::kUninitialized:
void FastCodeGenerator::Move(Expression::Context context, Register source) {
switch (context) {
case Expression::kUninitialized:
UNREACHABLE();
case Location::kEffect:
case Expression::kEffect:
break;
case Location::kValue:
case Expression::kValue:
masm_->push(source);
break;
}
}
// All platform macro assemblers in {ia32,x64,arm} have a pop(Register)
// function.
void FastCodeGenerator::Move(Register destination, Location source) {
switch (source.type()) {
case Location::kUninitialized: // Fall through.
case Location::kEffect:
UNREACHABLE();
case Location::kValue:
masm_->pop(destination);
}
}
void FastCodeGenerator::VisitDeclarations(
ZoneList<Declaration*>* declarations) {
int length = declarations->length();
......@@ -323,7 +310,7 @@ void FastCodeGenerator::VisitSlot(Slot* expr) {
void FastCodeGenerator::VisitLiteral(Literal* expr) {
Move(expr->location(), expr);
Move(expr->context(), expr);
}
......
......@@ -51,16 +51,13 @@ class FastCodeGenerator: public AstVisitor {
private:
int SlotOffset(Slot* slot);
void Move(Location destination, Register source);
void Move(Location destination, Slot* source);
void Move(Location destination, Literal* source);
void Move(Register destination, Location source);
void Move(Slot* destination, Location source);
void Move(Expression::Context destination, Register source);
void Move(Expression::Context destination, Slot* source);
void Move(Expression::Context destination, Literal* source);
// Drop the TOS, and store source to destination.
// If destination is TOS, just overwrite TOS with source.
void DropAndMove(Location destination, Register source);
void DropAndMove(Expression::Context destination, Register source);
void VisitDeclarations(ZoneList<Declaration*>* declarations);
Handle<JSFunction> BuildBoilerplate(FunctionLiteral* fun);
......
This diff is collapsed.
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_LOCATION_H_
#define V8_LOCATION_H_
#include "utils.h"
namespace v8 {
namespace internal {
class Location BASE_EMBEDDED {
public:
enum Type {
kUninitialized,
kEffect,
kValue
};
static Location Uninitialized() { return Location(kUninitialized); }
static Location Effect() { return Location(kEffect); }
static Location Value() { return Location(kValue); }
bool is_effect() { return type_ == kEffect; }
bool is_value() { return type_ == kValue; }
Type type() { return type_; }
private:
explicit Location(Type type) : type_(type) {}
Type type_;
};
} } // namespace v8::internal
#endif // V8_LOCATION_H_
This diff is collapsed.
......@@ -293,7 +293,6 @@
'../../src/jsregexp.h',
'../../src/list-inl.h',
'../../src/list.h',
'../../src/location.h',
'../../src/log-inl.h',
'../../src/log-utils.cc',
'../../src/log-utils.h',
......
......@@ -556,10 +556,6 @@
RelativePath="..\..\src\list.h"
>
</File>
<File
RelativePath="..\..\src\location.h"
>
</File>
<File
RelativePath="..\..\src\log.cc"
>
......
......@@ -560,10 +560,6 @@
RelativePath="..\..\src\list.h"
>
</File>
<File
RelativePath="..\..\src\location.h"
>
</File>
<File
RelativePath="..\..\src\log.cc"
>
......
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