Change the overly-general class named Node to the more specific

AstNode in case we ever want to have some other kind of node.

Split the NODE_LIST macro-generating macro so that we can iterate
concrete subclasses of Statement and concrete subclasses of Expression
separately.
Review URL: http://codereview.chromium.org/159632

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2586 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dc8ca169
......@@ -374,7 +374,7 @@ class CodeGenerator: public AstVisitor {
// information.
void CodeForFunctionPosition(FunctionLiteral* fun);
void CodeForReturnPosition(FunctionLiteral* fun);
void CodeForStatementPosition(Node* node);
void CodeForStatementPosition(AstNode* node);
void CodeForSourcePosition(int pos);
#ifdef DEBUG
......
......@@ -53,9 +53,8 @@ namespace internal {
// Nodes of the abstract syntax tree. Only concrete classes are
// enumerated here.
#define NODE_LIST(V) \
#define STATEMENT_NODE_LIST(V) \
V(Block) \
V(Declaration) \
V(ExpressionStatement) \
V(EmptyStatement) \
V(IfStatement) \
......@@ -69,7 +68,9 @@ namespace internal {
V(ForInStatement) \
V(TryCatch) \
V(TryFinally) \
V(DebuggerStatement) \
V(DebuggerStatement)
#define EXPRESSION_NODE_LIST(V) \
V(FunctionLiteral) \
V(FunctionBoilerplateLiteral) \
V(Conditional) \
......@@ -93,6 +94,10 @@ namespace internal {
V(CompareOperation) \
V(ThisFunction)
#define AST_NODE_LIST(V) \
V(Declaration) \
STATEMENT_NODE_LIST(V) \
EXPRESSION_NODE_LIST(V)
// Forward declarations
class TargetCollector;
......@@ -108,10 +113,10 @@ NODE_LIST(DEF_FORWARD_DECLARATION)
typedef ZoneList<Handle<String> > ZoneStringList;
class Node: public ZoneObject {
class AstNode: public ZoneObject {
public:
Node(): statement_pos_(RelocInfo::kNoPosition) { }
virtual ~Node() { }
AstNode(): statement_pos_(RelocInfo::kNoPosition) { }
virtual ~AstNode() { }
virtual void Accept(AstVisitor* v) = 0;
// Type testing & conversion.
......@@ -143,7 +148,7 @@ class Node: public ZoneObject {
};
class Statement: public Node {
class Statement: public AstNode {
public:
virtual Statement* AsStatement() { return this; }
virtual ReturnStatement* AsReturnStatement() { return NULL; }
......@@ -152,7 +157,7 @@ class Statement: public Node {
};
class Expression: public Node {
class Expression: public AstNode {
public:
virtual Expression* AsExpression() { return this; }
......@@ -240,7 +245,7 @@ class Block: public BreakableStatement {
};
class Declaration: public Node {
class Declaration: public AstNode {
public:
Declaration(VariableProxy* proxy, Variable::Mode mode, FunctionLiteral* fun)
: proxy_(proxy),
......@@ -523,7 +528,7 @@ class IfStatement: public Statement {
// NOTE: TargetCollectors are represented as nodes to fit in the target
// stack in the compiler; this should probably be reworked.
class TargetCollector: public Node {
class TargetCollector: public AstNode {
public:
explicit TargetCollector(ZoneList<BreakTarget*>* targets)
: targets_(targets) {
......@@ -1678,7 +1683,7 @@ class AstVisitor BASE_EMBEDDED {
virtual ~AstVisitor() { }
// Dispatch
void Visit(Node* node) { node->Accept(this); }
void Visit(AstNode* node) { node->Accept(this); }
// Iteration
virtual void VisitStatements(ZoneList<Statement*>* statements);
......
......@@ -496,7 +496,7 @@ void CodeGenerator::CodeForReturnPosition(FunctionLiteral* fun) {
}
void CodeGenerator::CodeForStatementPosition(Node* node) {
void CodeGenerator::CodeForStatementPosition(AstNode* node) {
if (FLAG_debug_info) {
int pos = node->statement_pos();
if (pos != RelocInfo::kNoPosition) {
......
......@@ -558,7 +558,7 @@ class CodeGenerator: public AstVisitor {
// information.
void CodeForFunctionPosition(FunctionLiteral* fun);
void CodeForReturnPosition(FunctionLiteral* fun);
void CodeForStatementPosition(Node* node);
void CodeForStatementPosition(AstNode* node);
void CodeForSourcePosition(int pos);
#ifdef DEBUG
......
......@@ -1059,7 +1059,7 @@ VariableProxy* PreParser::Declare(Handle<String> name, Variable::Mode mode,
class Target BASE_EMBEDDED {
public:
Target(Parser* parser, Node* node)
Target(Parser* parser, AstNode* node)
: parser_(parser), node_(node), previous_(parser_->target_stack_) {
parser_->target_stack_ = this;
}
......@@ -1069,11 +1069,11 @@ class Target BASE_EMBEDDED {
}
Target* previous() { return previous_; }
Node* node() { return node_; }
AstNode* node() { return node_; }
private:
Parser* parser_;
Node* node_;
AstNode* node_;
Target* previous_;
};
......
......@@ -417,7 +417,7 @@ void PrettyPrinter::VisitThisFunction(ThisFunction* node) {
}
const char* PrettyPrinter::Print(Node* node) {
const char* PrettyPrinter::Print(AstNode* node) {
Init();
Visit(node);
return output_;
......@@ -441,7 +441,7 @@ const char* PrettyPrinter::PrintProgram(FunctionLiteral* program) {
}
void PrettyPrinter::PrintOut(Node* node) {
void PrettyPrinter::PrintOut(AstNode* node) {
PrettyPrinter printer;
PrintF("%s", printer.Print(node));
}
......@@ -700,7 +700,7 @@ void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) {
}
void AstPrinter::PrintIndentedVisit(const char* s, Node* node) {
void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) {
IndentedScope indent(s);
Visit(node);
}
......
......@@ -42,12 +42,12 @@ class PrettyPrinter: public AstVisitor {
// The following routines print a node into a string.
// The result string is alive as long as the PrettyPrinter is alive.
const char* Print(Node* node);
const char* Print(AstNode* node);
const char* PrintExpression(FunctionLiteral* program);
const char* PrintProgram(FunctionLiteral* program);
// Print a node to stdout.
static void PrintOut(Node* node);
static void PrintOut(AstNode* node);
// Individual nodes
#define DEF_VISIT(type) \
......@@ -92,7 +92,7 @@ class AstPrinter: public PrettyPrinter {
private:
friend class IndentedScope;
void PrintIndented(const char* txt);
void PrintIndentedVisit(const char* s, Node* node);
void PrintIndentedVisit(const char* s, AstNode* node);
void PrintStatements(ZoneList<Statement*>* statements);
void PrintDeclarations(ZoneList<Declaration*>* declarations);
......
......@@ -42,7 +42,7 @@ static const int InitialWeight = 100;
class UsageComputer: public AstVisitor {
public:
static bool Traverse(Node* node);
static bool Traverse(AstNode* node);
void VisitBlock(Block* node);
void VisitDeclaration(Declaration* node);
......@@ -116,7 +116,7 @@ class WeightScaler BASE_EMBEDDED {
// ----------------------------------------------------------------------------
// Implementation of UsageComputer
bool UsageComputer::Traverse(Node* node) {
bool UsageComputer::Traverse(AstNode* node) {
UsageComputer uc(InitialWeight, false);
uc.Visit(node);
return !uc.HasStackOverflow();
......
......@@ -361,7 +361,7 @@ class CodeGenerator: public AstVisitor {
#define DEF_VISIT(type) \
void Visit##type(type* node);
NODE_LIST(DEF_VISIT)
AST_NODE_LIST(DEF_VISIT)
#undef DEF_VISIT
// Visit a statement and then spill the virtual frame if control flow can
......@@ -548,7 +548,7 @@ class CodeGenerator: public AstVisitor {
// information.
void CodeForFunctionPosition(FunctionLiteral* fun);
void CodeForReturnPosition(FunctionLiteral* fun);
void CodeForStatementPosition(Node* node);
void CodeForStatementPosition(AstNode* node);
void CodeForSourcePosition(int pos);
#ifdef DEBUG
......
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