[cfe-commits] r39344 - in /cfe/cfe/trunk: AST/Stmt.cpp AST/StmtPrinter.cpp AST/StmtVisitor.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Expr.h include/clang/AST/ExprCXX.h include/clang/AST/Stmt.h include/clang/AST/StmtNodes.def include/clang/AST/StmtVisitor.h
snaroff at cs.uiuc.edu
snaroff at cs.uiuc.edu
Wed Jul 11 09:43:23 PDT 2007
Author: snaroff
Date: Wed Jul 11 11:43:23 2007
New Revision: 39344
URL: http://llvm.org/viewvc/llvm-project?rev=39344&view=rev
Log:
More changes to complete the dynamic type support for Stmt/Expr.
This set of changes includes:
- convert ExprCXX.h and add to the Xcode project file.
-- required adding CXXBoolLiteralExpr to StmtNodes.def.
-- required adding visitor support (decl/defn).
- make the class codes in StmtNodes.def explicit (to enable range checking).
-- this required changing all clients of the STMT macro.
- declare the instance data const.
Modified:
cfe/cfe/trunk/AST/Stmt.cpp
cfe/cfe/trunk/AST/StmtPrinter.cpp
cfe/cfe/trunk/AST/StmtVisitor.cpp
cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/AST/ExprCXX.h
cfe/cfe/trunk/include/clang/AST/Stmt.h
cfe/cfe/trunk/include/clang/AST/StmtNodes.def
cfe/cfe/trunk/include/clang/AST/StmtVisitor.h
Modified: cfe/cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Stmt.cpp?rev=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/cfe/trunk/AST/Stmt.cpp Wed Jul 11 11:43:23 2007
@@ -18,8 +18,8 @@
using namespace clang;
// Implement all the AST node visit methods using the StmtNodes.def database.
-#define STMT(CLASS, PARENT) \
+#define STMT(N, CLASS, PARENT) \
void CLASS::visit(StmtVisitor &V) { return V.Visit##CLASS(this); }
-STMT(Stmt, )
+STMT(0, Stmt, )
#include "clang/AST/StmtNodes.def"
Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:43:23 2007
@@ -78,7 +78,7 @@
}
virtual void VisitStmt(Stmt *Node);
-#define STMT(CLASS, PARENT) \
+#define STMT(N, CLASS, PARENT) \
virtual void Visit##CLASS(CLASS *Node);
#include "clang/AST/StmtNodes.def"
};
@@ -311,6 +311,11 @@
PrintExpr(Node->getSubExpr());
OS << ")";
}
+
+void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
+ assert(0 && "TODO: should print CXXBoolLiteralExpr!");
+}
+
void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
PrintExpr(Node->getLHS());
OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
Modified: cfe/cfe/trunk/AST/StmtVisitor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtVisitor.cpp?rev=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/StmtVisitor.cpp (original)
+++ cfe/cfe/trunk/AST/StmtVisitor.cpp Wed Jul 11 11:43:23 2007
@@ -21,7 +21,7 @@
}
// Implement all of the delegation visitor methods.
-#define STMT(FROM, TO) \
+#define STMT(N, FROM, TO) \
void StmtVisitor::Visit##FROM(FROM *Node) { Visit##TO(Node); }
#include "clang/AST/StmtNodes.def"
Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:43:23 2007
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 1A30A9E90B93A4C800201A91 /* ExprCXX.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1A30A9E80B93A4C800201A91 /* ExprCXX.h */; };
DE01DA490B12ADA300AC22CE /* PPCallbacks.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE01DA480B12ADA300AC22CE /* PPCallbacks.h */; };
DE06B73E0A8307640050E87E /* LangOptions.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE06B73D0A8307640050E87E /* LangOptions.h */; };
DE06BECB0A854E4B0050E87E /* Scope.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE06BECA0A854E4B0050E87E /* Scope.h */; };
@@ -143,12 +144,14 @@
DED676FA0B6C797B00AAD4A3 /* Builtins.h in CopyFiles */,
DED67AEE0B6DB92A00AAD4A3 /* X86Builtins.def in CopyFiles */,
DED67AF00B6DB92F00AAD4A3 /* PPCBuiltins.def in CopyFiles */,
+ 1A30A9E90B93A4C800201A91 /* ExprCXX.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 1A30A9E80B93A4C800201A91 /* ExprCXX.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ExprCXX.h; path = clang/AST/ExprCXX.h; sourceTree = "<group>"; };
8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
@@ -330,6 +333,7 @@
DEC8D98B0A9433BC00353FCA /* AST */ = {
isa = PBXGroup;
children = (
+ 1A30A9E80B93A4C800201A91 /* ExprCXX.h */,
DEC8D9A30A94346E00353FCA /* AST.h */,
DE75ED280B044DC90020CF81 /* ASTContext.h */,
DEC8DABF0A94402500353FCA /* ASTStreamer.h */,
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=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:43:23 2007
@@ -29,13 +29,13 @@
class Expr : public Stmt {
/// TODO: Type.
public:
- Expr() : Stmt(ExprClass) {}
Expr(StmtClass SC) : Stmt(SC) {}
~Expr() {}
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
- return T->getStmtClass() == ExprClass;
+ return T->getStmtClass() >= firstExprConstant &&
+ T->getStmtClass() <= lastExprConstant;
}
static bool classof(const Expr *) { return true; }
};
@@ -269,6 +269,7 @@
Expr *Op;
public:
CastExpr(TypeRef ty, Expr *op) : Expr(CastExprClass), Ty(ty), Op(op) {}
+ CastExpr(StmtClass SC, TypeRef ty, Expr *op) : Expr(SC), Ty(ty), Op(op) {}
TypeRef getDestType() const { return Ty; }
Modified: cfe/cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/ExprCXX.h?rev=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ExprCXX.h Wed Jul 11 11:43:23 2007
@@ -35,7 +35,7 @@
};
CXXCastExpr(Opcode op, TypeRef ty, Expr *expr)
- : CastExpr(ty, expr), Op(op) {}
+ : CastExpr(CXXCastExprClass, ty, expr), Op(op) {}
Opcode getOpcode() const { return Op; }
virtual void visit(StmtVisitor &Visitor);
@@ -48,7 +48,8 @@
class CXXBoolLiteralExpr : public Expr {
bool Value;
public:
- CXXBoolLiteralExpr(bool val) : Value(val) {}
+ CXXBoolLiteralExpr(bool val) : Expr(CXXBoolLiteralExprClass), Value(val) {}
+ virtual void visit(StmtVisitor &Visitor);
};
} // end namespace clang
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=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:43:23 2007
@@ -29,12 +29,15 @@
class Stmt {
public:
enum StmtClass {
-#define STMT(CLASS, PARENT) CLASS##Class,
+#define STMT(N, CLASS, PARENT) CLASS##Class = N,
+#define FIRST_STMT(N) firstStmtConstant = N,
+#define LAST_STMT(N) lastStmtConstant = N,
+#define FIRST_EXPR(N) firstExprConstant = N,
+#define LAST_EXPR(N) lastExprConstant = N
#include "clang/AST/StmtNodes.def"
- LastStmtClass
- };
+};
private:
- StmtClass sClass;
+ const StmtClass sClass;
public:
Stmt(StmtClass SC) : sClass(SC) {}
virtual ~Stmt() {}
Modified: cfe/cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/StmtNodes.def?rev=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/cfe/trunk/include/clang/AST/StmtNodes.def Wed Jul 11 11:43:23 2007
@@ -11,39 +11,58 @@
//
//===----------------------------------------------------------------------===//
+#ifndef FIRST_STMT
+#define FIRST_STMT(n)
+#define LAST_STMT(n)
+#endif
+
+#ifndef FIRST_EXPR
+#define FIRST_EXPR(n)
+#define LAST_EXPR(n)
+#endif
+
// Normal Statements.
-STMT(CompoundStmt , Stmt)
-STMT(CaseStmt , Stmt)
-STMT(DefaultStmt , Stmt)
-STMT(LabelStmt , Stmt)
-STMT(IfStmt , Stmt)
-STMT(SwitchStmt , Stmt)
-STMT(WhileStmt , Stmt)
-STMT(DoStmt , Stmt)
-STMT(ForStmt , Stmt)
-STMT(GotoStmt , Stmt)
-STMT(IndirectGotoStmt, Stmt)
-STMT(ContinueStmt , Stmt)
-STMT(BreakStmt , Stmt)
-STMT(ReturnStmt , Stmt)
+FIRST_STMT(1)
+STMT(1, CompoundStmt , Stmt)
+STMT(2, CaseStmt , Stmt)
+STMT(3, DefaultStmt , Stmt)
+STMT(4, LabelStmt , Stmt)
+STMT(5, IfStmt , Stmt)
+STMT(6, SwitchStmt , Stmt)
+STMT(7, WhileStmt , Stmt)
+STMT(8, DoStmt , Stmt)
+STMT(9, ForStmt , Stmt)
+STMT(10, GotoStmt , Stmt)
+STMT(11, IndirectGotoStmt, Stmt)
+STMT(12, ContinueStmt , Stmt)
+STMT(13, BreakStmt , Stmt)
+STMT(14, ReturnStmt , Stmt)
+LAST_STMT(14)
+FIRST_EXPR(32)
// Expressions.
-STMT(Expr , Stmt)
-STMT(DeclRefExpr , Expr)
-STMT(IntegerLiteral , Expr)
-STMT(FloatingLiteral , Expr)
-STMT(StringLiteral , Expr)
-STMT(ParenExpr , Expr)
-STMT(UnaryOperator , Expr)
-STMT(SizeOfAlignOfTypeExpr, Expr)
-STMT(ArraySubscriptExpr , Expr)
-STMT(CallExpr , Expr)
-STMT(MemberExpr , Expr)
-STMT(CastExpr , Expr)
-STMT(BinaryOperator , Expr)
-STMT(ConditionalOperator , Expr)
+STMT(32, Expr , Stmt)
+STMT(33, DeclRefExpr , Expr)
+STMT(34, IntegerLiteral , Expr)
+STMT(35, FloatingLiteral , Expr)
+STMT(36, StringLiteral , Expr)
+STMT(37, ParenExpr , Expr)
+STMT(38, UnaryOperator , Expr)
+STMT(39, SizeOfAlignOfTypeExpr, Expr)
+STMT(40, ArraySubscriptExpr , Expr)
+STMT(41, CallExpr , Expr)
+STMT(42, MemberExpr , Expr)
+STMT(43, CastExpr , Expr)
+STMT(44, BinaryOperator , Expr)
+STMT(45, ConditionalOperator , Expr)
// C++ Expressions.
-STMT(CXXCastExpr , CastExpr)
+STMT(46, CXXCastExpr , CastExpr)
+STMT(47, CXXBoolLiteralExpr , Expr)
+LAST_EXPR(47)
#undef STMT
+#undef FIRST_STMT
+#undef LAST_STMT
+#undef FIRST_EXPR
+#undef LAST_EXPR
Modified: cfe/cfe/trunk/include/clang/AST/StmtVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/StmtVisitor.h?rev=39344&r1=39343&r2=39344&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/StmtVisitor.h (original)
+++ cfe/cfe/trunk/include/clang/AST/StmtVisitor.h Wed Jul 11 11:43:23 2007
@@ -18,7 +18,7 @@
namespace clang {
class Stmt;
// Add prototypes for all AST node classes.
-#define STMT(CLASS, PARENT) \
+#define STMT(N, CLASS, PARENT) \
class CLASS;
#include "clang/AST/StmtNodes.def"
@@ -31,7 +31,7 @@
virtual void VisitStmt(Stmt *Node) {}
// Implement all the methods with the StmtNodes.def file.
-#define STMT(CLASS, PARENT) \
+#define STMT(N, CLASS, PARENT) \
virtual void Visit##CLASS(CLASS *Node);
#include "clang/AST/StmtNodes.def"
};
More information about the cfe-commits
mailing list