[cfe-commits] r41366 - in /cfe/trunk: AST/Expr.cpp include/clang/AST/Expr.h
Ted Kremenek
kremenek at apple.com
Fri Aug 24 13:06:47 PDT 2007
Author: kremenek
Date: Fri Aug 24 15:06:47 2007
New Revision: 41366
URL: http://llvm.org/viewvc/llvm-project?rev=41366&view=rev
Log:
Finished adding child_begin/child_end to all subclasses of Stmt in Expr.h.
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=41366&r1=41365&r2=41366&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Fri Aug 24 15:06:47 2007
@@ -717,28 +717,28 @@
//===----------------------------------------------------------------------===//
// DeclRefExpr
-Stmt::child_iterator DeclRefExpr::child_begin() { return NULL; }
-Stmt::child_iterator DeclRefExpr::child_end() { return NULL; }
+Stmt::child_iterator DeclRefExpr::child_begin() { return NULL; }
+Stmt::child_iterator DeclRefExpr::child_end() { return NULL; }
// PreDefinedExpr
-Stmt::child_iterator PreDefinedExpr::child_begin() { return NULL; }
-Stmt::child_iterator PreDefinedExpr::child_end() { return NULL; }
+Stmt::child_iterator PreDefinedExpr::child_begin() { return NULL; }
+Stmt::child_iterator PreDefinedExpr::child_end() { return NULL; }
// IntegerLiteral
-Stmt::child_iterator IntegerLiteral::child_begin() { return NULL; }
-Stmt::child_iterator IntegerLiteral::child_end() { return NULL; }
+Stmt::child_iterator IntegerLiteral::child_begin() { return NULL; }
+Stmt::child_iterator IntegerLiteral::child_end() { return NULL; }
// CharacterLiteral
-Stmt::child_iterator CharacterLiteral::child_begin() { return NULL; }
-Stmt::child_iterator CharacterLiteral::child_end() { return NULL; }
+Stmt::child_iterator CharacterLiteral::child_begin() { return NULL; }
+Stmt::child_iterator CharacterLiteral::child_end() { return NULL; }
// FloatingLiteral
-Stmt::child_iterator FloatingLiteral::child_begin() { return NULL; }
-Stmt::child_iterator FloatingLiteral::child_end() { return NULL; }
+Stmt::child_iterator FloatingLiteral::child_begin() { return NULL; }
+Stmt::child_iterator FloatingLiteral::child_end() { return NULL; }
// StringLiteral
-Stmt::child_iterator StringLiteral::child_begin() { return NULL; }
-Stmt::child_iterator StringLiteral::child_end() { return NULL; }
+Stmt::child_iterator StringLiteral::child_begin() { return NULL; }
+Stmt::child_iterator StringLiteral::child_end() { return NULL; }
// ParenExpr
Stmt::child_iterator ParenExpr::child_begin() {
@@ -759,28 +759,127 @@
}
// SizeOfAlignOfTypeExpr
-Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() {
+Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() {
return NULL;
}
-Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() {
+Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() {
return NULL;
}
// ArraySubscriptExpr
-Stmt::child_iterator ArraySubscriptExpr::child_begin() {
+Stmt::child_iterator ArraySubscriptExpr::child_begin() {
return reinterpret_cast<Stmt**>(&SubExprs);
}
-Stmt::child_iterator ArraySubscriptExpr::child_end() {
+Stmt::child_iterator ArraySubscriptExpr::child_end() {
return child_begin()+END_EXPR;
}
// CallExpr
-Stmt::child_iterator CallExpr::child_begin() {
+Stmt::child_iterator CallExpr::child_begin() {
return reinterpret_cast<Stmt**>(&SubExprs);
}
-Stmt::child_iterator CallExpr::child_end() {
+Stmt::child_iterator CallExpr::child_end() {
return child_begin()+NumArgs+ARGS_START;
}
+
+// MemberExpr
+Stmt::child_iterator MemberExpr::child_begin() {
+ return reinterpret_cast<Stmt**>(&Base);
+}
+
+Stmt::child_iterator MemberExpr::child_end() {
+ return child_begin()+1;
+}
+
+// OCUVectorElementExpr
+Stmt::child_iterator OCUVectorElementExpr::child_begin() {
+ return reinterpret_cast<Stmt**>(&Base);
+}
+
+Stmt::child_iterator OCUVectorElementExpr::child_end() {
+ return child_begin()+1;
+}
+
+// CompoundLiteralExpr
+Stmt::child_iterator CompoundLiteralExpr::child_begin() {
+ return reinterpret_cast<Stmt**>(&Init);
+}
+
+Stmt::child_iterator CompoundLiteralExpr::child_end() {
+ return child_begin()+1;
+}
+
+// ImplicitCastExpr
+Stmt::child_iterator ImplicitCastExpr::child_begin() {
+ return reinterpret_cast<Stmt**>(&Op);
+}
+
+Stmt::child_iterator ImplicitCastExpr::child_end() {
+ return child_begin()+1;
+}
+
+// CastExpr
+Stmt::child_iterator CastExpr::child_begin() {
+ return reinterpret_cast<Stmt**>(&Op);
+}
+
+Stmt::child_iterator CastExpr::child_end() {
+ return child_begin()+1;
+}
+
+// BinaryOperator
+Stmt::child_iterator BinaryOperator::child_begin() {
+ return reinterpret_cast<Stmt**>(&SubExprs);
+}
+
+Stmt::child_iterator BinaryOperator::child_end() {
+ return child_begin()+END_EXPR;
+}
+
+// ConditionalOperator
+Stmt::child_iterator ConditionalOperator::child_begin() {
+ return reinterpret_cast<Stmt**>(&SubExprs);
+}
+
+Stmt::child_iterator ConditionalOperator::child_end() {
+ return child_begin()+END_EXPR;
+}
+
+// AddrLabelExpr
+Stmt::child_iterator AddrLabelExpr::child_begin() { return NULL; }
+Stmt::child_iterator AddrLabelExpr::child_end() { return NULL; }
+
+
+// StmtExpr
+Stmt::child_iterator StmtExpr::child_begin() {
+ return reinterpret_cast<Stmt**>(&SubStmt);
+}
+
+Stmt::child_iterator StmtExpr::child_end() {
+ return child_begin()+1;
+}
+
+// TypesCompatibleExpr
+Stmt::child_iterator TypesCompatibleExpr::child_begin() { return NULL; }
+Stmt::child_iterator TypesCompatibleExpr::child_end() { return NULL; }
+
+// ChooseExpr
+Stmt::child_iterator ChooseExpr::child_begin() {
+ return reinterpret_cast<Stmt**>(&SubExprs);
+}
+
+Stmt::child_iterator ChooseExpr::child_end() {
+ return child_begin()+END_EXPR;
+}
+
+// ObjCStringLiteral
+Stmt::child_iterator ObjCStringLiteral::child_begin() { return NULL; }
+Stmt::child_iterator ObjCStringLiteral::child_end() { return NULL; }
+
+// ObjCEncodeExpr
+Stmt::child_iterator ObjCEncodeExpr::child_begin() { return NULL; }
+Stmt::child_iterator ObjCEncodeExpr::child_end() { return NULL; }
+
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=41366&r1=41365&r2=41366&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Aug 24 15:06:47 2007
@@ -527,6 +527,10 @@
return T->getStmtClass() == MemberExprClass;
}
static bool classof(const MemberExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// OCUVectorElementExpr - This represents access to specific elements of a
@@ -583,6 +587,10 @@
return T->getStmtClass() == OCUVectorElementExprClass;
}
static bool classof(const OCUVectorElementExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// CompoundLiteralExpr - [C99 6.5.2.5]
@@ -602,6 +610,10 @@
return T->getStmtClass() == CompoundLiteralExprClass;
}
static bool classof(const CompoundLiteralExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// ImplicitCastExpr - Allows us to explicitly represent implicit type
@@ -623,6 +635,10 @@
return T->getStmtClass() == ImplicitCastExprClass;
}
static bool classof(const ImplicitCastExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// CastExpr - [C99 6.5.4] Cast Operators.
@@ -645,6 +661,10 @@
return T->getStmtClass() == CastExprClass;
}
static bool classof(const CastExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
class BinaryOperator : public Expr {
@@ -672,14 +692,16 @@
};
BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy)
- : Expr(BinaryOperatorClass, ResTy), LHS(lhs), RHS(rhs), Opc(opc) {
+ : Expr(BinaryOperatorClass, ResTy), Opc(opc) {
+ SubExprs[LHS] = lhs;
+ SubExprs[RHS] = rhs;
assert(!isCompoundAssignmentOp() &&
"Use ArithAssignBinaryOperator for compound assignments");
}
Opcode getOpcode() const { return Opc; }
- Expr *getLHS() const { return LHS; }
- Expr *getRHS() const { return RHS; }
+ Expr *getLHS() const { return SubExprs[LHS]; }
+ Expr *getRHS() const { return SubExprs[RHS]; }
virtual SourceRange getSourceRange() const {
return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
}
@@ -704,12 +726,21 @@
return T->getStmtClass() == BinaryOperatorClass;
}
static bool classof(const BinaryOperator *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+
private:
- Expr *LHS, *RHS;
+ enum { LHS, RHS, END_EXPR };
+ Expr* SubExprs[END_EXPR];
Opcode Opc;
+
protected:
BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, bool dead)
- : Expr(BinaryOperatorClass, ResTy), LHS(lhs), RHS(rhs), Opc(opc) {
+ : Expr(BinaryOperatorClass, ResTy), Opc(opc) {
+ SubExprs[LHS] = lhs;
+ SubExprs[RHS] = rhs;
}
};
@@ -744,14 +775,19 @@
/// GNU "missing LHS" extension is in use.
///
class ConditionalOperator : public Expr {
- Expr *Cond, *LHS, *RHS; // Left/Middle/Right hand sides.
+ enum { COND, LHS, RHS, END_EXPR };
+ Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
public:
ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
- : Expr(ConditionalOperatorClass, t), Cond(cond), LHS(lhs), RHS(rhs) {}
+ : Expr(ConditionalOperatorClass, t) {
+ SubExprs[COND] = cond;
+ SubExprs[LHS] = lhs;
+ SubExprs[RHS] = rhs;
+ }
- Expr *getCond() const { return Cond; }
- Expr *getLHS() const { return LHS; }
- Expr *getRHS() const { return RHS; }
+ Expr *getCond() const { return SubExprs[COND]; }
+ Expr *getLHS() const { return SubExprs[LHS]; }
+ Expr *getRHS() const { return SubExprs[RHS]; }
virtual SourceRange getSourceRange() const {
return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
@@ -760,6 +796,10 @@
return T->getStmtClass() == ConditionalOperatorClass;
}
static bool classof(const ConditionalOperator *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// AddrLabelExpr - The GNU address of label extension, representing &&label.
@@ -781,6 +821,10 @@
return T->getStmtClass() == AddrLabelExprClass;
}
static bool classof(const AddrLabelExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
@@ -805,6 +849,10 @@
return T->getStmtClass() == StmtExprClass;
}
static bool classof(const StmtExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
@@ -833,6 +881,10 @@
return T->getStmtClass() == TypesCompatibleExprClass;
}
static bool classof(const TypesCompatibleExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
@@ -842,22 +894,23 @@
/// - the expression returned has it's type unaltered by promotion rules.
/// - does not evaluate the expression that was not chosen.
class ChooseExpr : public Expr {
- Expr *Cond, *LHS, *RHS; // First, second, and third arguments.
+ enum { COND, LHS, RHS, END_EXPR };
+ Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
SourceLocation BuiltinLoc, RParenLoc;
public:
ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
SourceLocation RP)
: Expr(ChooseExprClass, t),
- Cond(cond), LHS(lhs), RHS(rhs), BuiltinLoc(BLoc), RParenLoc(RP) {}
-
- Expr *getCond() { return Cond; }
- Expr *getLHS() { return LHS; }
- Expr *getRHS() { return RHS; }
-
- const Expr *getCond() const { return Cond; }
- const Expr *getLHS() const { return LHS; }
- const Expr *getRHS() const { return RHS; }
-
+ BuiltinLoc(BLoc), RParenLoc(RP) {
+ SubExprs[COND] = cond;
+ SubExprs[LHS] = lhs;
+ SubExprs[RHS] = rhs;
+ }
+
+ Expr *getCond() const { return SubExprs[COND]; }
+ Expr *getLHS() const { return SubExprs[LHS]; }
+ Expr *getRHS() const { return SubExprs[RHS]; }
+
virtual SourceRange getSourceRange() const {
return SourceRange(BuiltinLoc, RParenLoc);
}
@@ -865,6 +918,10 @@
return T->getStmtClass() == ChooseExprClass;
}
static bool classof(const ChooseExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// ObjCStringLiteral, used for Objective-C string literals
@@ -887,6 +944,10 @@
return T->getStmtClass() == ObjCStringLiteralClass;
}
static bool classof(const ObjCStringLiteral *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
/// ObjCEncodeExpr, used for @encode in Objective-C.
@@ -906,6 +967,10 @@
return T->getStmtClass() == ObjCEncodeExprClass;
}
static bool classof(const ObjCEncodeExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
};
} // end namespace clang
More information about the cfe-commits
mailing list