[cfe-commits] r39104 - in /cfe/cfe/trunk: AST/Expr.cpp AST/Stmt.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Expr.h include/clang/AST/Stmt.h include/clang/AST/StmtVisitor.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:27:33 PDT 2007
Author: sabre
Date: Wed Jul 11 11:27:33 2007
New Revision: 39104
URL: http://llvm.org/viewvc/llvm-project?rev=39104&view=rev
Log:
add a new StmtVisitor class for traversing Stmt/Expr nodes.
Added:
cfe/cfe/trunk/include/clang/AST/StmtVisitor.h (with props)
Modified:
cfe/cfe/trunk/AST/Expr.cpp
cfe/cfe/trunk/AST/Stmt.cpp
cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/AST/Stmt.h
Modified: cfe/cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Expr.cpp?rev=39104&r1=39103&r2=39104&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:27:33 2007
@@ -12,12 +12,36 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/Expr.h"
+#include "clang/AST/StmtVisitor.h"
#include "clang/Lex/IdentifierTable.h"
#include <iostream>
using namespace llvm;
using namespace clang;
//===----------------------------------------------------------------------===//
+// Visitor Implementation.
+//===----------------------------------------------------------------------===//
+
+#define MAKE_VISITOR(CLASS) \
+ void CLASS::visit(StmtVisitor *V) { return V->Visit ## CLASS(this); }
+
+MAKE_VISITOR(DeclRefExpr)
+MAKE_VISITOR(IntegerConstant)
+MAKE_VISITOR(FloatingConstant)
+MAKE_VISITOR(StringExpr)
+MAKE_VISITOR(ParenExpr)
+MAKE_VISITOR(UnaryOperator)
+MAKE_VISITOR(SizeOfAlignOfTypeExpr)
+MAKE_VISITOR(ArraySubscriptExpr)
+MAKE_VISITOR(CallExpr)
+MAKE_VISITOR(MemberExpr)
+MAKE_VISITOR(CastExpr)
+MAKE_VISITOR(BinaryOperator)
+MAKE_VISITOR(ConditionalOperator)
+
+#undef MAKE_VISITOR
+
+//===----------------------------------------------------------------------===//
// Primary Expressions.
//===----------------------------------------------------------------------===//
Modified: cfe/cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Stmt.cpp?rev=39104&r1=39103&r2=39104&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/cfe/trunk/AST/Stmt.cpp Wed Jul 11 11:27:33 2007
@@ -13,6 +13,7 @@
#include "clang/AST/Stmt.h"
#include "clang/AST/Expr.h"
+#include "clang/AST/StmtVisitor.h"
#include <iostream>
using namespace llvm;
using namespace clang;
@@ -28,6 +29,10 @@
}
+void CompoundStmt::visit(StmtVisitor *V) { return V->VisitCompoundStmt(this); }
+void IfStmt ::visit(StmtVisitor *V) { return V->VisitIfStmt(this); }
+void ReturnStmt ::visit(StmtVisitor *V) { return V->VisitReturnStmt(this); }
+
void CompoundStmt::dump_impl() const {
std::cerr << "{\n";
Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=39104&r1=39103&r2=39104&view=diff
==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:27:33 2007
@@ -28,6 +28,7 @@
DE3452410AEF1A2D00DBC861 /* Stmt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE3452400AEF1A2D00DBC861 /* Stmt.cpp */; };
DE3452810AEF1B1800DBC861 /* Stmt.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3452800AEF1B1800DBC861 /* Stmt.h */; };
DE345B500AFB1CFE00DBC861 /* ASTBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE345B4F0AFB1CFE00DBC861 /* ASTBuilder.cpp */; };
+ DE345C1A0AFC658B00DBC861 /* StmtVisitor.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE345C190AFC658B00DBC861 /* StmtVisitor.h */; };
DE46BF280AE0A82D00CC047C /* TargetInfo.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE46BF270AE0A82D00CC047C /* TargetInfo.h */; };
DE5932D10AD60FF400BC794C /* clang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CD0AD60FF400BC794C /* clang.cpp */; };
DE5932D20AD60FF400BC794C /* clang.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE5932CE0AD60FF400BC794C /* clang.h */; };
@@ -113,6 +114,7 @@
DE344AB80AE5DF6D00DBC861 /* HeaderSearch.h in CopyFiles */,
DE3450D70AEB543100DBC861 /* DirectoryLookup.h in CopyFiles */,
DE3452810AEF1B1800DBC861 /* Stmt.h in CopyFiles */,
+ DE345C1A0AFC658B00DBC861 /* StmtVisitor.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 1;
};
@@ -141,6 +143,7 @@
DE3452400AEF1A2D00DBC861 /* Stmt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Stmt.cpp; path = AST/Stmt.cpp; sourceTree = "<group>"; };
DE3452800AEF1B1800DBC861 /* Stmt.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Stmt.h; path = clang/AST/Stmt.h; sourceTree = "<group>"; };
DE345B4F0AFB1CFE00DBC861 /* ASTBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ASTBuilder.cpp; path = AST/ASTBuilder.cpp; sourceTree = "<group>"; };
+ DE345C190AFC658B00DBC861 /* StmtVisitor.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = StmtVisitor.h; path = clang/AST/StmtVisitor.h; sourceTree = "<group>"; };
DE46BF270AE0A82D00CC047C /* TargetInfo.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TargetInfo.h; sourceTree = "<group>"; };
DE5932CD0AD60FF400BC794C /* clang.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = clang.cpp; path = Driver/clang.cpp; sourceTree = "<group>"; };
DE5932CE0AD60FF400BC794C /* clang.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = clang.h; path = Driver/clang.h; sourceTree = "<group>"; };
@@ -283,6 +286,7 @@
DEC8D9900A9433CD00353FCA /* Decl.h */,
DE0FCA620A95859D00248FD5 /* Expr.h */,
DE3452800AEF1B1800DBC861 /* Stmt.h */,
+ DE345C190AFC658B00DBC861 /* StmtVisitor.h */,
);
name = AST;
sourceTree = "<group>";
Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39104&r1=39103&r2=39104&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:27:33 2007
@@ -49,18 +49,21 @@
public:
DeclRefExpr(Decl &d) : D(d) {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
class IntegerConstant : public Expr {
public:
IntegerConstant() {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
class FloatingConstant : public Expr {
public:
FloatingConstant() {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
class StringExpr : public Expr {
@@ -71,6 +74,7 @@
StringExpr(const char *strData, unsigned byteLength, bool Wide);
virtual ~StringExpr();
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
class StringExprLOC : public StringExpr {
@@ -92,6 +96,7 @@
ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
: L(l), R(r), Val(val) {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
@@ -120,7 +125,8 @@
static const char *getOpcodeStr(Opcode Op);
virtual void dump_impl() const;
-
+ virtual void visit(StmtVisitor *Visitor);
+
private:
Expr *Input;
Opcode Opc;
@@ -143,6 +149,7 @@
}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
class SizeOfAlignOfTypeExprLOC : public SizeOfAlignOfTypeExpr {
@@ -167,6 +174,7 @@
ArraySubscriptExpr(Expr *base, Expr *idx) : Base(base), Idx(idx) {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
@@ -205,6 +213,7 @@
unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
class CallExprLOC : public CallExpr {
@@ -229,6 +238,7 @@
: Base(base), MemberDecl(memberdecl), isArrow(isarrow) {
}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
class MemberExprLOC : public MemberExpr {
@@ -250,6 +260,7 @@
CastExpr(Type *ty, Expr *op) : Ty(ty), Op(op) {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
class CastExprLOC : public CastExpr {
@@ -293,6 +304,7 @@
static const char *getOpcodeStr(Opcode Op);
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
private:
Expr *LHS, *RHS;
@@ -316,6 +328,7 @@
ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs)
: Cond(cond), LHS(lhs), RHS(rhs) {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
/// ConditionalOperatorLOC - ConditionalOperator with full location info.
Modified: cfe/cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Stmt.h?rev=39104&r1=39103&r2=39104&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:27:33 2007
@@ -20,6 +20,7 @@
namespace llvm {
namespace clang {
class Expr;
+ class StmtVisitor;
/// Stmt - This represents one statement.
///
@@ -34,6 +35,8 @@
// FIXME: move to isa/dyncast etc.
virtual bool isExpr() const { return false; }
+ // Implement visitor support.
+ virtual void visit(StmtVisitor *Visitor) = 0;
private:
virtual void dump_impl() const = 0;
};
@@ -47,6 +50,8 @@
: Body(StmtStart, StmtStart+NumStmts) {}
virtual void dump_impl() const;
+
+ virtual void visit(StmtVisitor *Visitor);
};
/// IfStmt - This represents an if/then/else.
@@ -59,6 +64,7 @@
: Cond(cond), Then(then), Else(elsev) {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
@@ -71,6 +77,7 @@
ReturnStmt(Expr *E = 0) : RetExpr(E) {}
virtual void dump_impl() const;
+ virtual void visit(StmtVisitor *Visitor);
};
Added: cfe/cfe/trunk/include/clang/AST/StmtVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/StmtVisitor.h?rev=39104&view=auto
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/StmtVisitor.h (added)
+++ cfe/cfe/trunk/include/clang/AST/StmtVisitor.h Wed Jul 11 11:27:33 2007
@@ -0,0 +1,69 @@
+//===--- StmtVisitor.h - Visitor for Stmt subclasses ------------*- C++ -*-===//
+//
+// 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 defines the StmtVisitor interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_STMTVISITOR_H
+#define LLVM_CLANG_AST_STMT_H
+
+namespace llvm {
+namespace clang {
+ class CompoundStmt;
+ class IfStmt;
+ class ReturnStmt;
+
+ class DeclRefExpr;
+ class IntegerConstant;
+ class FloatingConstant;
+ class StringExpr;
+ class ParenExpr;
+ class UnaryOperator;
+ class SizeOfAlignOfTypeExpr;
+ class ArraySubscriptExpr;
+ class CallExpr;
+ class MemberExpr;
+ class CastExpr;
+ class BinaryOperator;
+ class ConditionalOperator;
+
+/// StmtVisitor - This class implements a simple visitor for Stmt subclasses.
+/// Since Expr derives from Stmt, this also includes support for visiting Exprs.
+struct StmtVisitor {
+ virtual ~StmtVisitor();
+
+ /// VisitNull - Visit a null pointer.
+ ///
+ virtual void VisitNull() {}
+
+ // Visitation methods for various subclasses.
+ virtual void VisitCompoundStmt(CompoundStmt *Node) {}
+ virtual void VisitIfStmt (IfStmt *Node) {}
+ virtual void VisitReturnStmt (ReturnStmt *Node) {}
+
+ virtual void VisitDeclRefExpr(DeclRefExpr *Node) {}
+ virtual void VisitIntegerConstant(IntegerConstant *Node) {}
+ virtual void VisitFloatingConstant(FloatingConstant *Node) {}
+ virtual void VisitStringExpr(StringExpr *Node) {}
+ virtual void VisitParenExpr(ParenExpr *Node) {}
+ virtual void VisitUnaryOperator(UnaryOperator *Node) {}
+ virtual void VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {}
+ virtual void VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {}
+ virtual void VisitCallExpr(CallExpr *Node) {}
+ virtual void VisitMemberExpr(MemberExpr *Node) {}
+ virtual void VisitCastExpr(CastExpr *Node) {}
+ virtual void VisitBinaryOperator(BinaryOperator *Node) {}
+ virtual void VisitConditionalOperator(ConditionalOperator *Node) {}
+};
+
+}
+}
+
+#endif
Propchange: cfe/cfe/trunk/include/clang/AST/StmtVisitor.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/include/clang/AST/StmtVisitor.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
More information about the cfe-commits
mailing list