summaryrefslogtreecommitdiffstats
path: root/include/clang/AST/ExprCXX.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/AST/ExprCXX.h')
-rw-r--r--include/clang/AST/ExprCXX.h168
1 files changed, 71 insertions, 97 deletions
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h
index 707aeed..0608aba 100644
--- a/include/clang/AST/ExprCXX.h
+++ b/include/clang/AST/ExprCXX.h
@@ -951,7 +951,9 @@ public:
/// This wraps up a function call argument that was created from the
/// corresponding parameter's default argument, when the call did not
/// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr : public Expr {
+class CXXDefaultArgExpr final
+ : public Expr,
+ private llvm::TrailingObjects<CXXDefaultArgExpr, Expr *> {
/// \brief The parameter whose default is being used.
///
/// When the bit is set, the subexpression is stored after the
@@ -977,7 +979,7 @@ class CXXDefaultArgExpr : public Expr {
SubExpr->getValueKind(), SubExpr->getObjectKind(),
false, false, false, false),
Param(param, true), Loc(Loc) {
- *reinterpret_cast<Expr **>(this + 1) = SubExpr;
+ *getTrailingObjects<Expr *>() = SubExpr;
}
public:
@@ -1002,12 +1004,12 @@ public:
// Retrieve the actual argument to the function call.
const Expr *getExpr() const {
if (Param.getInt())
- return *reinterpret_cast<Expr const * const*> (this + 1);
+ return *getTrailingObjects<Expr *>();
return getParam()->getDefaultArg();
}
Expr *getExpr() {
if (Param.getInt())
- return *reinterpret_cast<Expr **> (this + 1);
+ return *getTrailingObjects<Expr *>();
return getParam()->getDefaultArg();
}
@@ -1031,6 +1033,7 @@ public:
return child_range(child_iterator(), child_iterator());
}
+ friend TrailingObjects;
friend class ASTStmtReader;
friend class ASTStmtWriter;
};
@@ -1441,7 +1444,9 @@ public:
/// C++1y introduces a new form of "capture" called an init-capture that
/// includes an initializing expression (rather than capturing a variable),
/// and which can never occur implicitly.
-class LambdaExpr : public Expr {
+class LambdaExpr final
+ : public Expr,
+ private llvm::TrailingObjects<LambdaExpr, Stmt *, unsigned, VarDecl *> {
/// \brief The source range that covers the lambda introducer ([...]).
SourceRange IntroducerRange;
@@ -1476,23 +1481,21 @@ class LambdaExpr : public Expr {
/// module file just to determine the source range.
SourceLocation ClosingBrace;
- // Note: The capture initializers are stored directly after the lambda
- // expression, along with the index variables used to initialize by-copy
- // array captures.
+ size_t numTrailingObjects(OverloadToken<Stmt *>) const {
+ return NumCaptures + 1;
+ }
- typedef LambdaCapture Capture;
+ size_t numTrailingObjects(OverloadToken<unsigned>) const {
+ return HasArrayIndexVars ? NumCaptures + 1 : 0;
+ }
/// \brief Construct a lambda expression.
LambdaExpr(QualType T, SourceRange IntroducerRange,
LambdaCaptureDefault CaptureDefault,
- SourceLocation CaptureDefaultLoc,
- ArrayRef<Capture> Captures,
- bool ExplicitParams,
- bool ExplicitResultType,
- ArrayRef<Expr *> CaptureInits,
- ArrayRef<VarDecl *> ArrayIndexVars,
- ArrayRef<unsigned> ArrayIndexStarts,
- SourceLocation ClosingBrace,
+ SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
+ bool ExplicitParams, bool ExplicitResultType,
+ ArrayRef<Expr *> CaptureInits, ArrayRef<VarDecl *> ArrayIndexVars,
+ ArrayRef<unsigned> ArrayIndexStarts, SourceLocation ClosingBrace,
bool ContainsUnexpandedParameterPack);
/// \brief Construct an empty lambda expression.
@@ -1503,53 +1506,35 @@ class LambdaExpr : public Expr {
getStoredStmts()[NumCaptures] = nullptr;
}
- Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
+ Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
- Stmt *const *getStoredStmts() const {
- return reinterpret_cast<Stmt *const *>(this + 1);
- }
+ Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
/// \brief Retrieve the mapping from captures to the first array index
/// variable.
- unsigned *getArrayIndexStarts() {
- return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
- }
+ unsigned *getArrayIndexStarts() { return getTrailingObjects<unsigned>(); }
const unsigned *getArrayIndexStarts() const {
- return reinterpret_cast<const unsigned *>(getStoredStmts() + NumCaptures +
- 1);
+ return getTrailingObjects<unsigned>();
}
/// \brief Retrieve the complete set of array-index variables.
- VarDecl **getArrayIndexVars() {
- unsigned ArrayIndexSize = llvm::RoundUpToAlignment(
- sizeof(unsigned) * (NumCaptures + 1), llvm::alignOf<VarDecl *>());
- return reinterpret_cast<VarDecl **>(
- reinterpret_cast<char *>(getArrayIndexStarts()) + ArrayIndexSize);
- }
+ VarDecl **getArrayIndexVars() { return getTrailingObjects<VarDecl *>(); }
VarDecl *const *getArrayIndexVars() const {
- unsigned ArrayIndexSize = llvm::RoundUpToAlignment(
- sizeof(unsigned) * (NumCaptures + 1), llvm::alignOf<VarDecl *>());
- return reinterpret_cast<VarDecl *const *>(
- reinterpret_cast<const char *>(getArrayIndexStarts()) + ArrayIndexSize);
+ return getTrailingObjects<VarDecl *>();
}
public:
/// \brief Construct a new lambda expression.
- static LambdaExpr *Create(const ASTContext &C,
- CXXRecordDecl *Class,
- SourceRange IntroducerRange,
- LambdaCaptureDefault CaptureDefault,
- SourceLocation CaptureDefaultLoc,
- ArrayRef<Capture> Captures,
- bool ExplicitParams,
- bool ExplicitResultType,
- ArrayRef<Expr *> CaptureInits,
- ArrayRef<VarDecl *> ArrayIndexVars,
- ArrayRef<unsigned> ArrayIndexStarts,
- SourceLocation ClosingBrace,
- bool ContainsUnexpandedParameterPack);
+ static LambdaExpr *
+ Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange,
+ LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc,
+ ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
+ bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
+ ArrayRef<VarDecl *> ArrayIndexVars,
+ ArrayRef<unsigned> ArrayIndexStarts, SourceLocation ClosingBrace,
+ bool ContainsUnexpandedParameterPack);
/// \brief Construct a new lambda expression that will be deserialized from
/// an external source.
@@ -1572,7 +1557,7 @@ public:
/// \brief An iterator that walks over the captures of the lambda,
/// both implicit and explicit.
- typedef const Capture *capture_iterator;
+ typedef const LambdaCapture *capture_iterator;
/// \brief An iterator over a range of lambda captures.
typedef llvm::iterator_range<capture_iterator> capture_range;
@@ -1709,9 +1694,11 @@ public:
SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
child_range children() {
+ // Includes initialization exprs plus body stmt
return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
}
+ friend TrailingObjects;
friend class ASTStmtReader;
friend class ASTStmtWriter;
};
@@ -2226,7 +2213,9 @@ public:
/// __is_enum(std::string) == false
/// __is_trivially_constructible(vector<int>, int*, int*)
/// \endcode
-class TypeTraitExpr : public Expr {
+class TypeTraitExpr final
+ : public Expr,
+ private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
/// \brief The location of the type trait keyword.
SourceLocation Loc;
@@ -2243,16 +2232,10 @@ class TypeTraitExpr : public Expr {
TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
- /// \brief Retrieve the argument types.
- TypeSourceInfo **getTypeSourceInfos() {
- return reinterpret_cast<TypeSourceInfo **>(this+1);
- }
-
- /// \brief Retrieve the argument types.
- TypeSourceInfo * const *getTypeSourceInfos() const {
- return reinterpret_cast<TypeSourceInfo * const*>(this+1);
+ size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
+ return getNumArgs();
}
-
+
public:
/// \brief Create a new type trait expression.
static TypeTraitExpr *Create(const ASTContext &C, QualType T,
@@ -2284,22 +2267,9 @@ public:
}
/// \brief Retrieve the argument types.
- ArrayRef<TypeSourceInfo *> getArgs() const {
- return llvm::makeArrayRef(getTypeSourceInfos(), getNumArgs());
- }
-
- typedef TypeSourceInfo **arg_iterator;
- arg_iterator arg_begin() {
- return getTypeSourceInfos();
- }
- arg_iterator arg_end() {
- return getTypeSourceInfos() + getNumArgs();
- }
-
- typedef TypeSourceInfo const * const *arg_const_iterator;
- arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
- arg_const_iterator arg_end() const {
- return getTypeSourceInfos() + getNumArgs();
+ ArrayRef<TypeSourceInfo *> getArgs() const {
+ return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
+ getNumArgs());
}
SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
@@ -2314,9 +2284,9 @@ public:
return child_range(child_iterator(), child_iterator());
}
+ friend TrailingObjects;
friend class ASTStmtReader;
friend class ASTStmtWriter;
-
};
/// \brief An Embarcadero array type trait, as used in the implementation of
@@ -2899,7 +2869,9 @@ public:
/// This expression also tracks whether the sub-expression contains a
/// potentially-evaluated block literal. The lifetime of a block
/// literal is the extent of the enclosing scope.
-class ExprWithCleanups : public Expr {
+class ExprWithCleanups final
+ : public Expr,
+ private llvm::TrailingObjects<ExprWithCleanups, BlockDecl *> {
public:
/// The type of objects that are kept in the cleanup.
/// It's useful to remember the set of blocks; we could also
@@ -2913,12 +2885,7 @@ private:
ExprWithCleanups(EmptyShell, unsigned NumObjects);
ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
- CleanupObject *getObjectsBuffer() {
- return reinterpret_cast<CleanupObject*>(this + 1);
- }
- const CleanupObject *getObjectsBuffer() const {
- return reinterpret_cast<const CleanupObject*>(this + 1);
- }
+ friend TrailingObjects;
friend class ASTStmtReader;
public:
@@ -2929,7 +2896,8 @@ public:
ArrayRef<CleanupObject> objects);
ArrayRef<CleanupObject> getObjects() const {
- return llvm::makeArrayRef(getObjectsBuffer(), getNumObjects());
+ return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
+ getNumObjects());
}
unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
@@ -2981,7 +2949,9 @@ public:
/// When the returned expression is instantiated, it may resolve to a
/// constructor call, conversion function call, or some kind of type
/// conversion.
-class CXXUnresolvedConstructExpr : public Expr {
+class CXXUnresolvedConstructExpr final
+ : public Expr,
+ private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
/// \brief The type being constructed.
TypeSourceInfo *Type;
@@ -3002,6 +2972,7 @@ class CXXUnresolvedConstructExpr : public Expr {
CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
: Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
+ friend TrailingObjects;
friend class ASTStmtReader;
public:
@@ -3036,13 +3007,11 @@ public:
unsigned arg_size() const { return NumArgs; }
typedef Expr** arg_iterator;
- arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
+ arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
arg_iterator arg_end() { return arg_begin() + NumArgs; }
typedef const Expr* const * const_arg_iterator;
- const_arg_iterator arg_begin() const {
- return reinterpret_cast<const Expr* const *>(this + 1);
- }
+ const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
const_arg_iterator arg_end() const {
return arg_begin() + NumArgs;
}
@@ -3075,7 +3044,7 @@ public:
// Iterators
child_range children() {
- Stmt **begin = reinterpret_cast<Stmt**>(this+1);
+ Stmt **begin = reinterpret_cast<Stmt **>(arg_begin());
return child_range(begin, begin + NumArgs);
}
};
@@ -3608,7 +3577,9 @@ public:
/// static const unsigned value = sizeof...(Types);
/// };
/// \endcode
-class SizeOfPackExpr : public Expr {
+class SizeOfPackExpr final
+ : public Expr,
+ private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> {
/// \brief The location of the \c sizeof keyword.
SourceLocation OperatorLoc;
@@ -3633,6 +3604,7 @@ class SizeOfPackExpr : public Expr {
/// \brief The parameter pack.
NamedDecl *Pack;
+ friend TrailingObjects;
friend class ASTStmtReader;
friend class ASTStmtWriter;
@@ -3649,7 +3621,7 @@ class SizeOfPackExpr : public Expr {
Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
assert((!Length || PartialArgs.empty()) &&
"have partial args for non-dependent sizeof... expression");
- TemplateArgument *Args = reinterpret_cast<TemplateArgument *>(this + 1);
+ TemplateArgument *Args = getTrailingObjects<TemplateArgument>();
std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
}
@@ -3700,8 +3672,7 @@ public:
/// \brief Get
ArrayRef<TemplateArgument> getPartialArguments() const {
assert(isPartiallySubstituted());
- const TemplateArgument *Args =
- reinterpret_cast<const TemplateArgument *>(this + 1);
+ const TemplateArgument *Args = getTrailingObjects<TemplateArgument>();
return llvm::makeArrayRef(Args, Args + Length);
}
@@ -3837,7 +3808,9 @@ public:
/// };
/// template struct S<int, int>;
/// \endcode
-class FunctionParmPackExpr : public Expr {
+class FunctionParmPackExpr final
+ : public Expr,
+ private llvm::TrailingObjects<FunctionParmPackExpr, ParmVarDecl *> {
/// \brief The function parameter pack which was referenced.
ParmVarDecl *ParamPack;
@@ -3851,6 +3824,7 @@ class FunctionParmPackExpr : public Expr {
SourceLocation NameLoc, unsigned NumParams,
ParmVarDecl *const *Params);
+ friend TrailingObjects;
friend class ASTReader;
friend class ASTStmtReader;
@@ -3871,7 +3845,7 @@ public:
/// \brief Iterators over the parameters which the parameter pack expanded
/// into.
typedef ParmVarDecl * const *iterator;
- iterator begin() const { return reinterpret_cast<iterator>(this+1); }
+ iterator begin() const { return getTrailingObjects<ParmVarDecl *>(); }
iterator end() const { return begin() + NumParameters; }
/// \brief Get the number of parameters in this parameter pack.
OpenPOWER on IntegriCloud