Expand Up
@@ -951,7 +951,9 @@ class CXXThrowExpr : public Expr {
// / 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
Expand All
@@ -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:
Expand All
@@ -1002,12 +1004,12 @@ class CXXDefaultArgExpr : public Expr {
// 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 ();
}
Expand All
@@ -1031,6 +1033,7 @@ class CXXDefaultArgExpr : public Expr {
return child_range (child_iterator (), child_iterator ());
}
friend TrailingObjects;
friend class ASTStmtReader ;
friend class ASTStmtWriter ;
};
Expand Down
Expand Up
@@ -1441,7 +1444,9 @@ class CXXTemporaryObjectExpr : public CXXConstructExpr {
// / 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;
Expand Down
Expand Up
@@ -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.
Expand All
@@ -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.
Expand All
@@ -1572,7 +1557,7 @@ class LambdaExpr : public Expr {
// / \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;
Expand Down
Expand Up
@@ -1709,9 +1694,11 @@ class LambdaExpr : public Expr {
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 ;
};
Expand Down
Expand Up
@@ -2226,7 +2213,9 @@ class CXXPseudoDestructorExpr : public Expr {
// / __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;
Expand All
@@ -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,
Expand Down
Expand Up
@@ -2284,22 +2267,9 @@ class TypeTraitExpr : public Expr {
}
// / \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; }
Expand All
@@ -2314,9 +2284,9 @@ class TypeTraitExpr : public Expr {
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
Expand Down
Expand Up
@@ -2899,7 +2869,9 @@ class DependentScopeDeclRefExpr final
// / 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
Expand All
@@ -2913,12 +2885,7 @@ class ExprWithCleanups : public Expr {
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:
Expand All
@@ -2929,7 +2896,8 @@ class ExprWithCleanups : public Expr {
ArrayRef<CleanupObject> objects);
ArrayRef<CleanupObject> getObjects () const {
return llvm::makeArrayRef (getObjectsBuffer (), getNumObjects ());
return llvm::makeArrayRef (getTrailingObjects<CleanupObject>(),
getNumObjects ());
}
unsigned getNumObjects () const { return ExprWithCleanupsBits.NumObjects ; }
Expand Down
Expand Up
@@ -2981,7 +2949,9 @@ class ExprWithCleanups : public Expr {
// / 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;
Expand All
@@ -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:
Expand Down
Expand Up
@@ -3036,13 +3007,11 @@ class CXXUnresolvedConstructExpr : public Expr {
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;
}
Expand Down
Expand Up
@@ -3075,7 +3044,7 @@ class CXXUnresolvedConstructExpr : public Expr {
// Iterators
child_range children () {
Stmt **begin = reinterpret_cast <Stmt**>(this + 1 );
Stmt **begin = reinterpret_cast <Stmt **>(arg_begin () );
return child_range (begin, begin + NumArgs);
}
};
Expand Down
Expand Up
@@ -3608,7 +3577,9 @@ class PackExpansionExpr : public Expr {
// / 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;
Expand All
@@ -3633,6 +3604,7 @@ class SizeOfPackExpr : public Expr {
// / \brief The parameter pack.
NamedDecl *Pack;
friend TrailingObjects;
friend class ASTStmtReader ;
friend class ASTStmtWriter ;
Expand All
@@ -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);
}
Expand Down
Expand Up
@@ -3700,8 +3672,7 @@ class SizeOfPackExpr : public Expr {
// / \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);
}
Expand Down
Expand Up
@@ -3837,7 +3808,9 @@ class SubstNonTypeTemplateParmPackExpr : public Expr {
// / };
// / 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;
Expand All
@@ -3851,6 +3824,7 @@ class FunctionParmPackExpr : public Expr {
SourceLocation NameLoc, unsigned NumParams,
ParmVarDecl *const *Params);
friend TrailingObjects;
friend class ASTReader ;
friend class ASTStmtReader ;
Expand All
@@ -3871,7 +3845,7 @@ class FunctionParmPackExpr : public Expr {
// / \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.
Expand Down