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