From a48fd5916e3aed9a705c59e12f19a81795d2b731 Mon Sep 17 00:00:00 2001 From: "kmillikin@chromium.org" Date: Thu, 30 Jul 2009 11:53:29 +0000 Subject: [PATCH] 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 --- src/arm/codegen-arm.h | 2 +- src/ast.h | 27 ++++++++++++++++----------- src/codegen.cc | 2 +- src/ia32/codegen-ia32.h | 2 +- src/parser.cc | 6 +++--- src/prettyprinter.cc | 6 +++--- src/prettyprinter.h | 6 +++--- src/usage-analyzer.cc | 4 ++-- src/x64/codegen-x64.h | 4 ++-- 9 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/arm/codegen-arm.h b/src/arm/codegen-arm.h index 6391a8e..641efd3 100644 --- a/src/arm/codegen-arm.h +++ b/src/arm/codegen-arm.h @@ -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 diff --git a/src/ast.h b/src/ast.h index 64d61cc..d2f843b 100644 --- a/src/ast.h +++ b/src/ast.h @@ -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 > 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* 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* statements); diff --git a/src/codegen.cc b/src/codegen.cc index b7297d7..7a4bb12 100644 --- a/src/codegen.cc +++ b/src/codegen.cc @@ -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) { diff --git a/src/ia32/codegen-ia32.h b/src/ia32/codegen-ia32.h index 5cd50b8..8dbff22 100644 --- a/src/ia32/codegen-ia32.h +++ b/src/ia32/codegen-ia32.h @@ -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 diff --git a/src/parser.cc b/src/parser.cc index da2b286..348c12a 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -1059,7 +1059,7 @@ VariableProxy* PreParser::Declare(Handle 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_; }; diff --git a/src/prettyprinter.cc b/src/prettyprinter.cc index 30a0602..7a8af40 100644 --- a/src/prettyprinter.cc +++ b/src/prettyprinter.cc @@ -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); } diff --git a/src/prettyprinter.h b/src/prettyprinter.h index bfce9b0..1457daa 100644 --- a/src/prettyprinter.h +++ b/src/prettyprinter.h @@ -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* statements); void PrintDeclarations(ZoneList* declarations); diff --git a/src/usage-analyzer.cc b/src/usage-analyzer.cc index 36464fa..5514f40 100644 --- a/src/usage-analyzer.cc +++ b/src/usage-analyzer.cc @@ -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(); diff --git a/src/x64/codegen-x64.h b/src/x64/codegen-x64.h index bb4b538..9e69007 100644 --- a/src/x64/codegen-x64.h +++ b/src/x64/codegen-x64.h @@ -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 -- 2.7.4