Switch StmtVisitor from using dynamic to static dispatch. This makes it
significantly faster and actually reduces the amount of code in the system.
This also allows for future visitor changes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41211 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp
index e43f03c..d56a026 100644
--- a/AST/Stmt.cpp
+++ b/AST/Stmt.cpp
@@ -17,13 +17,6 @@
#include "clang/Lex/IdentifierTable.h"
using namespace clang;
-// Implement all the AST node visit methods using the StmtNodes.def database.
-#define STMT(N, CLASS, PARENT) \
-void CLASS::visit(StmtVisitor &V) { return V.Visit##CLASS(this); }
-
-STMT(0, Stmt, )
-#include "clang/AST/StmtNodes.def"
-
static struct StmtClassNameTable {
int enumValue;
const char *className;
diff --git a/AST/StmtDumper.cpp b/AST/StmtDumper.cpp
index 7b0d794..87d4e33 100644
--- a/AST/StmtDumper.cpp
+++ b/AST/StmtDumper.cpp
@@ -25,7 +25,7 @@
//===----------------------------------------------------------------------===//
namespace {
- class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor {
+ class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> {
FILE *F;
unsigned IndentLevel;
@@ -43,7 +43,7 @@
++IndentLevel;
if (S) {
- S->visit(*this);
+ Visit(S);
} else {
Indent();
fprintf(F, "<<<NULL>>>\n");
@@ -78,9 +78,9 @@
DumpType(Node->getType());
}
- virtual void VisitStmt(Stmt *Node);
+ void VisitStmt(Stmt *Node);
#define STMT(N, CLASS, PARENT) \
- virtual void Visit##CLASS(CLASS *Node);
+ void Visit##CLASS(CLASS *Node);
#include "clang/AST/StmtNodes.def"
};
}
@@ -502,13 +502,13 @@
/// This is useful in a debugger.
void Stmt::dump() const {
StmtDumper P(stderr, 4);
- const_cast<Stmt*>(this)->visit(P);
+ P.Visit(const_cast<Stmt*>(this));
fprintf(stderr, "\n");
}
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
void Stmt::dumpAll() const {
StmtDumper P(stderr, ~0U);
- const_cast<Stmt*>(this)->visit(P);
+ P.Visit(const_cast<Stmt*>(this));
fprintf(stderr, "\n");
}
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index 67a6be8..6387f66 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -26,7 +26,7 @@
//===----------------------------------------------------------------------===//
namespace {
- class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor {
+ class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor<StmtPrinter> {
std::ostream &OS;
unsigned IndentLevel;
public:
@@ -37,10 +37,10 @@
if (S && isa<Expr>(S)) {
// If this is an expr used in a stmt context, indent and newline it.
Indent();
- S->visit(*this);
+ Visit(S);
OS << ";\n";
} else if (S) {
- S->visit(*this);
+ Visit(S);
} else {
Indent() << "<<<NULL STATEMENT>>>\n";
}
@@ -53,7 +53,7 @@
void PrintExpr(Expr *E) {
if (E)
- E->visit(*this);
+ Visit(E);
else
OS << "<null expr>";
}
@@ -64,9 +64,9 @@
return OS;
}
- virtual void VisitStmt(Stmt *Node);
+ void VisitStmt(Stmt *Node);
#define STMT(N, CLASS, PARENT) \
- virtual void Visit##CLASS(CLASS *Node);
+ void Visit##CLASS(CLASS *Node);
#include "clang/AST/StmtNodes.def"
};
}
@@ -528,5 +528,5 @@
}
StmtPrinter P(OS);
- const_cast<Stmt*>(this)->visit(P);
+ P.Visit(const_cast<Stmt*>(this));
}
diff --git a/AST/StmtVisitor.cpp b/AST/StmtVisitor.cpp
deleted file mode 100644
index 9171ef7..0000000
--- a/AST/StmtVisitor.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-//===--- StmtVisitor.cpp - Visitor for Stmt subclasses --------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the StmtVisitor class.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/AST/StmtVisitor.h"
-#include "clang/AST/ExprCXX.h"
-using namespace clang;
-
-StmtVisitor::~StmtVisitor() {
- // Out-of-line virtual dtor.
-}
-
-// Implement all of the delegation visitor methods.
-#define STMT(N, FROM, TO) \
- void StmtVisitor::Visit##FROM(FROM *Node) { Visit##TO(Node); }
-#include "clang/AST/StmtNodes.def"
-