2009-10-21 04:40:46 +04:00
|
|
|
//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
|
2009-08-04 20:50:30 +04:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//===----------------------------------------------------------------------===/
|
|
|
|
//
|
|
|
|
// This file implements a semantic tree transformation that takes a given
|
|
|
|
// AST and rebuilds it, possibly transforming some nodes in the process.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===/
|
|
|
|
#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
|
|
|
|
#define LLVM_CLANG_SEMA_TREETRANSFORM_H
|
|
|
|
|
2010-08-26 02:03:47 +04:00
|
|
|
#include "clang/Sema/SemaInternal.h"
|
2010-08-13 00:07:10 +04:00
|
|
|
#include "clang/Sema/Lookup.h"
|
2010-12-21 01:05:00 +03:00
|
|
|
#include "clang/Sema/ParsedTemplate.h"
|
2009-08-06 09:28:30 +04:00
|
|
|
#include "clang/Sema/SemaDiagnostic.h"
|
2010-08-25 12:40:02 +04:00
|
|
|
#include "clang/Sema/ScopeInfo.h"
|
2009-09-04 01:38:09 +04:00
|
|
|
#include "clang/AST/Decl.h"
|
2010-08-24 11:21:54 +04:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-08-07 02:17:10 +04:00
|
|
|
#include "clang/AST/Expr.h"
|
2009-08-11 09:31:07 +04:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
|
|
|
#include "clang/AST/ExprObjC.h"
|
2009-08-20 11:17:43 +04:00
|
|
|
#include "clang/AST/Stmt.h"
|
|
|
|
#include "clang/AST/StmtCXX.h"
|
|
|
|
#include "clang/AST/StmtObjC.h"
|
2010-08-20 22:27:03 +04:00
|
|
|
#include "clang/Sema/Ownership.h"
|
|
|
|
#include "clang/Sema/Designator.h"
|
2009-08-11 09:31:07 +04:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2009-10-21 04:40:46 +04:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-12-02 03:05:49 +03:00
|
|
|
#include "TypeLocBuilder.h"
|
2009-08-04 20:50:30 +04:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace clang {
|
2010-08-25 12:40:02 +04:00
|
|
|
using namespace sema;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief A semantic tree transformation that allows one to transform one
|
|
|
|
/// abstract syntax tree into another.
|
|
|
|
///
|
2009-09-09 19:08:12 +04:00
|
|
|
/// A new tree transformation is defined by creating a new subclass \c X of
|
|
|
|
/// \c TreeTransform<X> and then overriding certain operations to provide
|
|
|
|
/// behavior specific to that transformation. For example, template
|
2009-08-04 20:50:30 +04:00
|
|
|
/// instantiation is implemented as a tree transformation where the
|
|
|
|
/// transformation of TemplateTypeParmType nodes involves substituting the
|
|
|
|
/// template arguments for their corresponding template parameters; a similar
|
|
|
|
/// transformation is performed for non-type template parameters and
|
|
|
|
/// template template parameters.
|
|
|
|
///
|
|
|
|
/// This tree-transformation template uses static polymorphism to allow
|
2009-09-09 19:08:12 +04:00
|
|
|
/// subclasses to customize any of its operations. Thus, a subclass can
|
2009-08-04 20:50:30 +04:00
|
|
|
/// override any of the transformation or rebuild operators by providing an
|
|
|
|
/// operation with the same signature as the default implementation. The
|
|
|
|
/// overridding function should not be virtual.
|
|
|
|
///
|
|
|
|
/// Semantic tree transformations are split into two stages, either of which
|
|
|
|
/// can be replaced by a subclass. The "transform" step transforms an AST node
|
|
|
|
/// or the parts of an AST node using the various transformation functions,
|
|
|
|
/// then passes the pieces on to the "rebuild" step, which constructs a new AST
|
|
|
|
/// node of the appropriate kind from the pieces. The default transformation
|
|
|
|
/// routines recursively transform the operands to composite AST nodes (e.g.,
|
|
|
|
/// the pointee type of a PointerType node) and, if any of those operand nodes
|
|
|
|
/// were changed by the transformation, invokes the rebuild operation to create
|
|
|
|
/// a new AST node.
|
|
|
|
///
|
2009-09-09 19:08:12 +04:00
|
|
|
/// Subclasses can customize the transformation at various levels. The
|
2009-08-05 02:27:00 +04:00
|
|
|
/// most coarse-grained transformations involve replacing TransformType(),
|
2009-08-04 20:50:30 +04:00
|
|
|
/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
|
|
|
|
/// TransformTemplateName(), or TransformTemplateArgument() with entirely
|
|
|
|
/// new implementations.
|
|
|
|
///
|
|
|
|
/// For more fine-grained transformations, subclasses can replace any of the
|
|
|
|
/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
|
2009-08-20 11:17:43 +04:00
|
|
|
/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
|
2009-08-04 20:50:30 +04:00
|
|
|
/// replacing TransformTemplateTypeParmType() allows template instantiation
|
2009-09-09 19:08:12 +04:00
|
|
|
/// to substitute template arguments for their corresponding template
|
2009-08-04 20:50:30 +04:00
|
|
|
/// parameters. Additionally, subclasses can override the \c RebuildXXX
|
|
|
|
/// functions to control how AST nodes are rebuilt when their operands change.
|
|
|
|
/// By default, \c TreeTransform will invoke semantic analysis to rebuild
|
|
|
|
/// AST nodes. However, certain other tree transformations (e.g, cloning) may
|
|
|
|
/// be able to use more efficient rebuild steps.
|
|
|
|
///
|
|
|
|
/// There are a handful of other functions that can be overridden, allowing one
|
2009-09-09 19:08:12 +04:00
|
|
|
/// to avoid traversing nodes that don't need any transformation
|
2009-08-04 20:50:30 +04:00
|
|
|
/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
|
|
|
|
/// operands have not changed (\c AlwaysRebuild()), and customize the
|
|
|
|
/// default locations and entity names used for type-checking
|
|
|
|
/// (\c getBaseLocation(), \c getBaseEntity()).
|
|
|
|
template<typename Derived>
|
|
|
|
class TreeTransform {
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
/// \brief Private RAII object that helps us forget and then re-remember
|
|
|
|
/// the template argument corresponding to a partially-substituted parameter
|
|
|
|
/// pack.
|
|
|
|
class ForgetPartiallySubstitutedPackRAII {
|
|
|
|
Derived &Self;
|
|
|
|
TemplateArgument Old;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
|
|
|
|
Old = Self.ForgetPartiallySubstitutedPack();
|
|
|
|
}
|
|
|
|
|
|
|
|
~ForgetPartiallySubstitutedPackRAII() {
|
|
|
|
Self.RememberPartiallySubstitutedPack(Old);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
protected:
|
|
|
|
Sema &SemaRef;
|
2010-12-21 01:05:00 +03:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
public:
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Initializes a new tree transformer.
|
2010-12-21 03:52:54 +03:00
|
|
|
TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Retrieves a reference to the derived class.
|
|
|
|
Derived &getDerived() { return static_cast<Derived&>(*this); }
|
|
|
|
|
|
|
|
/// \brief Retrieves a reference to the derived class.
|
2009-09-09 19:08:12 +04:00
|
|
|
const Derived &getDerived() const {
|
|
|
|
return static_cast<const Derived&>(*this);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
static inline ExprResult Owned(Expr *E) { return E; }
|
|
|
|
static inline StmtResult Owned(Stmt *S) { return S; }
|
2010-08-24 03:25:46 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Retrieves a reference to the semantic analysis object used for
|
|
|
|
/// this tree transform.
|
|
|
|
Sema &getSema() const { return SemaRef; }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Whether the transformation should always rebuild AST nodes, even
|
|
|
|
/// if none of the children have changed.
|
|
|
|
///
|
|
|
|
/// Subclasses may override this function to specify when the transformation
|
|
|
|
/// should rebuild all AST nodes.
|
|
|
|
bool AlwaysRebuild() { return false; }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Returns the location of the entity being transformed, if that
|
|
|
|
/// information was not available elsewhere in the AST.
|
|
|
|
///
|
2009-09-09 19:08:12 +04:00
|
|
|
/// By default, returns no source-location information. Subclasses can
|
2009-08-04 20:50:30 +04:00
|
|
|
/// provide an alternative implementation that provides better location
|
|
|
|
/// information.
|
|
|
|
SourceLocation getBaseLocation() { return SourceLocation(); }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Returns the name of the entity being transformed, if that
|
|
|
|
/// information was not available elsewhere in the AST.
|
|
|
|
///
|
|
|
|
/// By default, returns an empty name. Subclasses can provide an alternative
|
|
|
|
/// implementation with a more precise name.
|
|
|
|
DeclarationName getBaseEntity() { return DeclarationName(); }
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Sets the "base" location and entity when that
|
|
|
|
/// information is known based on another transformation.
|
|
|
|
///
|
|
|
|
/// By default, the source location and entity are ignored. Subclasses can
|
|
|
|
/// override this function to provide a customized implementation.
|
|
|
|
void setBase(SourceLocation Loc, DeclarationName Entity) { }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief RAII object that temporarily sets the base location and entity
|
|
|
|
/// used for reporting diagnostics in types.
|
|
|
|
class TemporaryBase {
|
|
|
|
TreeTransform &Self;
|
|
|
|
SourceLocation OldLocation;
|
|
|
|
DeclarationName OldEntity;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
public:
|
|
|
|
TemporaryBase(TreeTransform &Self, SourceLocation Location,
|
2009-09-09 19:08:12 +04:00
|
|
|
DeclarationName Entity) : Self(Self) {
|
2009-08-11 09:31:07 +04:00
|
|
|
OldLocation = Self.getDerived().getBaseLocation();
|
|
|
|
OldEntity = Self.getDerived().getBaseEntity();
|
|
|
|
Self.getDerived().setBase(Location, Entity);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
~TemporaryBase() {
|
|
|
|
Self.getDerived().setBase(OldLocation, OldEntity);
|
|
|
|
}
|
|
|
|
};
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
/// \brief Determine whether the given type \p T has already been
|
2009-08-04 20:50:30 +04:00
|
|
|
/// transformed.
|
|
|
|
///
|
|
|
|
/// Subclasses can provide an alternative implementation of this routine
|
2009-09-09 19:08:12 +04:00
|
|
|
/// to short-circuit evaluation when it is known that a given type will
|
2009-08-04 20:50:30 +04:00
|
|
|
/// not change. For example, template instantiation need not traverse
|
|
|
|
/// non-dependent types.
|
|
|
|
bool AlreadyTransformed(QualType T) {
|
|
|
|
return T.isNull();
|
|
|
|
}
|
|
|
|
|
2009-12-14 22:27:10 +03:00
|
|
|
/// \brief Determine whether the given call argument should be dropped, e.g.,
|
|
|
|
/// because it is a default argument.
|
|
|
|
///
|
|
|
|
/// Subclasses can provide an alternative implementation of this routine to
|
|
|
|
/// determine which kinds of call arguments get dropped. By default,
|
|
|
|
/// CXXDefaultArgument nodes are dropped (prior to transformation).
|
|
|
|
bool DropCallArgument(Expr *E) {
|
|
|
|
return E->isDefaultArgument();
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-12-21 01:05:00 +03:00
|
|
|
/// \brief Determine whether we should expand a pack expansion with the
|
|
|
|
/// given set of parameter packs into separate arguments by repeatedly
|
|
|
|
/// transforming the pattern.
|
|
|
|
///
|
2010-12-21 03:52:54 +03:00
|
|
|
/// By default, the transformer never tries to expand pack expansions.
|
2010-12-21 01:05:00 +03:00
|
|
|
/// Subclasses can override this routine to provide different behavior.
|
|
|
|
///
|
|
|
|
/// \param EllipsisLoc The location of the ellipsis that identifies the
|
|
|
|
/// pack expansion.
|
|
|
|
///
|
|
|
|
/// \param PatternRange The source range that covers the entire pattern of
|
|
|
|
/// the pack expansion.
|
|
|
|
///
|
|
|
|
/// \param Unexpanded The set of unexpanded parameter packs within the
|
|
|
|
/// pattern.
|
|
|
|
///
|
|
|
|
/// \param NumUnexpanded The number of unexpanded parameter packs in
|
|
|
|
/// \p Unexpanded.
|
|
|
|
///
|
|
|
|
/// \param ShouldExpand Will be set to \c true if the transformer should
|
|
|
|
/// expand the corresponding pack expansions into separate arguments. When
|
|
|
|
/// set, \c NumExpansions must also be set.
|
|
|
|
///
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
/// \param RetainExpansion Whether the caller should add an unexpanded
|
|
|
|
/// pack expansion after all of the expanded arguments. This is used
|
|
|
|
/// when extending explicitly-specified template argument packs per
|
|
|
|
/// C++0x [temp.arg.explicit]p9.
|
|
|
|
///
|
2010-12-21 01:05:00 +03:00
|
|
|
/// \param NumExpansions The number of separate arguments that will be in
|
2011-01-14 20:04:44 +03:00
|
|
|
/// the expanded form of the corresponding pack expansion. This is both an
|
|
|
|
/// input and an output parameter, which can be set by the caller if the
|
|
|
|
/// number of expansions is known a priori (e.g., due to a prior substitution)
|
|
|
|
/// and will be set by the callee when the number of expansions is known.
|
|
|
|
/// The callee must set this value when \c ShouldExpand is \c true; it may
|
|
|
|
/// set this value in other cases.
|
2010-12-21 01:05:00 +03:00
|
|
|
///
|
|
|
|
/// \returns true if an error occurred (e.g., because the parameter packs
|
|
|
|
/// are to be instantiated with arguments of different lengths), false
|
|
|
|
/// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
|
|
|
|
/// must be set.
|
|
|
|
bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
|
|
|
|
SourceRange PatternRange,
|
|
|
|
const UnexpandedParameterPack *Unexpanded,
|
|
|
|
unsigned NumUnexpanded,
|
|
|
|
bool &ShouldExpand,
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
bool &RetainExpansion,
|
2011-01-14 20:04:44 +03:00
|
|
|
llvm::Optional<unsigned> &NumExpansions) {
|
2010-12-21 01:05:00 +03:00
|
|
|
ShouldExpand = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
/// \brief "Forget" about the partially-substituted pack template argument,
|
|
|
|
/// when performing an instantiation that must preserve the parameter pack
|
|
|
|
/// use.
|
|
|
|
///
|
|
|
|
/// This routine is meant to be overridden by the template instantiator.
|
|
|
|
TemplateArgument ForgetPartiallySubstitutedPack() {
|
|
|
|
return TemplateArgument();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief "Remember" the partially-substituted pack template argument
|
|
|
|
/// after performing an instantiation that must preserve the parameter pack
|
|
|
|
/// use.
|
|
|
|
///
|
|
|
|
/// This routine is meant to be overridden by the template instantiator.
|
|
|
|
void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
|
|
|
|
|
Implement substitution of a function parameter pack for its set of
instantiated function parameters, enabling instantiation of arbitrary
pack expansions involving function parameter packs. At this point, we
can now correctly compile a simple, variadic print() example:
#include <iostream>
#include <string>
void print() {}
template<typename Head, typename ...Tail>
void print(const Head &head, const Tail &...tail) {
std::cout << head;
print(tail...);
}
int main() {
std::string hello = "Hello";
print(hello, ", world!", " ", 2011, '\n');
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123000 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-07 19:43:16 +03:00
|
|
|
/// \brief Note to the derived class when a function parameter pack is
|
|
|
|
/// being expanded.
|
|
|
|
void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Transforms the given type into another type.
|
|
|
|
///
|
2009-10-21 04:40:46 +04:00
|
|
|
/// By default, this routine transforms a type by creating a
|
2009-12-07 05:54:59 +03:00
|
|
|
/// TypeSourceInfo for it and delegating to the appropriate
|
2009-10-21 04:40:46 +04:00
|
|
|
/// function. This is expensive, but we don't mind, because
|
|
|
|
/// this method is deprecated anyway; all users should be
|
2009-12-07 05:54:59 +03:00
|
|
|
/// switched to storing TypeSourceInfos.
|
2009-08-04 20:50:30 +04:00
|
|
|
///
|
|
|
|
/// \returns the transformed type.
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType TransformType(QualType T);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
/// \brief Transforms the given type-with-location into a new
|
|
|
|
/// type-with-location.
|
|
|
|
///
|
|
|
|
/// By default, this routine transforms a type by delegating to the
|
|
|
|
/// appropriate TransformXXXType to build a new type. Subclasses
|
|
|
|
/// may override this function (to take over all type
|
|
|
|
/// transformations) or some set of the TransformXXXType functions
|
|
|
|
/// to alter the transformation.
|
2010-11-12 11:19:04 +03:00
|
|
|
TypeSourceInfo *TransformType(TypeSourceInfo *DI);
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
/// \brief Transform the given type-with-location into a new
|
|
|
|
/// type, collecting location information in the given builder
|
|
|
|
/// as necessary.
|
2009-08-04 20:50:30 +04:00
|
|
|
///
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-07 02:17:10 +04:00
|
|
|
/// \brief Transform the given statement.
|
2009-08-04 20:50:30 +04:00
|
|
|
///
|
2009-09-09 19:08:12 +04:00
|
|
|
/// By default, this routine transforms a statement by delegating to the
|
2009-08-20 11:17:43 +04:00
|
|
|
/// appropriate TransformXXXStmt function to transform a specific kind of
|
|
|
|
/// statement or the TransformExpr() function to transform an expression.
|
|
|
|
/// Subclasses may override this function to transform statements using some
|
|
|
|
/// other mechanism.
|
|
|
|
///
|
|
|
|
/// \returns the transformed statement.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult TransformStmt(Stmt *S);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-07 02:17:10 +04:00
|
|
|
/// \brief Transform the given expression.
|
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, this routine transforms an expression by delegating to the
|
|
|
|
/// appropriate TransformXXXExpr function to build a new expression.
|
|
|
|
/// Subclasses may override this function to transform expressions using some
|
|
|
|
/// other mechanism.
|
|
|
|
///
|
|
|
|
/// \returns the transformed expression.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult TransformExpr(Expr *E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-03 22:04:46 +03:00
|
|
|
/// \brief Transform the given list of expressions.
|
|
|
|
///
|
|
|
|
/// This routine transforms a list of expressions by invoking
|
|
|
|
/// \c TransformExpr() for each subexpression. However, it also provides
|
|
|
|
/// support for variadic templates by expanding any pack expansions (if the
|
|
|
|
/// derived class permits such expansion) along the way. When pack expansions
|
|
|
|
/// are present, the number of outputs may not equal the number of inputs.
|
|
|
|
///
|
|
|
|
/// \param Inputs The set of expressions to be transformed.
|
|
|
|
///
|
|
|
|
/// \param NumInputs The number of expressions in \c Inputs.
|
|
|
|
///
|
|
|
|
/// \param IsCall If \c true, then this transform is being performed on
|
|
|
|
/// function-call arguments, and any arguments that should be dropped, will
|
|
|
|
/// be.
|
|
|
|
///
|
|
|
|
/// \param Outputs The transformed input expressions will be added to this
|
|
|
|
/// vector.
|
|
|
|
///
|
|
|
|
/// \param ArgChanged If non-NULL, will be set \c true if any argument changed
|
|
|
|
/// due to transformation.
|
|
|
|
///
|
|
|
|
/// \returns true if an error occurred, false otherwise.
|
|
|
|
bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
|
|
|
|
llvm::SmallVectorImpl<Expr *> &Outputs,
|
|
|
|
bool *ArgChanged = 0);
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Transform the given declaration, which is referenced from a type
|
|
|
|
/// or expression.
|
|
|
|
///
|
2009-08-06 09:28:30 +04:00
|
|
|
/// By default, acts as the identity function on declarations. Subclasses
|
|
|
|
/// may override this function to provide alternate behavior.
|
2010-03-01 18:56:25 +03:00
|
|
|
Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
|
2009-08-20 11:17:43 +04:00
|
|
|
|
|
|
|
/// \brief Transform the definition of the given declaration.
|
|
|
|
///
|
2009-09-09 19:08:12 +04:00
|
|
|
/// By default, invokes TransformDecl() to transform the declaration.
|
2009-08-20 11:17:43 +04:00
|
|
|
/// Subclasses may override this function to provide alternate behavior.
|
2010-05-05 19:23:54 +04:00
|
|
|
Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
|
|
|
|
return getDerived().TransformDecl(Loc, D);
|
2010-03-01 18:56:25 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-20 09:58:46 +04:00
|
|
|
/// \brief Transform the given declaration, which was the first part of a
|
|
|
|
/// nested-name-specifier in a member access expression.
|
|
|
|
///
|
2010-05-05 19:23:54 +04:00
|
|
|
/// This specific declaration transformation only applies to the first
|
2009-10-20 09:58:46 +04:00
|
|
|
/// identifier in a nested-name-specifier of a member access expression, e.g.,
|
|
|
|
/// the \c T in \c x->T::member
|
|
|
|
///
|
|
|
|
/// By default, invokes TransformDecl() to transform the declaration.
|
|
|
|
/// Subclasses may override this function to provide alternate behavior.
|
2010-05-05 19:23:54 +04:00
|
|
|
NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
|
|
|
|
return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
|
2009-10-20 09:58:46 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Transform the given nested-name-specifier.
|
|
|
|
///
|
2009-09-09 19:08:12 +04:00
|
|
|
/// By default, transforms all of the types and declarations within the
|
2009-08-06 09:28:30 +04:00
|
|
|
/// nested-name-specifier. Subclasses may override this function to provide
|
|
|
|
/// alternate behavior.
|
2009-08-04 20:50:30 +04:00
|
|
|
NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
|
2009-09-03 20:14:30 +04:00
|
|
|
SourceRange Range,
|
2009-09-04 01:38:09 +04:00
|
|
|
QualType ObjectType = QualType(),
|
|
|
|
NamedDecl *FirstQualifierInScope = 0);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-09-04 02:13:48 +04:00
|
|
|
/// \brief Transform the given declaration name.
|
|
|
|
///
|
|
|
|
/// By default, transforms the types of conversion function, constructor,
|
|
|
|
/// and destructor names and then (if needed) rebuilds the declaration name.
|
|
|
|
/// Identifiers and selectors are returned unmodified. Sublcasses may
|
|
|
|
/// override this function to provide alternate behavior.
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationNameInfo
|
2010-11-12 11:19:04 +03:00
|
|
|
TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Transform the given template name.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-06 10:41:21 +04:00
|
|
|
/// By default, transforms the template name by transforming the declarations
|
2009-09-09 19:08:12 +04:00
|
|
|
/// and nested-name-specifiers that occur within the template name.
|
2009-08-06 10:41:21 +04:00
|
|
|
/// Subclasses may override this function to provide alternate behavior.
|
2009-09-09 04:23:06 +04:00
|
|
|
TemplateName TransformTemplateName(TemplateName Name,
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType ObjectType = QualType(),
|
|
|
|
NamedDecl *FirstQualifierInScope = 0);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Transform the given template argument.
|
|
|
|
///
|
2009-09-09 19:08:12 +04:00
|
|
|
/// By default, this operation transforms the type, expression, or
|
|
|
|
/// declaration stored within the template argument and constructs a
|
2009-08-05 02:27:00 +04:00
|
|
|
/// new template argument from the transformed result. Subclasses may
|
|
|
|
/// override this function to provide alternate behavior.
|
2009-10-29 11:12:44 +03:00
|
|
|
///
|
|
|
|
/// Returns true if there was an error.
|
|
|
|
bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
|
|
|
|
TemplateArgumentLoc &Output);
|
|
|
|
|
2010-12-20 20:31:10 +03:00
|
|
|
/// \brief Transform the given set of template arguments.
|
|
|
|
///
|
|
|
|
/// By default, this operation transforms all of the template arguments
|
|
|
|
/// in the input set using \c TransformTemplateArgument(), and appends
|
|
|
|
/// the transformed arguments to the output list.
|
|
|
|
///
|
2010-12-21 02:36:19 +03:00
|
|
|
/// Note that this overload of \c TransformTemplateArguments() is merely
|
|
|
|
/// a convenience function. Subclasses that wish to override this behavior
|
|
|
|
/// should override the iterator-based member template version.
|
|
|
|
///
|
2010-12-20 20:31:10 +03:00
|
|
|
/// \param Inputs The set of template arguments to be transformed.
|
|
|
|
///
|
|
|
|
/// \param NumInputs The number of template arguments in \p Inputs.
|
|
|
|
///
|
|
|
|
/// \param Outputs The set of transformed template arguments output by this
|
|
|
|
/// routine.
|
|
|
|
///
|
|
|
|
/// Returns true if an error occurred.
|
|
|
|
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
|
|
|
|
unsigned NumInputs,
|
2010-12-21 02:36:19 +03:00
|
|
|
TemplateArgumentListInfo &Outputs) {
|
|
|
|
return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
|
|
|
|
}
|
2010-12-20 20:42:22 +03:00
|
|
|
|
|
|
|
/// \brief Transform the given set of template arguments.
|
|
|
|
///
|
|
|
|
/// By default, this operation transforms all of the template arguments
|
|
|
|
/// in the input set using \c TransformTemplateArgument(), and appends
|
|
|
|
/// the transformed arguments to the output list.
|
|
|
|
///
|
2010-12-21 02:36:19 +03:00
|
|
|
/// \param First An iterator to the first template argument.
|
|
|
|
///
|
|
|
|
/// \param Last An iterator one step past the last template argument.
|
2010-12-20 20:42:22 +03:00
|
|
|
///
|
|
|
|
/// \param Outputs The set of transformed template arguments output by this
|
|
|
|
/// routine.
|
|
|
|
///
|
|
|
|
/// Returns true if an error occurred.
|
2010-12-21 02:36:19 +03:00
|
|
|
template<typename InputIterator>
|
|
|
|
bool TransformTemplateArguments(InputIterator First,
|
|
|
|
InputIterator Last,
|
|
|
|
TemplateArgumentListInfo &Outputs);
|
2010-12-20 20:42:22 +03:00
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
/// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
|
|
|
|
void InventTemplateArgumentLoc(const TemplateArgument &Arg,
|
|
|
|
TemplateArgumentLoc &ArgLoc);
|
|
|
|
|
2009-12-07 05:54:59 +03:00
|
|
|
/// \brief Fakes up a TypeSourceInfo for a type.
|
|
|
|
TypeSourceInfo *InventTypeSourceInfo(QualType T) {
|
|
|
|
return SemaRef.Context.getTrivialTypeSourceInfo(T,
|
2009-10-29 11:12:44 +03:00
|
|
|
getDerived().getBaseLocation());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
#define ABSTRACT_TYPELOC(CLASS, PARENT)
|
|
|
|
#define TYPELOC(CLASS, PARENT) \
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
|
2009-10-21 04:40:46 +04:00
|
|
|
#include "clang/AST/TypeLocNodes.def"
|
2009-08-04 20:50:30 +04:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType
|
|
|
|
TransformTemplateSpecializationType(TypeLocBuilder &TLB,
|
|
|
|
TemplateSpecializationTypeLoc TL,
|
|
|
|
TemplateName Template);
|
|
|
|
|
|
|
|
QualType
|
|
|
|
TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
|
|
|
|
DependentTemplateSpecializationTypeLoc TL,
|
|
|
|
NestedNameSpecifier *Prefix);
|
|
|
|
|
2010-03-11 12:03:00 +03:00
|
|
|
/// \brief Transforms the parameters of a function type into the
|
|
|
|
/// given vectors.
|
|
|
|
///
|
|
|
|
/// The result vectors should be kept in sync; null entries in the
|
|
|
|
/// variables vector are acceptable.
|
|
|
|
///
|
|
|
|
/// Return true on error.
|
2011-01-07 03:20:55 +03:00
|
|
|
bool TransformFunctionTypeParams(SourceLocation Loc,
|
|
|
|
ParmVarDecl **Params, unsigned NumParams,
|
|
|
|
const QualType *ParamTypes,
|
2010-03-11 12:03:00 +03:00
|
|
|
llvm::SmallVectorImpl<QualType> &PTypes,
|
2011-01-07 03:20:55 +03:00
|
|
|
llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
|
2010-03-11 12:03:00 +03:00
|
|
|
|
|
|
|
/// \brief Transforms a single function-type parameter. Return null
|
|
|
|
/// on error.
|
2011-01-15 01:40:04 +03:00
|
|
|
ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
|
|
|
|
llvm::Optional<unsigned> NumExpansions);
|
2010-03-11 12:03:00 +03:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
|
2009-10-29 11:12:44 +03:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
|
|
|
|
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
#define STMT(Node, Parent) \
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Transform##Node(Node *S);
|
2009-08-11 09:31:07 +04:00
|
|
|
#define EXPR(Node, Parent) \
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Transform##Node(Node *E);
|
2010-05-18 10:22:21 +04:00
|
|
|
#define ABSTRACT_STMT(Stmt)
|
2010-05-05 19:24:00 +04:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new pointer type given its pointee type.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the pointer type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2009-10-30 03:06:24 +03:00
|
|
|
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
|
2009-08-04 20:50:30 +04:00
|
|
|
|
|
|
|
/// \brief Build a new block pointer type given its pointee type.
|
|
|
|
///
|
2009-09-09 19:08:12 +04:00
|
|
|
/// By default, performs semantic analysis when building the block pointer
|
2009-08-04 20:50:30 +04:00
|
|
|
/// type. Subclasses may override this routine to provide different behavior.
|
2009-10-30 03:06:24 +03:00
|
|
|
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
|
2009-08-04 20:50:30 +04:00
|
|
|
|
2009-10-30 03:06:24 +03:00
|
|
|
/// \brief Build a new reference type given the type it references.
|
2009-08-04 20:50:30 +04:00
|
|
|
///
|
2009-10-30 03:06:24 +03:00
|
|
|
/// By default, performs semantic analysis when building the
|
|
|
|
/// reference type. Subclasses may override this routine to provide
|
|
|
|
/// different behavior.
|
2009-08-04 20:50:30 +04:00
|
|
|
///
|
2009-10-30 03:06:24 +03:00
|
|
|
/// \param LValue whether the type was written with an lvalue sigil
|
|
|
|
/// or an rvalue sigil.
|
|
|
|
QualType RebuildReferenceType(QualType ReferentType,
|
|
|
|
bool LValue,
|
|
|
|
SourceLocation Sigil);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new member pointer type given the pointee type and the
|
|
|
|
/// class type it refers into.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the member pointer
|
|
|
|
/// type. Subclasses may override this routine to provide different behavior.
|
2009-10-30 03:06:24 +03:00
|
|
|
QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
|
|
|
|
SourceLocation Sigil);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new array type given the element type, size
|
|
|
|
/// modifier, size of the array (if known), size expression, and index type
|
|
|
|
/// qualifiers.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the array type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2009-09-09 19:08:12 +04:00
|
|
|
/// Also by default, all of the other Rebuild*Array
|
2009-08-04 20:50:30 +04:00
|
|
|
QualType RebuildArrayType(QualType ElementType,
|
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
|
|
|
const llvm::APInt *Size,
|
|
|
|
Expr *SizeExpr,
|
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new constant array type given the element type, size
|
|
|
|
/// modifier, (known) size of the array, and index type qualifiers.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the array type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType RebuildConstantArrayType(QualType ElementType,
|
2009-08-04 20:50:30 +04:00
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
|
|
|
const llvm::APInt &Size,
|
2009-10-30 03:06:24 +03:00
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange);
|
2009-08-04 20:50:30 +04:00
|
|
|
|
|
|
|
/// \brief Build a new incomplete array type given the element type, size
|
|
|
|
/// modifier, and index type qualifiers.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the array type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType RebuildIncompleteArrayType(QualType ElementType,
|
2009-08-04 20:50:30 +04:00
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
2009-10-30 03:06:24 +03:00
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange);
|
2009-08-04 20:50:30 +04:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// \brief Build a new variable-length array type given the element type,
|
2009-08-04 20:50:30 +04:00
|
|
|
/// size modifier, size expression, and index type qualifiers.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the array type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType RebuildVariableArrayType(QualType ElementType,
|
2009-08-04 20:50:30 +04:00
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SizeExpr,
|
2009-08-04 20:50:30 +04:00
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange);
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// \brief Build a new dependent-sized array type given the element type,
|
2009-08-04 20:50:30 +04:00
|
|
|
/// size modifier, size expression, and index type qualifiers.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the array type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType RebuildDependentSizedArrayType(QualType ElementType,
|
2009-08-04 20:50:30 +04:00
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SizeExpr,
|
2009-08-04 20:50:30 +04:00
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange);
|
|
|
|
|
|
|
|
/// \brief Build a new vector type given the element type and
|
|
|
|
/// number of elements.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the vector type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-02-05 03:12:22 +03:00
|
|
|
QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
|
2010-11-11 00:56:12 +03:00
|
|
|
VectorType::VectorKind VecKind);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new extended vector type given the element type and
|
|
|
|
/// number of elements.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the vector type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
|
|
|
|
SourceLocation AttributeLoc);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
/// \brief Build a new potentially dependently-sized extended vector type
|
2009-08-04 20:50:30 +04:00
|
|
|
/// given the element type and number of elements.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the vector type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType RebuildDependentSizedExtVectorType(QualType ElementType,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SizeExpr,
|
2009-08-04 20:50:30 +04:00
|
|
|
SourceLocation AttributeLoc);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new function type.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the function type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
QualType RebuildFunctionProtoType(QualType T,
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType *ParamTypes,
|
2009-08-04 20:50:30 +04:00
|
|
|
unsigned NumParamTypes,
|
2010-08-05 06:54:05 +04:00
|
|
|
bool Variadic, unsigned Quals,
|
|
|
|
const FunctionType::ExtInfo &Info);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
/// \brief Build a new unprototyped function type.
|
|
|
|
QualType RebuildFunctionNoProtoType(QualType ResultType);
|
|
|
|
|
2009-12-05 01:46:56 +03:00
|
|
|
/// \brief Rebuild an unresolved typename type, given the decl that
|
|
|
|
/// the UnresolvedUsingTypenameDecl was transformed to.
|
|
|
|
QualType RebuildUnresolvedUsingType(Decl *D);
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new typedef type.
|
|
|
|
QualType RebuildTypedefType(TypedefDecl *Typedef) {
|
|
|
|
return SemaRef.Context.getTypeDeclType(Typedef);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new class/struct/union type.
|
|
|
|
QualType RebuildRecordType(RecordDecl *Record) {
|
|
|
|
return SemaRef.Context.getTypeDeclType(Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new Enum type.
|
|
|
|
QualType RebuildEnumType(EnumDecl *Enum) {
|
|
|
|
return SemaRef.Context.getTypeDeclType(Enum);
|
|
|
|
}
|
2009-09-05 04:15:47 +04:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// \brief Build a new typeof(expr) type.
|
2009-08-04 20:50:30 +04:00
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the typeof type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-10-12 04:20:44 +04:00
|
|
|
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
|
2009-08-04 20:50:30 +04:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// \brief Build a new typeof(type) type.
|
2009-08-04 20:50:30 +04:00
|
|
|
///
|
|
|
|
/// By default, builds a new TypeOfType with the given underlying type.
|
|
|
|
QualType RebuildTypeOfType(QualType Underlying);
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// \brief Build a new C++0x decltype type.
|
2009-08-04 20:50:30 +04:00
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the decltype type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-10-12 04:20:44 +04:00
|
|
|
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new template specialization type.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the template
|
|
|
|
/// specialization type. Subclasses may override this routine to provide
|
|
|
|
/// different behavior.
|
|
|
|
QualType RebuildTemplateSpecializationType(TemplateName Template,
|
2009-10-29 11:12:44 +03:00
|
|
|
SourceLocation TemplateLoc,
|
2009-11-23 04:53:49 +03:00
|
|
|
const TemplateArgumentListInfo &Args);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-12-10 19:29:40 +03:00
|
|
|
/// \brief Build a new parenthesized type.
|
|
|
|
///
|
|
|
|
/// By default, builds a new ParenType type from the inner type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
QualType RebuildParenType(QualType InnerType) {
|
|
|
|
return SemaRef.Context.getParenType(InnerType);
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
/// \brief Build a new qualified name type.
|
|
|
|
///
|
2010-05-12 01:36:43 +04:00
|
|
|
/// By default, builds a new ElaboratedType type from the keyword,
|
|
|
|
/// the nested-name-specifier and the named type.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-11-04 22:04:38 +03:00
|
|
|
QualType RebuildElaboratedType(SourceLocation KeywordLoc,
|
|
|
|
ElaboratedTypeKeyword Keyword,
|
2010-05-12 01:36:43 +04:00
|
|
|
NestedNameSpecifier *NNS, QualType Named) {
|
|
|
|
return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
2009-08-04 20:50:30 +04:00
|
|
|
|
|
|
|
/// \brief Build a new typename type that refers to a template-id.
|
|
|
|
///
|
2010-05-20 01:37:53 +04:00
|
|
|
/// By default, builds a new DependentNameType type from the
|
|
|
|
/// nested-name-specifier and the given type. Subclasses may override
|
|
|
|
/// this routine to provide different behavior.
|
2010-06-11 04:33:02 +04:00
|
|
|
QualType RebuildDependentTemplateSpecializationType(
|
|
|
|
ElaboratedTypeKeyword Keyword,
|
2010-09-09 03:56:00 +04:00
|
|
|
NestedNameSpecifier *Qualifier,
|
|
|
|
SourceRange QualifierRange,
|
2010-06-11 04:33:02 +04:00
|
|
|
const IdentifierInfo *Name,
|
|
|
|
SourceLocation NameLoc,
|
|
|
|
const TemplateArgumentListInfo &Args) {
|
|
|
|
// Rebuild the template name.
|
|
|
|
// TODO: avoid TemplateName abstraction
|
|
|
|
TemplateName InstName =
|
2010-09-09 03:56:00 +04:00
|
|
|
getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType(), 0);
|
2010-06-11 04:33:02 +04:00
|
|
|
|
2010-06-19 02:12:56 +04:00
|
|
|
if (InstName.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
2010-06-11 04:33:02 +04:00
|
|
|
// If it's still dependent, make a dependent specialization.
|
|
|
|
if (InstName.getAsDependentTemplateName())
|
|
|
|
return SemaRef.Context.getDependentTemplateSpecializationType(
|
2010-09-09 03:56:00 +04:00
|
|
|
Keyword, Qualifier, Name, Args);
|
2010-06-11 04:33:02 +04:00
|
|
|
|
|
|
|
// Otherwise, make an elaborated type wrapping a non-dependent
|
|
|
|
// specialization.
|
|
|
|
QualType T =
|
|
|
|
getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
|
|
|
|
if (T.isNull()) return QualType();
|
2010-05-12 01:36:43 +04:00
|
|
|
|
2010-08-10 17:46:45 +04:00
|
|
|
// NOTE: NNS is already recorded in template specialization type T.
|
|
|
|
return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
2009-08-04 20:50:30 +04:00
|
|
|
|
|
|
|
/// \brief Build a new typename type that refers to an identifier.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the typename type
|
2010-05-20 01:37:53 +04:00
|
|
|
/// (or elaborated type). Subclasses may override this routine to provide
|
2009-08-04 20:50:30 +04:00
|
|
|
/// different behavior.
|
2010-05-20 01:37:53 +04:00
|
|
|
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
|
2010-04-01 00:19:30 +04:00
|
|
|
NestedNameSpecifier *NNS,
|
|
|
|
const IdentifierInfo *Id,
|
2010-05-20 01:37:53 +04:00
|
|
|
SourceLocation KeywordLoc,
|
|
|
|
SourceRange NNSRange,
|
|
|
|
SourceLocation IdLoc) {
|
2010-04-01 02:19:08 +04:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
SS.setScopeRep(NNS);
|
2010-05-20 01:37:53 +04:00
|
|
|
SS.setRange(NNSRange);
|
|
|
|
|
2010-04-01 02:19:08 +04:00
|
|
|
if (NNS->isDependent()) {
|
|
|
|
// If the name is still dependent, just build a new dependent name type.
|
|
|
|
if (!SemaRef.computeDeclContext(SS))
|
|
|
|
return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
|
|
|
|
}
|
|
|
|
|
2010-05-12 01:36:43 +04:00
|
|
|
if (Keyword == ETK_None || Keyword == ETK_Typename)
|
2010-05-20 01:37:53 +04:00
|
|
|
return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
|
|
|
|
KeywordLoc, NNSRange, IdLoc);
|
2010-05-12 01:36:43 +04:00
|
|
|
|
|
|
|
TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
|
|
|
|
|
2010-05-20 01:37:53 +04:00
|
|
|
// We had a dependent elaborated-type-specifier that has been transformed
|
2010-04-01 02:19:08 +04:00
|
|
|
// into a non-dependent elaborated-type-specifier. Find the tag we're
|
|
|
|
// referring to.
|
2010-05-20 01:37:53 +04:00
|
|
|
LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
|
2010-04-01 02:19:08 +04:00
|
|
|
DeclContext *DC = SemaRef.computeDeclContext(SS, false);
|
|
|
|
if (!DC)
|
|
|
|
return QualType();
|
|
|
|
|
2010-05-27 10:40:31 +04:00
|
|
|
if (SemaRef.RequireCompleteDeclContext(SS, DC))
|
|
|
|
return QualType();
|
|
|
|
|
2010-04-01 02:19:08 +04:00
|
|
|
TagDecl *Tag = 0;
|
|
|
|
SemaRef.LookupQualifiedName(Result, DC);
|
|
|
|
switch (Result.getResultKind()) {
|
|
|
|
case LookupResult::NotFound:
|
|
|
|
case LookupResult::NotFoundInCurrentInstantiation:
|
|
|
|
break;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-01 02:19:08 +04:00
|
|
|
case LookupResult::Found:
|
|
|
|
Tag = Result.getAsSingle<TagDecl>();
|
|
|
|
break;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-01 02:19:08 +04:00
|
|
|
case LookupResult::FoundOverloaded:
|
|
|
|
case LookupResult::FoundUnresolvedValue:
|
|
|
|
llvm_unreachable("Tag lookup cannot find non-tags");
|
|
|
|
return QualType();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-01 02:19:08 +04:00
|
|
|
case LookupResult::Ambiguous:
|
|
|
|
// Let the LookupResult structure handle ambiguities.
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Tag) {
|
2010-04-01 03:17:41 +04:00
|
|
|
// FIXME: Would be nice to highlight just the source range.
|
2010-05-20 01:37:53 +04:00
|
|
|
SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
|
2010-04-01 03:17:41 +04:00
|
|
|
<< Kind << Id << DC;
|
2010-04-01 02:19:08 +04:00
|
|
|
return QualType();
|
|
|
|
}
|
2010-05-12 01:36:43 +04:00
|
|
|
|
2010-05-20 01:37:53 +04:00
|
|
|
if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
|
|
|
|
SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
|
2010-04-01 02:19:08 +04:00
|
|
|
SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the elaborated-type-specifier type.
|
|
|
|
QualType T = SemaRef.Context.getTypeDeclType(Tag);
|
2010-05-12 01:36:43 +04:00
|
|
|
return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
|
2009-08-06 09:28:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-12 20:07:58 +03:00
|
|
|
/// \brief Build a new pack expansion type.
|
|
|
|
///
|
|
|
|
/// By default, builds a new PackExpansionType type from the given pattern.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
QualType RebuildPackExpansionType(QualType Pattern,
|
|
|
|
SourceRange PatternRange,
|
2011-01-14 20:04:44 +03:00
|
|
|
SourceLocation EllipsisLoc,
|
|
|
|
llvm::Optional<unsigned> NumExpansions) {
|
|
|
|
return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
|
|
|
|
NumExpansions);
|
2011-01-12 20:07:58 +03:00
|
|
|
}
|
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
/// \brief Build a new nested-name-specifier given the prefix and an
|
|
|
|
/// identifier that names the next step in the nested-name-specifier.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the new
|
|
|
|
/// nested-name-specifier. Subclasses may override this routine to provide
|
|
|
|
/// different behavior.
|
|
|
|
NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
|
|
|
|
SourceRange Range,
|
2009-09-03 20:14:30 +04:00
|
|
|
IdentifierInfo &II,
|
2009-09-04 01:38:09 +04:00
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *FirstQualifierInScope);
|
2009-08-06 09:28:30 +04:00
|
|
|
|
|
|
|
/// \brief Build a new nested-name-specifier given the prefix and the
|
|
|
|
/// namespace named in the next step in the nested-name-specifier.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the new
|
|
|
|
/// nested-name-specifier. Subclasses may override this routine to provide
|
|
|
|
/// different behavior.
|
|
|
|
NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
|
|
|
|
SourceRange Range,
|
|
|
|
NamespaceDecl *NS);
|
|
|
|
|
|
|
|
/// \brief Build a new nested-name-specifier given the prefix and the
|
|
|
|
/// type named in the next step in the nested-name-specifier.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis when building the new
|
|
|
|
/// nested-name-specifier. Subclasses may override this routine to provide
|
|
|
|
/// different behavior.
|
|
|
|
NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
|
|
|
|
SourceRange Range,
|
|
|
|
bool TemplateKW,
|
2010-02-25 07:46:04 +03:00
|
|
|
QualType T);
|
2009-08-06 10:41:21 +04:00
|
|
|
|
|
|
|
/// \brief Build a new template name given a nested name specifier, a flag
|
|
|
|
/// indicating whether the "template" keyword was provided, and the template
|
|
|
|
/// that the template name refers to.
|
|
|
|
///
|
|
|
|
/// By default, builds the new template name directly. Subclasses may override
|
|
|
|
/// this routine to provide different behavior.
|
|
|
|
TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
|
|
|
|
bool TemplateKW,
|
|
|
|
TemplateDecl *Template);
|
|
|
|
|
|
|
|
/// \brief Build a new template name given a nested name specifier and the
|
|
|
|
/// name that is referred to as a template.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to determine whether the name can
|
|
|
|
/// be resolved to a specific template, then builds the appropriate kind of
|
|
|
|
/// template name. Subclasses may override this routine to provide different
|
|
|
|
/// behavior.
|
|
|
|
TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
|
2010-09-09 03:56:00 +04:00
|
|
|
SourceRange QualifierRange,
|
2009-09-09 04:23:06 +04:00
|
|
|
const IdentifierInfo &II,
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *FirstQualifierInScope);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-04 03:56:37 +03:00
|
|
|
/// \brief Build a new template name given a nested name specifier and the
|
|
|
|
/// overloaded operator name that is referred to as a template.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to determine whether the name can
|
|
|
|
/// be resolved to a specific template, then builds the appropriate kind of
|
|
|
|
/// template name. Subclasses may override this routine to provide different
|
|
|
|
/// behavior.
|
|
|
|
TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
|
|
|
|
OverloadedOperatorKind Operator,
|
|
|
|
QualType ObjectType);
|
2011-01-15 09:45:20 +03:00
|
|
|
|
|
|
|
/// \brief Build a new template name given a template template parameter pack
|
|
|
|
/// and the
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to determine whether the name can
|
|
|
|
/// be resolved to a specific template, then builds the appropriate kind of
|
|
|
|
/// template name. Subclasses may override this routine to provide different
|
|
|
|
/// behavior.
|
|
|
|
TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
|
|
|
|
const TemplateArgument &ArgPack) {
|
|
|
|
return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new compound statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
|
2009-08-20 11:17:43 +04:00
|
|
|
MultiStmtArg Statements,
|
|
|
|
SourceLocation RBraceLoc,
|
|
|
|
bool IsStmtExpr) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
|
2009-08-20 11:17:43 +04:00
|
|
|
IsStmtExpr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new case statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *LHS,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation EllipsisLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *RHS,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation ColonLoc) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
|
2009-08-20 11:17:43 +04:00
|
|
|
ColonLoc);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Attach the body to a new case statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
|
2010-08-24 03:25:46 +04:00
|
|
|
getSema().ActOnCaseStmtBody(S, Body);
|
|
|
|
return S;
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new default statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation ColonLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *SubStmt) {
|
|
|
|
return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
|
2009-08-20 11:17:43 +04:00
|
|
|
/*CurScope=*/0);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new label statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
|
2009-08-20 11:17:43 +04:00
|
|
|
IdentifierInfo *Id,
|
|
|
|
SourceLocation ColonLoc,
|
2010-09-28 18:54:07 +04:00
|
|
|
Stmt *SubStmt, bool HasUnusedAttr) {
|
|
|
|
return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
|
|
|
|
HasUnusedAttr);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new "if" statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
|
2010-11-20 05:04:01 +03:00
|
|
|
VarDecl *CondVar, Stmt *Then,
|
2010-08-24 03:25:46 +04:00
|
|
|
SourceLocation ElseLoc, Stmt *Else) {
|
2010-11-20 05:04:01 +03:00
|
|
|
return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Start building a new switch statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Cond, VarDecl *CondVar) {
|
|
|
|
return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
|
2010-08-21 13:40:31 +04:00
|
|
|
CondVar);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Attach the body to the switch statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *Switch, Stmt *Body) {
|
|
|
|
return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new while statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
|
2010-05-09 02:20:28 +04:00
|
|
|
Sema::FullExprArg Cond,
|
2009-11-25 03:27:52 +03:00
|
|
|
VarDecl *CondVar,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *Body) {
|
|
|
|
return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new do-while statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation WhileLoc,
|
|
|
|
SourceLocation LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Cond,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
|
|
|
|
Cond, RParenLoc);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new for statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildForStmt(SourceLocation ForLoc,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *Init, Sema::FullExprArg Cond,
|
2009-11-25 03:27:52 +03:00
|
|
|
VarDecl *CondVar, Sema::FullExprArg Inc,
|
2010-08-24 03:25:46 +04:00
|
|
|
SourceLocation RParenLoc, Stmt *Body) {
|
|
|
|
return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
|
2010-08-21 13:40:31 +04:00
|
|
|
CondVar,
|
2010-08-24 03:25:46 +04:00
|
|
|
Inc, RParenLoc, Body);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new goto statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation LabelLoc,
|
|
|
|
LabelStmt *Label) {
|
|
|
|
return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new indirect goto statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation StarLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Target) {
|
|
|
|
return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new return statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Result) {
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnReturnStmt(ReturnLoc, Result);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new declaration statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation StartLoc,
|
2009-08-20 11:17:43 +04:00
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return getSema().Owned(
|
|
|
|
new (getSema().Context) DeclStmt(
|
|
|
|
DeclGroupRef::Create(getSema().Context,
|
|
|
|
Decls, NumDecls),
|
|
|
|
StartLoc, EndLoc));
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
/// \brief Build a new inline asm statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
|
2010-01-24 08:50:09 +03:00
|
|
|
bool IsSimple,
|
|
|
|
bool IsVolatile,
|
|
|
|
unsigned NumOutputs,
|
|
|
|
unsigned NumInputs,
|
2010-01-31 01:25:16 +03:00
|
|
|
IdentifierInfo **Names,
|
2010-01-24 08:50:09 +03:00
|
|
|
MultiExprArg Constraints,
|
|
|
|
MultiExprArg Exprs,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *AsmString,
|
2010-01-24 08:50:09 +03:00
|
|
|
MultiExprArg Clobbers,
|
|
|
|
SourceLocation RParenLoc,
|
|
|
|
bool MSAsm) {
|
2010-05-05 19:23:54 +04:00
|
|
|
return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
|
2010-01-24 08:50:09 +03:00
|
|
|
NumInputs, Names, move(Constraints),
|
2010-08-24 03:25:46 +04:00
|
|
|
Exprs, AsmString, Clobbers,
|
2010-01-24 08:50:09 +03:00
|
|
|
RParenLoc, MSAsm);
|
|
|
|
}
|
2010-04-23 03:59:56 +04:00
|
|
|
|
|
|
|
/// \brief Build a new Objective-C @try statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *TryBody,
|
2010-04-24 02:50:49 +04:00
|
|
|
MultiStmtArg CatchStmts,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *Finally) {
|
|
|
|
return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
|
|
|
|
Finally);
|
2010-04-23 03:59:56 +04:00
|
|
|
}
|
|
|
|
|
2010-04-26 21:57:08 +04:00
|
|
|
/// \brief Rebuild an Objective-C exception declaration.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new declaration.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
|
|
|
|
TypeSourceInfo *TInfo, QualType T) {
|
2010-05-05 19:23:54 +04:00
|
|
|
return getSema().BuildObjCExceptionDecl(TInfo, T,
|
|
|
|
ExceptionDecl->getIdentifier(),
|
2010-04-26 21:57:08 +04:00
|
|
|
ExceptionDecl->getLocation());
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-26 21:57:08 +04:00
|
|
|
/// \brief Build a new Objective-C @catch statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
|
2010-04-26 21:57:08 +04:00
|
|
|
SourceLocation RParenLoc,
|
|
|
|
VarDecl *Var,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *Body) {
|
2010-04-26 21:57:08 +04:00
|
|
|
return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Var, Body);
|
2010-04-26 21:57:08 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 03:59:56 +04:00
|
|
|
/// \brief Build a new Objective-C @finally statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *Body) {
|
|
|
|
return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
|
2010-04-23 03:59:56 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 02:01:21 +04:00
|
|
|
/// \brief Build a new Objective-C @throw statement.
|
2010-04-23 01:44:01 +04:00
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Operand) {
|
|
|
|
return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
|
2010-04-23 01:44:01 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 02:01:21 +04:00
|
|
|
/// \brief Build a new Objective-C @synchronized statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Object,
|
|
|
|
Stmt *Body) {
|
|
|
|
return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
|
|
|
|
Body);
|
2010-04-23 02:01:21 +04:00
|
|
|
}
|
2010-04-23 03:10:45 +04:00
|
|
|
|
|
|
|
/// \brief Build a new Objective-C fast enumeration statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
|
2010-08-27 03:41:50 +04:00
|
|
|
SourceLocation LParenLoc,
|
|
|
|
Stmt *Element,
|
|
|
|
Expr *Collection,
|
|
|
|
SourceLocation RParenLoc,
|
|
|
|
Stmt *Body) {
|
2010-04-23 03:10:45 +04:00
|
|
|
return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Element,
|
|
|
|
Collection,
|
2010-04-23 03:10:45 +04:00
|
|
|
RParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Body);
|
2010-04-23 03:10:45 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new C++ exception declaration.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new decaration.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-09-09 21:09:21 +04:00
|
|
|
VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
|
2009-12-07 05:54:59 +03:00
|
|
|
TypeSourceInfo *Declarator,
|
2009-08-20 11:17:43 +04:00
|
|
|
IdentifierInfo *Name,
|
2010-09-09 21:09:21 +04:00
|
|
|
SourceLocation Loc) {
|
|
|
|
return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C++ catch statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
|
2010-08-27 03:41:50 +04:00
|
|
|
VarDecl *ExceptionDecl,
|
|
|
|
Stmt *Handler) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
|
|
|
|
Handler));
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
/// \brief Build a new C++ try statement.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new statement.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
|
2010-08-27 03:41:50 +04:00
|
|
|
Stmt *TryBlock,
|
|
|
|
MultiStmtArg Handlers) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-24 22:00:30 +03:00
|
|
|
/// \brief Build a new expression that references a declaration.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
|
2010-08-27 03:41:50 +04:00
|
|
|
LookupResult &R,
|
|
|
|
bool RequiresADL) {
|
2009-11-24 22:00:30 +03:00
|
|
|
return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new expression that references a declaration.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
|
2010-08-27 03:41:50 +04:00
|
|
|
SourceRange QualifierRange,
|
|
|
|
ValueDecl *VD,
|
|
|
|
const DeclarationNameInfo &NameInfo,
|
|
|
|
TemplateArgumentListInfo *TemplateArgs) {
|
2009-10-23 22:54:35 +04:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
SS.setScopeRep(Qualifier);
|
|
|
|
SS.setRange(QualifierRange);
|
2009-12-08 12:08:17 +03:00
|
|
|
|
|
|
|
// FIXME: loses template args.
|
2010-08-12 02:01:17 +04:00
|
|
|
|
|
|
|
return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new expression in parentheses.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParen) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-04 21:36:40 +04:00
|
|
|
/// \brief Build a new pseudo-destructor expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-09-04 21:36:40 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
|
2009-09-04 21:36:40 +04:00
|
|
|
SourceLocation OperatorLoc,
|
|
|
|
bool isArrow,
|
2010-02-25 04:56:36 +03:00
|
|
|
NestedNameSpecifier *Qualifier,
|
2010-02-25 02:40:28 +03:00
|
|
|
SourceRange QualifierRange,
|
|
|
|
TypeSourceInfo *ScopeType,
|
|
|
|
SourceLocation CCLoc,
|
2010-02-25 02:50:37 +03:00
|
|
|
SourceLocation TildeLoc,
|
2010-02-25 04:56:36 +03:00
|
|
|
PseudoDestructorTypeStorage Destroyed);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new unary operator expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
|
2010-08-25 15:45:40 +04:00
|
|
|
UnaryOperatorKind Opc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SubExpr) {
|
|
|
|
return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
/// \brief Build a new builtin offsetof expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
TypeSourceInfo *Type,
|
2010-08-27 03:41:50 +04:00
|
|
|
Sema::OffsetOfComponent *Components,
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
unsigned NumComponents,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
|
|
|
|
NumComponents, RParenLoc);
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new sizeof or alignof expression with a type argument.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
|
2009-11-04 10:28:41 +03:00
|
|
|
SourceLocation OpLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
bool isSizeOf, SourceRange R) {
|
2009-12-07 05:54:59 +03:00
|
|
|
return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// \brief Build a new sizeof or alignof expression with an expression
|
2009-08-11 09:31:07 +04:00
|
|
|
/// argument.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
bool isSizeOf, SourceRange R) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result
|
2010-08-24 03:25:46 +04:00
|
|
|
= getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return move(Result);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new array subscript expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildArraySubscriptExpr(Expr *LHS,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation LBracketLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *RHS,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RBracketLoc) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
|
|
|
|
LBracketLoc, RHS,
|
2009-08-11 09:31:07 +04:00
|
|
|
RBracketLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new call expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
MultiExprArg Args,
|
|
|
|
SourceLocation RParenLoc) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
|
2010-09-09 20:33:13 +04:00
|
|
|
move(Args), RParenLoc);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new member access expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
|
2010-11-18 09:31:45 +03:00
|
|
|
bool isArrow,
|
|
|
|
NestedNameSpecifier *Qualifier,
|
|
|
|
SourceRange QualifierRange,
|
|
|
|
const DeclarationNameInfo &MemberNameInfo,
|
|
|
|
ValueDecl *Member,
|
|
|
|
NamedDecl *FoundDecl,
|
2009-11-23 04:53:49 +03:00
|
|
|
const TemplateArgumentListInfo *ExplicitTemplateArgs,
|
2010-11-18 09:31:45 +03:00
|
|
|
NamedDecl *FirstQualifierInScope) {
|
2009-09-01 08:26:58 +04:00
|
|
|
if (!Member->getDeclName()) {
|
2010-11-18 09:31:45 +03:00
|
|
|
// We have a reference to an unnamed field. This is always the
|
|
|
|
// base of an anonymous struct/union member access, i.e. the
|
|
|
|
// field is always of record type.
|
2009-09-01 08:26:58 +04:00
|
|
|
assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
|
2010-11-18 09:31:45 +03:00
|
|
|
assert(Member->getType()->isRecordType() &&
|
|
|
|
"unnamed member not of record type?");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
if (getSema().PerformObjectMemberConversion(Base, Qualifier,
|
2010-03-31 01:47:33 +04:00
|
|
|
FoundDecl, Member))
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-24 23:23:34 +03:00
|
|
|
|
2010-11-18 09:31:45 +03:00
|
|
|
ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
|
2009-09-09 19:08:12 +04:00
|
|
|
MemberExpr *ME =
|
2010-08-24 03:25:46 +04:00
|
|
|
new (getSema().Context) MemberExpr(Base, isArrow,
|
2010-08-12 02:01:17 +04:00
|
|
|
Member, MemberNameInfo,
|
2010-11-18 09:31:45 +03:00
|
|
|
cast<FieldDecl>(Member)->getType(),
|
|
|
|
VK, OK_Ordinary);
|
2009-09-01 08:26:58 +04:00
|
|
|
return getSema().Owned(ME);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-09-01 03:41:50 +04:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
if (Qualifier) {
|
|
|
|
SS.setRange(QualifierRange);
|
|
|
|
SS.setScopeRep(Qualifier);
|
|
|
|
}
|
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
getSema().DefaultFunctionArrayConversion(Base);
|
|
|
|
QualType BaseType = Base->getType();
|
2009-12-02 01:10:20 +03:00
|
|
|
|
2010-03-31 01:47:33 +04:00
|
|
|
// FIXME: this involves duplicating earlier analysis in a lot of
|
|
|
|
// cases; we should avoid this when possible.
|
2010-08-12 02:01:17 +04:00
|
|
|
LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
|
2010-03-31 01:47:33 +04:00
|
|
|
R.addDecl(FoundDecl);
|
2010-01-15 11:34:02 +03:00
|
|
|
R.resolveKind();
|
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
|
2009-12-01 01:42:35 +03:00
|
|
|
SS, FirstQualifierInScope,
|
2010-01-15 11:34:02 +03:00
|
|
|
R, ExplicitTemplateArgs);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new binary operator expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
|
2010-08-25 15:45:40 +04:00
|
|
|
BinaryOperatorKind Opc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *LHS, Expr *RHS) {
|
|
|
|
return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new conditional operator expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildConditionalOperator(Expr *Cond,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation QuestionLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *LHS,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation ColonLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *RHS) {
|
|
|
|
return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
|
|
|
|
LHS, RHS);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C-style cast expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
|
2010-01-15 21:39:57 +03:00
|
|
|
TypeSourceInfo *TInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SubExpr) {
|
2010-01-15 21:56:44 +03:00
|
|
|
return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new compound literal expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
|
2010-01-18 22:35:47 +03:00
|
|
|
TypeSourceInfo *TInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Init) {
|
2010-01-18 22:35:47 +03:00
|
|
|
return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Init);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new extended vector element access expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildExtVectorElementExpr(Expr *Base,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation OpLoc,
|
|
|
|
SourceLocation AccessorLoc,
|
|
|
|
IdentifierInfo &Accessor) {
|
2009-12-02 01:10:20 +03:00
|
|
|
|
2009-12-01 01:42:35 +03:00
|
|
|
CXXScopeSpec SS;
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
|
2009-12-01 01:42:35 +03:00
|
|
|
OpLoc, /*IsArrow*/ false,
|
|
|
|
SS, /*FirstQualifierInScope*/ 0,
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo,
|
2009-12-01 01:42:35 +03:00
|
|
|
/* TemplateArgs */ 0);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new initializer list expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildInitList(SourceLocation LBraceLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
MultiExprArg Inits,
|
2009-11-09 20:16:50 +03:00
|
|
|
SourceLocation RBraceLoc,
|
|
|
|
QualType ResultTy) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result
|
2009-11-09 20:16:50 +03:00
|
|
|
= SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
|
|
|
|
if (Result.isInvalid() || ResultTy->isDependentType())
|
|
|
|
return move(Result);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-11-09 20:16:50 +03:00
|
|
|
// Patch in the result type we were given, which may have been computed
|
|
|
|
// when the initial InitListExpr was built.
|
|
|
|
InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
|
|
|
|
ILE->setType(ResultTy);
|
|
|
|
return move(Result);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new designated initializer expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildDesignatedInitExpr(Designation &Desig,
|
2009-08-11 09:31:07 +04:00
|
|
|
MultiExprArg ArrayExprs,
|
|
|
|
SourceLocation EqualOrColonLoc,
|
|
|
|
bool GNUSyntax,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Init) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result
|
2009-08-11 09:31:07 +04:00
|
|
|
= SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
|
2010-08-24 03:25:46 +04:00
|
|
|
Init);
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
ArrayExprs.release();
|
|
|
|
return move(Result);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new value-initialized expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, builds the implicit value initialization without performing
|
|
|
|
/// any semantic analysis. Subclasses may override this routine to provide
|
|
|
|
/// different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildImplicitValueInitExpr(QualType T) {
|
2009-08-11 09:31:07 +04:00
|
|
|
return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new \c va_arg expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SubExpr, TypeSourceInfo *TInfo,
|
2010-08-10 14:06:15 +04:00
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildVAArgExpr(BuiltinLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr, TInfo,
|
2010-08-10 14:06:15 +04:00
|
|
|
RParenLoc);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new expression list in parentheses.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
MultiExprArg SubExprs,
|
|
|
|
SourceLocation RParenLoc) {
|
2010-05-05 19:23:54 +04:00
|
|
|
return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
|
2009-11-25 04:26:41 +03:00
|
|
|
move(SubExprs));
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new address-of-label expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis, using the name of the label
|
2009-08-11 09:31:07 +04:00
|
|
|
/// rather than attempting to map the label statement itself.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation LabelLoc,
|
|
|
|
LabelStmt *Label) {
|
|
|
|
return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new GNU statement expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
///
|
2009-08-11 09:31:07 +04:00
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Stmt *SubStmt,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new __builtin_choose_expr expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Cond, Expr *LHS, Expr *RHS,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return SemaRef.ActOnChooseExpr(BuiltinLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Cond, LHS, RHS,
|
2009-08-11 09:31:07 +04:00
|
|
|
RParenLoc);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new overloaded operator call expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// The semantic analysis provides the behavior of template instantiation,
|
|
|
|
/// copying with transformations that turn what looks like an overloaded
|
2009-09-09 19:08:12 +04:00
|
|
|
/// operator call into a use of a builtin operator, performing
|
2009-08-11 09:31:07 +04:00
|
|
|
/// argument-dependent lookup, etc. Subclasses may override this routine to
|
|
|
|
/// provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation OpLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Callee,
|
|
|
|
Expr *First,
|
|
|
|
Expr *Second);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
/// \brief Build a new C++ "named" cast expression, such as static_cast or
|
2009-08-11 09:31:07 +04:00
|
|
|
/// reinterpret_cast.
|
|
|
|
///
|
|
|
|
/// By default, this routine dispatches to one of the more-specific routines
|
2009-09-09 19:08:12 +04:00
|
|
|
/// for a particular named case, e.g., RebuildCXXStaticCastExpr().
|
2009-08-11 09:31:07 +04:00
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
Stmt::StmtClass Class,
|
|
|
|
SourceLocation LAngleLoc,
|
2010-01-15 21:39:57 +03:00
|
|
|
TypeSourceInfo *TInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RAngleLoc,
|
|
|
|
SourceLocation LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SubExpr,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
switch (Class) {
|
|
|
|
case Stmt::CXXStaticCastExprClass:
|
2010-01-15 21:39:57 +03:00
|
|
|
return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
|
2009-09-09 19:08:12 +04:00
|
|
|
RAngleLoc, LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr, RParenLoc);
|
2009-08-11 09:31:07 +04:00
|
|
|
|
|
|
|
case Stmt::CXXDynamicCastExprClass:
|
2010-01-15 21:39:57 +03:00
|
|
|
return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
|
2009-09-09 19:08:12 +04:00
|
|
|
RAngleLoc, LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr, RParenLoc);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
case Stmt::CXXReinterpretCastExprClass:
|
2010-01-15 21:39:57 +03:00
|
|
|
return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
|
2009-09-09 19:08:12 +04:00
|
|
|
RAngleLoc, LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr,
|
2009-08-11 09:31:07 +04:00
|
|
|
RParenLoc);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
case Stmt::CXXConstCastExprClass:
|
2010-01-15 21:39:57 +03:00
|
|
|
return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
|
2009-09-09 19:08:12 +04:00
|
|
|
RAngleLoc, LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr, RParenLoc);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
default:
|
|
|
|
assert(false && "Invalid C++ named cast");
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new C++ static_cast expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation LAngleLoc,
|
2010-01-15 21:39:57 +03:00
|
|
|
TypeSourceInfo *TInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RAngleLoc,
|
|
|
|
SourceLocation LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SubExpr,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-01-15 22:13:16 +03:00
|
|
|
return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
|
2010-08-24 03:25:46 +04:00
|
|
|
TInfo, SubExpr,
|
2010-01-15 22:13:16 +03:00
|
|
|
SourceRange(LAngleLoc, RAngleLoc),
|
|
|
|
SourceRange(LParenLoc, RParenLoc));
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C++ dynamic_cast expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation LAngleLoc,
|
2010-01-15 21:39:57 +03:00
|
|
|
TypeSourceInfo *TInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RAngleLoc,
|
|
|
|
SourceLocation LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SubExpr,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-01-15 22:13:16 +03:00
|
|
|
return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
|
2010-08-24 03:25:46 +04:00
|
|
|
TInfo, SubExpr,
|
2010-01-15 22:13:16 +03:00
|
|
|
SourceRange(LAngleLoc, RAngleLoc),
|
|
|
|
SourceRange(LParenLoc, RParenLoc));
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C++ reinterpret_cast expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation LAngleLoc,
|
2010-01-15 21:39:57 +03:00
|
|
|
TypeSourceInfo *TInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RAngleLoc,
|
|
|
|
SourceLocation LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SubExpr,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-01-15 22:13:16 +03:00
|
|
|
return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
|
2010-08-24 03:25:46 +04:00
|
|
|
TInfo, SubExpr,
|
2010-01-15 22:13:16 +03:00
|
|
|
SourceRange(LAngleLoc, RAngleLoc),
|
|
|
|
SourceRange(LParenLoc, RParenLoc));
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C++ const_cast expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation LAngleLoc,
|
2010-01-15 21:39:57 +03:00
|
|
|
TypeSourceInfo *TInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RAngleLoc,
|
|
|
|
SourceLocation LParenLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SubExpr,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-01-15 22:13:16 +03:00
|
|
|
return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
|
2010-08-24 03:25:46 +04:00
|
|
|
TInfo, SubExpr,
|
2010-01-15 22:13:16 +03:00
|
|
|
SourceRange(LAngleLoc, RAngleLoc),
|
|
|
|
SourceRange(LParenLoc, RParenLoc));
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new C++ functional-style cast expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-09-08 04:15:04 +04:00
|
|
|
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
Expr *Sub,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
|
2010-08-27 03:41:50 +04:00
|
|
|
MultiExprArg(&Sub, 1),
|
2009-08-11 09:31:07 +04:00
|
|
|
RParenLoc);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new C++ typeid(type) expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
|
2010-04-27 02:37:10 +04:00
|
|
|
SourceLocation TypeidLoc,
|
|
|
|
TypeSourceInfo *Operand,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-05-05 19:23:54 +04:00
|
|
|
return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
|
2010-04-27 02:37:10 +04:00
|
|
|
RParenLoc);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-09-08 16:20:18 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new C++ typeid(expr) expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
|
2010-04-27 02:37:10 +04:00
|
|
|
SourceLocation TypeidLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Operand,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
|
2010-04-27 02:37:10 +04:00
|
|
|
RParenLoc);
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
|
|
|
|
2010-09-08 16:20:18 +04:00
|
|
|
/// \brief Build a new C++ __uuidof(type) expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
|
|
|
|
SourceLocation TypeidLoc,
|
|
|
|
TypeSourceInfo *Operand,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
|
|
|
|
RParenLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C++ __uuidof(expr) expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
|
|
|
|
SourceLocation TypeidLoc,
|
|
|
|
Expr *Operand,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
|
|
|
|
RParenLoc);
|
|
|
|
}
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new C++ "this" expression.
|
|
|
|
///
|
|
|
|
/// By default, builds a new "this" expression without performing any
|
2009-09-09 19:08:12 +04:00
|
|
|
/// semantic analysis. Subclasses may override this routine to provide
|
2009-08-11 09:31:07 +04:00
|
|
|
/// different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
|
2010-09-09 20:55:46 +04:00
|
|
|
QualType ThisType,
|
|
|
|
bool isImplicit) {
|
2009-08-11 09:31:07 +04:00
|
|
|
return getSema().Owned(
|
2010-01-08 02:12:05 +03:00
|
|
|
new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
|
|
|
|
isImplicit));
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C++ throw expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnCXXThrow(ThrowLoc, Sub);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C++ default-argument expression.
|
|
|
|
///
|
|
|
|
/// By default, builds a new default-argument expression, which does not
|
|
|
|
/// require any semantic analysis. Subclasses may override this routine to
|
|
|
|
/// provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
|
2009-12-24 02:03:06 +03:00
|
|
|
ParmVarDecl *Param) {
|
|
|
|
return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
|
|
|
|
Param));
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new C++ zero-initialization expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-09-08 04:15:04 +04:00
|
|
|
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
|
2009-09-09 19:08:12 +04:00
|
|
|
MultiExprArg(getSema(), 0, 0),
|
2010-09-08 04:15:04 +04:00
|
|
|
RParenLoc);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new C++ "new" expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
|
2010-09-08 01:49:58 +04:00
|
|
|
bool UseGlobal,
|
|
|
|
SourceLocation PlacementLParen,
|
|
|
|
MultiExprArg PlacementArgs,
|
|
|
|
SourceLocation PlacementRParen,
|
|
|
|
SourceRange TypeIdParens,
|
|
|
|
QualType AllocatedType,
|
|
|
|
TypeSourceInfo *AllocatedTypeInfo,
|
|
|
|
Expr *ArraySize,
|
|
|
|
SourceLocation ConstructorLParen,
|
|
|
|
MultiExprArg ConstructorArgs,
|
|
|
|
SourceLocation ConstructorRParen) {
|
2009-09-09 19:08:12 +04:00
|
|
|
return getSema().BuildCXXNew(StartLoc, UseGlobal,
|
2009-08-11 09:31:07 +04:00
|
|
|
PlacementLParen,
|
|
|
|
move(PlacementArgs),
|
|
|
|
PlacementRParen,
|
2010-07-13 19:54:32 +04:00
|
|
|
TypeIdParens,
|
2010-09-08 01:49:58 +04:00
|
|
|
AllocatedType,
|
|
|
|
AllocatedTypeInfo,
|
2010-08-24 03:25:46 +04:00
|
|
|
ArraySize,
|
2009-08-11 09:31:07 +04:00
|
|
|
ConstructorLParen,
|
|
|
|
move(ConstructorArgs),
|
|
|
|
ConstructorRParen);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new C++ "delete" expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
bool IsGlobalDelete,
|
|
|
|
bool IsArrayForm,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Operand) {
|
2009-08-11 09:31:07 +04:00
|
|
|
return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
|
2010-08-24 03:25:46 +04:00
|
|
|
Operand);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new unary type trait expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
|
2010-09-09 20:14:44 +04:00
|
|
|
SourceLocation StartLoc,
|
|
|
|
TypeSourceInfo *T,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2010-12-07 03:08:36 +03:00
|
|
|
/// \brief Build a new binary type trait expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
TypeSourceInfo *LhsT,
|
|
|
|
TypeSourceInfo *RhsT,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// \brief Build a new (previously unresolved) declaration reference
|
2009-08-11 09:31:07 +04:00
|
|
|
/// expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceRange QualifierRange,
|
2010-08-12 02:01:17 +04:00
|
|
|
const DeclarationNameInfo &NameInfo,
|
2009-11-24 22:00:30 +03:00
|
|
|
const TemplateArgumentListInfo *TemplateArgs) {
|
2009-08-11 09:31:07 +04:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
SS.setRange(QualifierRange);
|
|
|
|
SS.setScopeRep(NNS);
|
2009-11-24 22:00:30 +03:00
|
|
|
|
|
|
|
if (TemplateArgs)
|
2010-08-12 02:01:17 +04:00
|
|
|
return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
|
2009-11-24 22:00:30 +03:00
|
|
|
*TemplateArgs);
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new template-id expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
|
2009-11-24 22:00:30 +03:00
|
|
|
LookupResult &R,
|
|
|
|
bool RequiresADL,
|
2009-11-23 04:53:49 +03:00
|
|
|
const TemplateArgumentListInfo &TemplateArgs) {
|
2009-11-24 22:00:30 +03:00
|
|
|
return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new object-construction expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXConstructExpr(QualType T,
|
2009-12-14 19:27:04 +03:00
|
|
|
SourceLocation Loc,
|
2009-08-11 09:31:07 +04:00
|
|
|
CXXConstructorDecl *Constructor,
|
|
|
|
bool IsElidable,
|
2010-08-22 21:20:18 +04:00
|
|
|
MultiExprArg Args,
|
|
|
|
bool RequiresZeroInit,
|
2010-10-25 12:47:36 +04:00
|
|
|
CXXConstructExpr::ConstructionKind ConstructKind,
|
|
|
|
SourceRange ParenRange) {
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
|
2010-05-05 19:23:54 +04:00
|
|
|
if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
|
2009-12-14 19:27:04 +03:00
|
|
|
ConvertedArgs))
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-12-14 19:27:04 +03:00
|
|
|
return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
|
2010-08-22 21:20:18 +04:00
|
|
|
move_arg(ConvertedArgs),
|
2010-10-25 12:47:36 +04:00
|
|
|
RequiresZeroInit, ConstructKind,
|
|
|
|
ParenRange);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new object-construction expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-09-08 04:15:04 +04:00
|
|
|
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
MultiExprArg Args,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildCXXTypeConstructExpr(TSInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
LParenLoc,
|
|
|
|
move(Args),
|
|
|
|
RParenLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new object-construction expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-09-08 04:15:04 +04:00
|
|
|
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
MultiExprArg Args,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return getSema().BuildCXXTypeConstructExpr(TSInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
LParenLoc,
|
|
|
|
move(Args),
|
|
|
|
RParenLoc);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new member reference expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
|
2009-12-02 01:10:20 +03:00
|
|
|
QualType BaseType,
|
2009-08-11 09:31:07 +04:00
|
|
|
bool IsArrow,
|
|
|
|
SourceLocation OperatorLoc,
|
2009-09-03 20:14:30 +04:00
|
|
|
NestedNameSpecifier *Qualifier,
|
|
|
|
SourceRange QualifierRange,
|
2009-12-01 01:42:35 +03:00
|
|
|
NamedDecl *FirstQualifierInScope,
|
2010-08-12 02:01:17 +04:00
|
|
|
const DeclarationNameInfo &MemberNameInfo,
|
2009-12-01 01:42:35 +03:00
|
|
|
const TemplateArgumentListInfo *TemplateArgs) {
|
2009-08-11 09:31:07 +04:00
|
|
|
CXXScopeSpec SS;
|
2009-09-03 20:14:30 +04:00
|
|
|
SS.setRange(QualifierRange);
|
|
|
|
SS.setScopeRep(Qualifier);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
|
2009-12-02 01:10:20 +03:00
|
|
|
OperatorLoc, IsArrow,
|
2009-12-01 01:42:35 +03:00
|
|
|
SS, FirstQualifierInScope,
|
2010-08-12 02:01:17 +04:00
|
|
|
MemberNameInfo,
|
|
|
|
TemplateArgs);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-12-01 01:42:35 +03:00
|
|
|
/// \brief Build a new member reference expression.
|
2009-09-09 04:23:06 +04:00
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
|
2009-12-02 01:10:20 +03:00
|
|
|
QualType BaseType,
|
2009-12-01 01:42:35 +03:00
|
|
|
SourceLocation OperatorLoc,
|
|
|
|
bool IsArrow,
|
|
|
|
NestedNameSpecifier *Qualifier,
|
|
|
|
SourceRange QualifierRange,
|
2010-01-15 11:34:02 +03:00
|
|
|
NamedDecl *FirstQualifierInScope,
|
2009-12-01 01:42:35 +03:00
|
|
|
LookupResult &R,
|
|
|
|
const TemplateArgumentListInfo *TemplateArgs) {
|
2009-09-09 04:23:06 +04:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
SS.setRange(QualifierRange);
|
|
|
|
SS.setScopeRep(Qualifier);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
|
2009-12-02 01:10:20 +03:00
|
|
|
OperatorLoc, IsArrow,
|
2010-01-15 11:34:02 +03:00
|
|
|
SS, FirstQualifierInScope,
|
|
|
|
R, TemplateArgs);
|
2009-09-09 04:23:06 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-09-11 00:55:43 +04:00
|
|
|
/// \brief Build a new noexcept expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
|
|
|
|
return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
|
|
|
|
}
|
|
|
|
|
2011-01-04 20:33:58 +03:00
|
|
|
/// \brief Build a new expression to compute the length of a parameter pack.
|
|
|
|
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
|
|
|
|
SourceLocation PackLoc,
|
|
|
|
SourceLocation RParenLoc,
|
|
|
|
unsigned Length) {
|
|
|
|
return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
|
|
|
|
OperatorLoc, Pack, PackLoc,
|
|
|
|
RParenLoc, Length);
|
|
|
|
}
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new Objective-C @encode expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
|
2010-04-20 19:39:42 +04:00
|
|
|
TypeSourceInfo *EncodeTypeInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-04-20 19:39:42 +04:00
|
|
|
return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
RParenLoc));
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
2009-08-11 09:31:07 +04:00
|
|
|
|
2010-04-22 20:44:27 +04:00
|
|
|
/// \brief Build a new Objective-C class message.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
|
2010-04-22 20:44:27 +04:00
|
|
|
Selector Sel,
|
2010-12-10 23:08:27 +03:00
|
|
|
SourceLocation SelectorLoc,
|
2010-04-22 20:44:27 +04:00
|
|
|
ObjCMethodDecl *Method,
|
2010-05-05 19:23:54 +04:00
|
|
|
SourceLocation LBracLoc,
|
2010-04-22 20:44:27 +04:00
|
|
|
MultiExprArg Args,
|
|
|
|
SourceLocation RBracLoc) {
|
|
|
|
return SemaRef.BuildClassMessage(ReceiverTypeInfo,
|
|
|
|
ReceiverTypeInfo->getType(),
|
|
|
|
/*SuperLoc=*/SourceLocation(),
|
2010-12-10 23:08:27 +03:00
|
|
|
Sel, Method, LBracLoc, SelectorLoc,
|
|
|
|
RBracLoc, move(Args));
|
2010-04-22 20:44:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build a new Objective-C instance message.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildObjCMessageExpr(Expr *Receiver,
|
2010-04-22 20:44:27 +04:00
|
|
|
Selector Sel,
|
2010-12-10 23:08:27 +03:00
|
|
|
SourceLocation SelectorLoc,
|
2010-04-22 20:44:27 +04:00
|
|
|
ObjCMethodDecl *Method,
|
2010-05-05 19:23:54 +04:00
|
|
|
SourceLocation LBracLoc,
|
2010-04-22 20:44:27 +04:00
|
|
|
MultiExprArg Args,
|
|
|
|
SourceLocation RBracLoc) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.BuildInstanceMessage(Receiver,
|
|
|
|
Receiver->getType(),
|
2010-04-22 20:44:27 +04:00
|
|
|
/*SuperLoc=*/SourceLocation(),
|
2010-12-10 23:08:27 +03:00
|
|
|
Sel, Method, LBracLoc, SelectorLoc,
|
|
|
|
RBracLoc, move(Args));
|
2010-04-22 20:44:27 +04:00
|
|
|
}
|
|
|
|
|
2010-04-27 00:11:03 +04:00
|
|
|
/// \brief Build a new Objective-C ivar reference expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
|
2010-04-27 00:11:03 +04:00
|
|
|
SourceLocation IvarLoc,
|
|
|
|
bool IsArrow, bool IsFreeIvar) {
|
|
|
|
// FIXME: We lose track of the IsFreeIvar bit.
|
|
|
|
CXXScopeSpec SS;
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Base = BaseArg;
|
2010-04-27 00:11:03 +04:00
|
|
|
LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
|
|
|
|
Sema::LookupMemberName);
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
|
2010-04-27 00:11:03 +04:00
|
|
|
/*FIME:*/IvarLoc,
|
2010-08-21 13:40:31 +04:00
|
|
|
SS, 0,
|
2010-06-16 12:42:20 +04:00
|
|
|
false);
|
2010-04-27 00:11:03 +04:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 00:11:03 +04:00
|
|
|
if (Result.get())
|
|
|
|
return move(Result);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
|
2010-05-05 19:23:54 +04:00
|
|
|
/*FIXME:*/IvarLoc, IsArrow, SS,
|
2010-04-27 00:11:03 +04:00
|
|
|
/*FirstQualifierInScope=*/0,
|
2010-05-05 19:23:54 +04:00
|
|
|
R,
|
2010-04-27 00:11:03 +04:00
|
|
|
/*TemplateArgs=*/0);
|
|
|
|
}
|
2010-04-27 00:47:02 +04:00
|
|
|
|
|
|
|
/// \brief Build a new Objective-C property reference expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
|
2010-04-27 00:47:02 +04:00
|
|
|
ObjCPropertyDecl *Property,
|
|
|
|
SourceLocation PropertyLoc) {
|
|
|
|
CXXScopeSpec SS;
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Base = BaseArg;
|
2010-04-27 00:47:02 +04:00
|
|
|
LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
|
|
|
|
Sema::LookupMemberName);
|
|
|
|
bool IsArrow = false;
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
|
2010-04-27 00:47:02 +04:00
|
|
|
/*FIME:*/PropertyLoc,
|
2010-08-21 13:40:31 +04:00
|
|
|
SS, 0, false);
|
2010-04-27 00:47:02 +04:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 00:47:02 +04:00
|
|
|
if (Result.get())
|
|
|
|
return move(Result);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
|
2010-05-05 19:23:54 +04:00
|
|
|
/*FIXME:*/PropertyLoc, IsArrow,
|
|
|
|
SS,
|
2010-04-27 00:47:02 +04:00
|
|
|
/*FirstQualifierInScope=*/0,
|
2010-05-05 19:23:54 +04:00
|
|
|
R,
|
2010-04-27 00:47:02 +04:00
|
|
|
/*TemplateArgs=*/0);
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-12-02 04:19:52 +03:00
|
|
|
/// \brief Build a new Objective-C property reference expression.
|
2010-04-27 01:04:54 +04:00
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
2010-12-02 04:19:52 +03:00
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
|
|
|
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
|
|
|
|
ObjCMethodDecl *Getter,
|
|
|
|
ObjCMethodDecl *Setter,
|
|
|
|
SourceLocation PropertyLoc) {
|
|
|
|
// Since these expressions can only be value-dependent, we do not
|
|
|
|
// need to perform semantic analysis again.
|
|
|
|
return Owned(
|
|
|
|
new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
|
|
|
|
VK_LValue, OK_ObjCProperty,
|
|
|
|
PropertyLoc, Base));
|
2010-04-27 01:04:54 +04:00
|
|
|
}
|
|
|
|
|
2010-04-27 00:11:03 +04:00
|
|
|
/// \brief Build a new Objective-C "isa" expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
|
2010-04-27 00:11:03 +04:00
|
|
|
bool IsArrow) {
|
|
|
|
CXXScopeSpec SS;
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Base = BaseArg;
|
2010-04-27 00:11:03 +04:00
|
|
|
LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
|
|
|
|
Sema::LookupMemberName);
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
|
2010-04-27 00:11:03 +04:00
|
|
|
/*FIME:*/IsaLoc,
|
2010-08-21 13:40:31 +04:00
|
|
|
SS, 0, false);
|
2010-04-27 00:11:03 +04:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 00:11:03 +04:00
|
|
|
if (Result.get())
|
|
|
|
return move(Result);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
|
2010-05-05 19:23:54 +04:00
|
|
|
/*FIXME:*/IsaLoc, IsArrow, SS,
|
2010-04-27 00:11:03 +04:00
|
|
|
/*FirstQualifierInScope=*/0,
|
2010-05-05 19:23:54 +04:00
|
|
|
R,
|
2010-04-27 00:11:03 +04:00
|
|
|
/*TemplateArgs=*/0);
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Build a new shuffle vector expression.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build the new expression.
|
|
|
|
/// Subclasses may override this routine to provide different behavior.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
|
2010-11-18 09:31:45 +03:00
|
|
|
MultiExprArg SubExprs,
|
|
|
|
SourceLocation RParenLoc) {
|
2009-08-11 09:31:07 +04:00
|
|
|
// Find the declaration for __builtin_shufflevector
|
2009-09-09 19:08:12 +04:00
|
|
|
const IdentifierInfo &Name
|
2009-08-11 09:31:07 +04:00
|
|
|
= SemaRef.Context.Idents.get("__builtin_shufflevector");
|
|
|
|
TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
|
|
|
|
DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
|
|
|
|
assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// Build a reference to the __builtin_shufflevector builtin
|
|
|
|
FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
|
2009-09-09 19:08:12 +04:00
|
|
|
Expr *Callee
|
2009-08-11 09:31:07 +04:00
|
|
|
= new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
|
2010-11-18 09:31:45 +03:00
|
|
|
VK_LValue, BuiltinLoc);
|
2009-08-11 09:31:07 +04:00
|
|
|
SemaRef.UsualUnaryConversions(Callee);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
// Build the CallExpr
|
2009-08-11 09:31:07 +04:00
|
|
|
unsigned NumSubExprs = SubExprs.size();
|
|
|
|
Expr **Subs = (Expr **)SubExprs.release();
|
|
|
|
CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
|
|
|
|
Subs, NumSubExprs,
|
2010-07-13 12:18:22 +04:00
|
|
|
Builtin->getCallResultType(),
|
2010-11-18 09:31:45 +03:00
|
|
|
Expr::getValueKindForType(Builtin->getResultType()),
|
2009-08-11 09:31:07 +04:00
|
|
|
RParenLoc);
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult OwnedCall(SemaRef.Owned(TheCall));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// Type-check the __builtin_shufflevector expression.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
OwnedCall.release();
|
2009-09-09 19:08:12 +04:00
|
|
|
return move(Result);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2010-11-12 11:19:04 +03:00
|
|
|
|
2010-12-21 01:05:00 +03:00
|
|
|
/// \brief Build a new template argument pack expansion.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build a new pack expansion
|
|
|
|
/// for a template argument. Subclasses may override this routine to provide
|
|
|
|
/// different behavior.
|
|
|
|
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
|
2011-01-14 20:04:44 +03:00
|
|
|
SourceLocation EllipsisLoc,
|
|
|
|
llvm::Optional<unsigned> NumExpansions) {
|
2010-12-21 01:05:00 +03:00
|
|
|
switch (Pattern.getArgument().getKind()) {
|
2011-01-04 00:37:45 +03:00
|
|
|
case TemplateArgument::Expression: {
|
|
|
|
ExprResult Result
|
2011-01-15 00:20:45 +03:00
|
|
|
= getSema().CheckPackExpansion(Pattern.getSourceExpression(),
|
|
|
|
EllipsisLoc, NumExpansions);
|
2011-01-04 00:37:45 +03:00
|
|
|
if (Result.isInvalid())
|
|
|
|
return TemplateArgumentLoc();
|
|
|
|
|
|
|
|
return TemplateArgumentLoc(Result.get(), Result.get());
|
|
|
|
}
|
2011-01-03 22:31:53 +03:00
|
|
|
|
2010-12-21 01:05:00 +03:00
|
|
|
case TemplateArgument::Template:
|
2011-01-05 21:58:31 +03:00
|
|
|
return TemplateArgumentLoc(TemplateArgument(
|
|
|
|
Pattern.getArgument().getAsTemplate(),
|
2011-01-15 02:41:42 +03:00
|
|
|
NumExpansions),
|
2011-01-05 21:58:31 +03:00
|
|
|
Pattern.getTemplateQualifierRange(),
|
|
|
|
Pattern.getTemplateNameLoc(),
|
|
|
|
EllipsisLoc);
|
2010-12-21 01:05:00 +03:00
|
|
|
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
case TemplateArgument::Integral:
|
|
|
|
case TemplateArgument::Declaration:
|
|
|
|
case TemplateArgument::Pack:
|
2011-01-05 21:58:31 +03:00
|
|
|
case TemplateArgument::TemplateExpansion:
|
2010-12-21 01:05:00 +03:00
|
|
|
llvm_unreachable("Pack expansion pattern has no parameter packs");
|
|
|
|
|
|
|
|
case TemplateArgument::Type:
|
|
|
|
if (TypeSourceInfo *Expansion
|
|
|
|
= getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
|
2011-01-14 20:04:44 +03:00
|
|
|
EllipsisLoc,
|
|
|
|
NumExpansions))
|
2010-12-21 01:05:00 +03:00
|
|
|
return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
|
|
|
|
Expansion);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TemplateArgumentLoc();
|
|
|
|
}
|
|
|
|
|
2011-01-03 22:31:53 +03:00
|
|
|
/// \brief Build a new expression pack expansion.
|
|
|
|
///
|
|
|
|
/// By default, performs semantic analysis to build a new pack expansion
|
|
|
|
/// for an expression. Subclasses may override this routine to provide
|
|
|
|
/// different behavior.
|
2011-01-15 00:20:45 +03:00
|
|
|
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
|
|
|
|
llvm::Optional<unsigned> NumExpansions) {
|
|
|
|
return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
|
2011-01-03 22:31:53 +03:00
|
|
|
}
|
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
private:
|
|
|
|
QualType TransformTypeInObjectScope(QualType T,
|
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *FirstQualifierInScope,
|
|
|
|
NestedNameSpecifier *Prefix);
|
|
|
|
|
|
|
|
TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
|
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *FirstQualifierInScope,
|
|
|
|
NestedNameSpecifier *Prefix);
|
2009-08-04 20:50:30 +04:00
|
|
|
};
|
2009-08-11 09:31:07 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!S)
|
|
|
|
return SemaRef.Owned(S);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
switch (S->getStmtClass()) {
|
|
|
|
case Stmt::NoStmtClass: break;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform individual statement nodes
|
|
|
|
#define STMT(Node, Parent) \
|
|
|
|
case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
|
|
|
|
#define EXPR(Node, Parent)
|
2010-05-05 19:24:00 +04:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform expressions by calling TransformExpr.
|
|
|
|
#define STMT(Node, Parent)
|
2010-05-18 10:22:21 +04:00
|
|
|
#define ABSTRACT_STMT(Stmt)
|
2009-08-20 11:17:43 +04:00
|
|
|
#define EXPR(Node, Parent) case Stmt::Node##Class:
|
2010-05-05 19:24:00 +04:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
2009-08-20 11:17:43 +04:00
|
|
|
{
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
|
2009-08-20 11:17:43 +04:00
|
|
|
if (E.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
|
|
|
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
|
2009-08-07 02:17:10 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!E)
|
|
|
|
return SemaRef.Owned(E);
|
|
|
|
|
|
|
|
switch (E->getStmtClass()) {
|
|
|
|
case Stmt::NoStmtClass: break;
|
|
|
|
#define STMT(Node, Parent) case Stmt::Node##Class: break;
|
2010-05-18 10:22:21 +04:00
|
|
|
#define ABSTRACT_STMT(Stmt)
|
2009-08-11 09:31:07 +04:00
|
|
|
#define EXPR(Node, Parent) \
|
2009-12-08 12:21:05 +03:00
|
|
|
case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
|
2010-05-05 19:24:00 +04:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
|
|
|
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-07 02:17:10 +04:00
|
|
|
}
|
|
|
|
|
2011-01-03 22:04:46 +03:00
|
|
|
template<typename Derived>
|
|
|
|
bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
|
|
|
|
unsigned NumInputs,
|
|
|
|
bool IsCall,
|
|
|
|
llvm::SmallVectorImpl<Expr *> &Outputs,
|
|
|
|
bool *ArgChanged) {
|
|
|
|
for (unsigned I = 0; I != NumInputs; ++I) {
|
|
|
|
// If requested, drop call arguments that need to be dropped.
|
|
|
|
if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
|
|
|
|
if (ArgChanged)
|
|
|
|
*ArgChanged = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-03 22:31:53 +03:00
|
|
|
if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
|
|
|
|
Expr *Pattern = Expansion->getPattern();
|
|
|
|
|
|
|
|
llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
|
|
|
|
getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
|
|
|
|
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
|
|
|
|
|
|
|
|
// Determine whether the set of unexpanded parameter packs can and should
|
|
|
|
// be expanded.
|
|
|
|
bool Expand = true;
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
bool RetainExpansion = false;
|
2011-01-15 00:20:45 +03:00
|
|
|
llvm::Optional<unsigned> OrigNumExpansions
|
|
|
|
= Expansion->getNumExpansions();
|
|
|
|
llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
|
2011-01-03 22:31:53 +03:00
|
|
|
if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
|
|
|
|
Pattern->getSourceRange(),
|
|
|
|
Unexpanded.data(),
|
|
|
|
Unexpanded.size(),
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
Expand, RetainExpansion,
|
|
|
|
NumExpansions))
|
2011-01-03 22:31:53 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!Expand) {
|
|
|
|
// The transform has determined that we should perform a simple
|
|
|
|
// transformation on the pack expansion, producing another pack
|
|
|
|
// expansion.
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
|
|
|
|
ExprResult OutPattern = getDerived().TransformExpr(Pattern);
|
|
|
|
if (OutPattern.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
|
2011-01-15 00:20:45 +03:00
|
|
|
Expansion->getEllipsisLoc(),
|
|
|
|
NumExpansions);
|
2011-01-03 22:31:53 +03:00
|
|
|
if (Out.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (ArgChanged)
|
|
|
|
*ArgChanged = true;
|
|
|
|
Outputs.push_back(Out.get());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The transform has determined that we should perform an elementwise
|
|
|
|
// expansion of the pattern. Do so.
|
2011-01-14 20:04:44 +03:00
|
|
|
for (unsigned I = 0; I != *NumExpansions; ++I) {
|
2011-01-03 22:31:53 +03:00
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
|
|
|
|
ExprResult Out = getDerived().TransformExpr(Pattern);
|
|
|
|
if (Out.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
2011-01-12 01:21:24 +03:00
|
|
|
if (Out.get()->containsUnexpandedParameterPack()) {
|
2011-01-15 00:20:45 +03:00
|
|
|
Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
|
|
|
|
OrigNumExpansions);
|
2011-01-12 01:21:24 +03:00
|
|
|
if (Out.isInvalid())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-03 22:31:53 +03:00
|
|
|
if (ArgChanged)
|
|
|
|
*ArgChanged = true;
|
|
|
|
Outputs.push_back(Out.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-03 22:04:46 +03:00
|
|
|
ExprResult Result = getDerived().TransformExpr(Inputs[I]);
|
|
|
|
if (Result.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Result.get() != Inputs[I] && ArgChanged)
|
|
|
|
*ArgChanged = true;
|
|
|
|
|
|
|
|
Outputs.push_back(Result.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
template<typename Derived>
|
|
|
|
NestedNameSpecifier *
|
|
|
|
TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
|
2009-09-03 20:14:30 +04:00
|
|
|
SourceRange Range,
|
2009-09-04 01:38:09 +04:00
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *FirstQualifierInScope) {
|
2010-11-12 11:19:04 +03:00
|
|
|
NestedNameSpecifier *Prefix = NNS->getPrefix();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the prefix of this nested name specifier.
|
2009-08-06 09:28:30 +04:00
|
|
|
if (Prefix) {
|
2009-09-09 19:08:12 +04:00
|
|
|
Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
|
2009-09-04 01:38:09 +04:00
|
|
|
ObjectType,
|
|
|
|
FirstQualifierInScope);
|
2009-08-06 09:28:30 +04:00
|
|
|
if (!Prefix)
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
switch (NNS->getKind()) {
|
|
|
|
case NestedNameSpecifier::Identifier:
|
2010-11-12 11:19:04 +03:00
|
|
|
if (Prefix) {
|
|
|
|
// The object type and qualifier-in-scope really apply to the
|
|
|
|
// leftmost entity.
|
|
|
|
ObjectType = QualType();
|
|
|
|
FirstQualifierInScope = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
assert((Prefix || !ObjectType.isNull()) &&
|
2009-09-03 20:14:30 +04:00
|
|
|
"Identifier nested-name-specifier with no prefix or object type");
|
|
|
|
if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
|
|
|
|
ObjectType.isNull())
|
2009-08-06 09:28:30 +04:00
|
|
|
return NNS;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
|
2009-09-03 20:14:30 +04:00
|
|
|
*NNS->getAsIdentifier(),
|
2009-09-04 01:38:09 +04:00
|
|
|
ObjectType,
|
|
|
|
FirstQualifierInScope);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
case NestedNameSpecifier::Namespace: {
|
2009-09-09 19:08:12 +04:00
|
|
|
NamespaceDecl *NS
|
2009-08-06 09:28:30 +04:00
|
|
|
= cast_or_null<NamespaceDecl>(
|
2010-03-01 18:56:25 +03:00
|
|
|
getDerived().TransformDecl(Range.getBegin(),
|
|
|
|
NNS->getAsNamespace()));
|
2009-09-09 19:08:12 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2009-08-06 09:28:30 +04:00
|
|
|
Prefix == NNS->getPrefix() &&
|
|
|
|
NS == NNS->getAsNamespace())
|
|
|
|
return NNS;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
case NestedNameSpecifier::Global:
|
|
|
|
// There is no meaningful transformation that one could perform on the
|
|
|
|
// global scope.
|
|
|
|
return NNS;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate:
|
|
|
|
case NestedNameSpecifier::TypeSpec: {
|
2009-10-30 01:21:39 +03:00
|
|
|
TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
|
|
|
|
ObjectType,
|
|
|
|
FirstQualifierInScope,
|
|
|
|
Prefix);
|
2009-08-06 10:41:21 +04:00
|
|
|
if (T.isNull())
|
|
|
|
return 0;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Prefix == NNS->getPrefix() &&
|
|
|
|
T == QualType(NNS->getAsType(), 0))
|
|
|
|
return NNS;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
|
|
|
|
NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
|
2010-02-25 07:46:04 +03:00
|
|
|
T);
|
2009-08-06 09:28:30 +04:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
// Required to silence a GCC warning
|
2009-09-09 19:08:12 +04:00
|
|
|
return 0;
|
2009-08-06 09:28:30 +04:00
|
|
|
}
|
|
|
|
|
2009-09-04 02:13:48 +04:00
|
|
|
template<typename Derived>
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationNameInfo
|
|
|
|
TreeTransform<Derived>
|
2010-11-12 11:19:04 +03:00
|
|
|
::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationName Name = NameInfo.getName();
|
2009-09-04 02:13:48 +04:00
|
|
|
if (!Name)
|
2010-08-12 02:01:17 +04:00
|
|
|
return DeclarationNameInfo();
|
2009-09-04 02:13:48 +04:00
|
|
|
|
|
|
|
switch (Name.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
|
|
|
case DeclarationName::CXXOperatorName:
|
2009-11-29 10:34:05 +03:00
|
|
|
case DeclarationName::CXXLiteralOperatorName:
|
2009-09-04 02:13:48 +04:00
|
|
|
case DeclarationName::CXXUsingDirective:
|
2010-08-12 02:01:17 +04:00
|
|
|
return NameInfo;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-09-04 02:13:48 +04:00
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXConversionFunctionName: {
|
2010-08-12 02:01:17 +04:00
|
|
|
TypeSourceInfo *NewTInfo;
|
|
|
|
CanQualType NewCanTy;
|
|
|
|
if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
|
2010-11-12 11:19:04 +03:00
|
|
|
NewTInfo = getDerived().TransformType(OldTInfo);
|
|
|
|
if (!NewTInfo)
|
|
|
|
return DeclarationNameInfo();
|
|
|
|
NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
|
2010-08-12 02:01:17 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NewTInfo = 0;
|
|
|
|
TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType NewT = getDerived().TransformType(Name.getCXXNameType());
|
2010-08-12 02:01:17 +04:00
|
|
|
if (NewT.isNull())
|
|
|
|
return DeclarationNameInfo();
|
|
|
|
NewCanTy = SemaRef.Context.getCanonicalType(NewT);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationName NewName
|
|
|
|
= SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
|
|
|
|
NewCanTy);
|
|
|
|
DeclarationNameInfo NewNameInfo(NameInfo);
|
|
|
|
NewNameInfo.setName(NewName);
|
|
|
|
NewNameInfo.setNamedTypeInfo(NewTInfo);
|
|
|
|
return NewNameInfo;
|
2009-09-04 02:13:48 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
assert(0 && "Unknown name kind.");
|
|
|
|
return DeclarationNameInfo();
|
2009-09-04 02:13:48 +04:00
|
|
|
}
|
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
TemplateName
|
2009-09-09 04:23:06 +04:00
|
|
|
TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *FirstQualifierInScope) {
|
2010-03-01 18:56:25 +03:00
|
|
|
SourceLocation Loc = getDerived().getBaseLocation();
|
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
|
2009-09-09 19:08:12 +04:00
|
|
|
NestedNameSpecifier *NNS
|
2009-08-06 10:41:21 +04:00
|
|
|
= getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
|
2010-11-12 11:19:04 +03:00
|
|
|
/*FIXME*/ SourceRange(Loc),
|
|
|
|
ObjectType,
|
|
|
|
FirstQualifierInScope);
|
2009-08-06 10:41:21 +04:00
|
|
|
if (!NNS)
|
|
|
|
return TemplateName();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
if (TemplateDecl *Template = QTN->getTemplateDecl()) {
|
2009-09-09 19:08:12 +04:00
|
|
|
TemplateDecl *TransTemplate
|
2010-03-01 18:56:25 +03:00
|
|
|
= cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
|
2009-08-06 10:41:21 +04:00
|
|
|
if (!TransTemplate)
|
|
|
|
return TemplateName();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
NNS == QTN->getQualifier() &&
|
|
|
|
TransTemplate == Template)
|
|
|
|
return Name;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
|
|
|
|
TransTemplate);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-24 22:00:30 +03:00
|
|
|
// These should be getting filtered out before they make it into the AST.
|
2010-11-12 11:19:04 +03:00
|
|
|
llvm_unreachable("overloaded template name survived to here");
|
2009-08-06 10:41:21 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
|
2010-11-12 11:19:04 +03:00
|
|
|
NestedNameSpecifier *NNS = DTN->getQualifier();
|
|
|
|
if (NNS) {
|
|
|
|
NNS = getDerived().TransformNestedNameSpecifier(NNS,
|
|
|
|
/*FIXME:*/SourceRange(Loc),
|
|
|
|
ObjectType,
|
|
|
|
FirstQualifierInScope);
|
|
|
|
if (!NNS) return TemplateName();
|
|
|
|
|
|
|
|
// These apply to the scope specifier, not the template.
|
|
|
|
ObjectType = QualType();
|
|
|
|
FirstQualifierInScope = 0;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2009-10-20 02:04:39 +04:00
|
|
|
NNS == DTN->getQualifier() &&
|
|
|
|
ObjectType.isNull())
|
2009-08-06 10:41:21 +04:00
|
|
|
return Name;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-09-09 03:56:00 +04:00
|
|
|
if (DTN->isIdentifier()) {
|
|
|
|
// FIXME: Bad range
|
|
|
|
SourceRange QualifierRange(getDerived().getBaseLocation());
|
|
|
|
return getDerived().RebuildTemplateName(NNS, QualifierRange,
|
|
|
|
*DTN->getIdentifier(),
|
2010-11-12 11:19:04 +03:00
|
|
|
ObjectType,
|
|
|
|
FirstQualifierInScope);
|
2010-09-09 03:56:00 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
|
2009-11-04 03:56:37 +03:00
|
|
|
ObjectType);
|
2009-08-06 10:41:21 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
|
2009-09-09 19:08:12 +04:00
|
|
|
TemplateDecl *TransTemplate
|
2010-03-01 18:56:25 +03:00
|
|
|
= cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
|
2009-08-06 10:41:21 +04:00
|
|
|
if (!TransTemplate)
|
|
|
|
return TemplateName();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
TransTemplate == Template)
|
|
|
|
return Name;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
return TemplateName(TransTemplate);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-15 09:45:20 +03:00
|
|
|
if (SubstTemplateTemplateParmPackStorage *SubstPack
|
|
|
|
= Name.getAsSubstTemplateTemplateParmPack()) {
|
|
|
|
TemplateTemplateParmDecl *TransParam
|
|
|
|
= cast_or_null<TemplateTemplateParmDecl>(
|
|
|
|
getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
|
|
|
|
if (!TransParam)
|
|
|
|
return TemplateName();
|
|
|
|
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
TransParam == SubstPack->getParameterPack())
|
|
|
|
return Name;
|
|
|
|
|
|
|
|
return getDerived().RebuildTemplateName(TransParam,
|
|
|
|
SubstPack->getArgumentPack());
|
|
|
|
}
|
|
|
|
|
2009-11-24 22:00:30 +03:00
|
|
|
// These should be getting filtered out before they reach the AST.
|
2010-11-12 11:19:04 +03:00
|
|
|
llvm_unreachable("overloaded function decl survived to here");
|
2009-11-24 22:00:30 +03:00
|
|
|
return TemplateName();
|
2009-08-06 10:41:21 +04:00
|
|
|
}
|
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
template<typename Derived>
|
2009-10-29 11:12:44 +03:00
|
|
|
void TreeTransform<Derived>::InventTemplateArgumentLoc(
|
|
|
|
const TemplateArgument &Arg,
|
|
|
|
TemplateArgumentLoc &Output) {
|
|
|
|
SourceLocation Loc = getDerived().getBaseLocation();
|
2009-08-05 02:27:00 +04:00
|
|
|
switch (Arg.getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
2009-12-12 08:05:38 +03:00
|
|
|
llvm_unreachable("null template argument in TreeTransform");
|
2009-10-29 11:12:44 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Type:
|
|
|
|
Output = TemplateArgumentLoc(Arg,
|
2009-12-07 05:54:59 +03:00
|
|
|
SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
break;
|
|
|
|
|
2009-11-11 04:00:40 +03:00
|
|
|
case TemplateArgument::Template:
|
|
|
|
Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
|
|
|
|
break;
|
2011-01-05 21:58:31 +03:00
|
|
|
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
|
|
|
|
break;
|
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
case TemplateArgument::Expression:
|
|
|
|
Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Declaration:
|
2009-08-05 02:27:00 +04:00
|
|
|
case TemplateArgument::Integral:
|
2009-10-29 11:12:44 +03:00
|
|
|
case TemplateArgument::Pack:
|
2009-10-29 21:45:58 +03:00
|
|
|
Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
|
2009-10-29 11:12:44 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
bool TreeTransform<Derived>::TransformTemplateArgument(
|
|
|
|
const TemplateArgumentLoc &Input,
|
|
|
|
TemplateArgumentLoc &Output) {
|
|
|
|
const TemplateArgument &Arg = Input.getArgument();
|
|
|
|
switch (Arg.getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
case TemplateArgument::Integral:
|
|
|
|
Output = Input;
|
|
|
|
return false;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
case TemplateArgument::Type: {
|
2009-12-07 05:54:59 +03:00
|
|
|
TypeSourceInfo *DI = Input.getTypeSourceInfo();
|
2009-10-29 11:12:44 +03:00
|
|
|
if (DI == NULL)
|
2009-12-07 05:54:59 +03:00
|
|
|
DI = InventTypeSourceInfo(Input.getArgument().getAsType());
|
2009-10-29 11:12:44 +03:00
|
|
|
|
|
|
|
DI = getDerived().TransformType(DI);
|
|
|
|
if (!DI) return true;
|
|
|
|
|
|
|
|
Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
|
|
|
|
return false;
|
2009-08-05 02:27:00 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
case TemplateArgument::Declaration: {
|
2009-10-29 11:12:44 +03:00
|
|
|
// FIXME: we should never have to transform one of these.
|
2009-10-27 09:26:26 +03:00
|
|
|
DeclarationName Name;
|
|
|
|
if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
|
|
|
|
Name = ND->getDeclName();
|
2009-11-11 04:00:40 +03:00
|
|
|
TemporaryBase Rebase(*this, Input.getLocation(), Name);
|
2010-03-01 18:56:25 +03:00
|
|
|
Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
|
2009-10-29 11:12:44 +03:00
|
|
|
if (!D) return true;
|
|
|
|
|
2009-10-29 21:45:58 +03:00
|
|
|
Expr *SourceExpr = Input.getSourceDeclExpression();
|
|
|
|
if (SourceExpr) {
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(getSema(),
|
2010-08-27 03:41:50 +04:00
|
|
|
Sema::Unevaluated);
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult E = getDerived().TransformExpr(SourceExpr);
|
2010-08-24 03:25:46 +04:00
|
|
|
SourceExpr = (E.isInvalid() ? 0 : E.take());
|
2009-10-29 21:45:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
|
2009-10-29 11:12:44 +03:00
|
|
|
return false;
|
2009-08-05 02:27:00 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-11 04:00:40 +03:00
|
|
|
case TemplateArgument::Template: {
|
2010-05-05 19:23:54 +04:00
|
|
|
TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
|
2009-11-11 04:00:40 +03:00
|
|
|
TemplateName Template
|
|
|
|
= getDerived().TransformTemplateName(Arg.getAsTemplate());
|
|
|
|
if (Template.isNull())
|
|
|
|
return true;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-11-11 04:00:40 +03:00
|
|
|
Output = TemplateArgumentLoc(TemplateArgument(Template),
|
|
|
|
Input.getTemplateQualifierRange(),
|
|
|
|
Input.getTemplateNameLoc());
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-05 21:58:31 +03:00
|
|
|
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
llvm_unreachable("Caller should expand pack expansions");
|
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
case TemplateArgument::Expression: {
|
|
|
|
// Template argument expressions are not potentially evaluated.
|
2009-09-09 19:08:12 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(getSema(),
|
2010-08-27 03:41:50 +04:00
|
|
|
Sema::Unevaluated);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
Expr *InputExpr = Input.getSourceExpression();
|
|
|
|
if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
|
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult E
|
2009-10-29 11:12:44 +03:00
|
|
|
= getDerived().TransformExpr(InputExpr);
|
|
|
|
if (E.isInvalid()) return true;
|
2010-08-24 03:25:46 +04:00
|
|
|
Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
|
2009-10-29 11:12:44 +03:00
|
|
|
return false;
|
2009-08-05 02:27:00 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
case TemplateArgument::Pack: {
|
|
|
|
llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
|
|
|
|
TransformedArgs.reserve(Arg.pack_size());
|
2009-09-09 19:08:12 +04:00
|
|
|
for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
|
2009-08-05 02:27:00 +04:00
|
|
|
AEnd = Arg.pack_end();
|
|
|
|
A != AEnd; ++A) {
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
// FIXME: preserve source information here when we start
|
|
|
|
// caring about parameter packs.
|
|
|
|
|
2009-10-29 21:45:58 +03:00
|
|
|
TemplateArgumentLoc InputArg;
|
|
|
|
TemplateArgumentLoc OutputArg;
|
|
|
|
getDerived().InventTemplateArgumentLoc(*A, InputArg);
|
|
|
|
if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
|
2009-10-29 11:12:44 +03:00
|
|
|
return true;
|
|
|
|
|
2009-10-29 21:45:58 +03:00
|
|
|
TransformedArgs.push_back(OutputArg.getArgument());
|
2009-08-05 02:27:00 +04:00
|
|
|
}
|
2010-11-08 02:05:16 +03:00
|
|
|
|
|
|
|
TemplateArgument *TransformedArgsPtr
|
|
|
|
= new (getSema().Context) TemplateArgument[TransformedArgs.size()];
|
|
|
|
std::copy(TransformedArgs.begin(), TransformedArgs.end(),
|
|
|
|
TransformedArgsPtr);
|
|
|
|
Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
|
|
|
|
TransformedArgs.size()),
|
|
|
|
Input.getLocInfo());
|
2009-10-29 11:12:44 +03:00
|
|
|
return false;
|
2009-08-05 02:27:00 +04:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
// Work around bogus GCC warning
|
2009-10-29 11:12:44 +03:00
|
|
|
return true;
|
2009-08-05 02:27:00 +04:00
|
|
|
}
|
|
|
|
|
2010-12-21 02:36:19 +03:00
|
|
|
/// \brief Iterator adaptor that invents template argument location information
|
|
|
|
/// for each of the template arguments in its underlying iterator.
|
|
|
|
template<typename Derived, typename InputIterator>
|
|
|
|
class TemplateArgumentLocInventIterator {
|
|
|
|
TreeTransform<Derived> &Self;
|
|
|
|
InputIterator Iter;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef TemplateArgumentLoc value_type;
|
|
|
|
typedef TemplateArgumentLoc reference;
|
|
|
|
typedef typename std::iterator_traits<InputIterator>::difference_type
|
|
|
|
difference_type;
|
|
|
|
typedef std::input_iterator_tag iterator_category;
|
|
|
|
|
|
|
|
class pointer {
|
|
|
|
TemplateArgumentLoc Arg;
|
2010-12-20 20:31:10 +03:00
|
|
|
|
2010-12-21 02:36:19 +03:00
|
|
|
public:
|
|
|
|
explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
|
|
|
|
|
|
|
|
const TemplateArgumentLoc *operator->() const { return &Arg; }
|
|
|
|
};
|
|
|
|
|
|
|
|
TemplateArgumentLocInventIterator() { }
|
|
|
|
|
|
|
|
explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
|
|
|
|
InputIterator Iter)
|
|
|
|
: Self(Self), Iter(Iter) { }
|
|
|
|
|
|
|
|
TemplateArgumentLocInventIterator &operator++() {
|
|
|
|
++Iter;
|
|
|
|
return *this;
|
2010-12-20 20:31:10 +03:00
|
|
|
}
|
|
|
|
|
2010-12-21 02:36:19 +03:00
|
|
|
TemplateArgumentLocInventIterator operator++(int) {
|
|
|
|
TemplateArgumentLocInventIterator Old(*this);
|
|
|
|
++(*this);
|
|
|
|
return Old;
|
|
|
|
}
|
|
|
|
|
|
|
|
reference operator*() const {
|
|
|
|
TemplateArgumentLoc Result;
|
|
|
|
Self.InventTemplateArgumentLoc(*Iter, Result);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
pointer operator->() const { return pointer(**this); }
|
|
|
|
|
|
|
|
friend bool operator==(const TemplateArgumentLocInventIterator &X,
|
|
|
|
const TemplateArgumentLocInventIterator &Y) {
|
|
|
|
return X.Iter == Y.Iter;
|
|
|
|
}
|
2010-12-20 20:31:10 +03:00
|
|
|
|
2010-12-21 02:36:19 +03:00
|
|
|
friend bool operator!=(const TemplateArgumentLocInventIterator &X,
|
|
|
|
const TemplateArgumentLocInventIterator &Y) {
|
|
|
|
return X.Iter != Y.Iter;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-12-20 20:42:22 +03:00
|
|
|
template<typename Derived>
|
2010-12-21 02:36:19 +03:00
|
|
|
template<typename InputIterator>
|
|
|
|
bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
|
|
|
|
InputIterator Last,
|
2010-12-20 20:42:22 +03:00
|
|
|
TemplateArgumentListInfo &Outputs) {
|
2010-12-21 02:36:19 +03:00
|
|
|
for (; First != Last; ++First) {
|
2010-12-20 20:42:22 +03:00
|
|
|
TemplateArgumentLoc Out;
|
2010-12-21 02:36:19 +03:00
|
|
|
TemplateArgumentLoc In = *First;
|
2010-12-21 01:05:00 +03:00
|
|
|
|
|
|
|
if (In.getArgument().getKind() == TemplateArgument::Pack) {
|
|
|
|
// Unpack argument packs, which we translate them into separate
|
|
|
|
// arguments.
|
2010-12-21 02:36:19 +03:00
|
|
|
// FIXME: We could do much better if we could guarantee that the
|
|
|
|
// TemplateArgumentLocInfo for the pack expansion would be usable for
|
|
|
|
// all of the template arguments in the argument pack.
|
|
|
|
typedef TemplateArgumentLocInventIterator<Derived,
|
|
|
|
TemplateArgument::pack_iterator>
|
|
|
|
PackLocIterator;
|
|
|
|
if (TransformTemplateArguments(PackLocIterator(*this,
|
|
|
|
In.getArgument().pack_begin()),
|
|
|
|
PackLocIterator(*this,
|
|
|
|
In.getArgument().pack_end()),
|
|
|
|
Outputs))
|
|
|
|
return true;
|
2010-12-21 01:05:00 +03:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (In.getArgument().isPackExpansion()) {
|
|
|
|
// We have a pack expansion, for which we will be substituting into
|
|
|
|
// the pattern.
|
|
|
|
SourceLocation Ellipsis;
|
2011-01-14 20:04:44 +03:00
|
|
|
llvm::Optional<unsigned> OrigNumExpansions;
|
2010-12-21 01:05:00 +03:00
|
|
|
TemplateArgumentLoc Pattern
|
2011-01-14 20:04:44 +03:00
|
|
|
= In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
|
|
|
|
getSema().Context);
|
2010-12-21 01:05:00 +03:00
|
|
|
|
|
|
|
llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
|
|
|
|
getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
|
|
|
|
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
|
|
|
|
|
|
|
|
// Determine whether the set of unexpanded parameter packs can and should
|
|
|
|
// be expanded.
|
|
|
|
bool Expand = true;
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
bool RetainExpansion = false;
|
2011-01-14 20:04:44 +03:00
|
|
|
llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
|
2010-12-21 01:05:00 +03:00
|
|
|
if (getDerived().TryExpandParameterPacks(Ellipsis,
|
|
|
|
Pattern.getSourceRange(),
|
|
|
|
Unexpanded.data(),
|
|
|
|
Unexpanded.size(),
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
Expand,
|
|
|
|
RetainExpansion,
|
|
|
|
NumExpansions))
|
2010-12-21 01:05:00 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!Expand) {
|
|
|
|
// The transform has determined that we should perform a simple
|
|
|
|
// transformation on the pack expansion, producing another pack
|
|
|
|
// expansion.
|
|
|
|
TemplateArgumentLoc OutPattern;
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
|
|
|
|
if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
|
|
|
|
return true;
|
|
|
|
|
2011-01-14 20:04:44 +03:00
|
|
|
Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
|
|
|
|
NumExpansions);
|
2010-12-21 01:05:00 +03:00
|
|
|
if (Out.getArgument().isNull())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Outputs.addArgument(Out);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The transform has determined that we should perform an elementwise
|
|
|
|
// expansion of the pattern. Do so.
|
2011-01-14 20:04:44 +03:00
|
|
|
for (unsigned I = 0; I != *NumExpansions; ++I) {
|
2010-12-21 01:05:00 +03:00
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
|
|
|
|
|
|
|
|
if (getDerived().TransformTemplateArgument(Pattern, Out))
|
|
|
|
return true;
|
|
|
|
|
2011-01-12 01:21:24 +03:00
|
|
|
if (Out.getArgument().containsUnexpandedParameterPack()) {
|
2011-01-14 20:04:44 +03:00
|
|
|
Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
|
|
|
|
OrigNumExpansions);
|
2011-01-12 01:21:24 +03:00
|
|
|
if (Out.getArgument().isNull())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-21 01:05:00 +03:00
|
|
|
Outputs.addArgument(Out);
|
|
|
|
}
|
|
|
|
|
2011-01-10 23:53:55 +03:00
|
|
|
// If we're supposed to retain a pack expansion, do so by temporarily
|
|
|
|
// forgetting the partially-substituted parameter pack.
|
|
|
|
if (RetainExpansion) {
|
|
|
|
ForgetPartiallySubstitutedPackRAII Forget(getDerived());
|
|
|
|
|
|
|
|
if (getDerived().TransformTemplateArgument(Pattern, Out))
|
|
|
|
return true;
|
|
|
|
|
2011-01-14 20:04:44 +03:00
|
|
|
Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
|
|
|
|
OrigNumExpansions);
|
2011-01-10 23:53:55 +03:00
|
|
|
if (Out.getArgument().isNull())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Outputs.addArgument(Out);
|
|
|
|
}
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
|
2010-12-21 01:05:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The simple case:
|
|
|
|
if (getDerived().TransformTemplateArgument(In, Out))
|
2010-12-20 20:42:22 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
Outputs.addArgument(Out);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type transformation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType TreeTransform<Derived>::TransformType(QualType T) {
|
2009-08-04 20:50:30 +04:00
|
|
|
if (getDerived().AlreadyTransformed(T))
|
|
|
|
return T;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
// Temporary workaround. All of these transformations should
|
|
|
|
// eventually turn into transformations on TypeLocs.
|
2009-12-07 05:54:59 +03:00
|
|
|
TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
|
2009-10-21 04:44:26 +04:00
|
|
|
DI->getTypeLoc().initialize(getDerived().getBaseLocation());
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
TypeSourceInfo *NewDI = getDerived().TransformType(DI);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
if (!NewDI)
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
return NewDI->getType();
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2010-11-12 11:19:04 +03:00
|
|
|
TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
|
2009-10-21 04:40:46 +04:00
|
|
|
if (getDerived().AlreadyTransformed(DI->getType()))
|
|
|
|
return DI;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeLocBuilder TLB;
|
2009-08-19 05:28:17 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeLoc TL = DI->getTypeLoc();
|
|
|
|
TLB.reserve(TL.getFullDataSize());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType Result = getDerived().TransformType(TLB, TL);
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return 0;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-12-07 05:54:59 +03:00
|
|
|
return TLB.getTypeSourceInfo(SemaRef.Context, Result);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType
|
2010-11-12 11:19:04 +03:00
|
|
|
TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
|
2009-10-21 04:40:46 +04:00
|
|
|
switch (T.getTypeLocClass()) {
|
|
|
|
#define ABSTRACT_TYPELOC(CLASS, PARENT)
|
|
|
|
#define TYPELOC(CLASS, PARENT) \
|
|
|
|
case TypeLoc::CLASS: \
|
2010-11-12 11:19:04 +03:00
|
|
|
return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
|
2009-10-21 04:40:46 +04:00
|
|
|
#include "clang/AST/TypeLocNodes.def"
|
|
|
|
}
|
2009-08-04 20:50:30 +04:00
|
|
|
|
2009-12-12 08:05:38 +03:00
|
|
|
llvm_unreachable("unhandled type loc!");
|
2009-10-21 04:40:46 +04:00
|
|
|
return QualType();
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
/// FIXME: By default, this routine adds type qualifiers only to types
|
|
|
|
/// that can have qualifiers, and silently suppresses those qualifiers
|
|
|
|
/// that are not permitted (e.g., qualifiers on reference or function
|
|
|
|
/// types). This is the right thing for template instantiation, but
|
|
|
|
/// probably not for other clients.
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
2009-10-21 04:40:46 +04:00
|
|
|
TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
QualifiedTypeLoc T) {
|
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88969 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-17 00:35:15 +03:00
|
|
|
Qualifiers Quals = T.getType().getLocalQualifiers();
|
2009-10-21 04:40:46 +04:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
2009-08-04 20:50:30 +04:00
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
// Silently suppress qualifiers if the result type can't be qualified.
|
|
|
|
// FIXME: this is the right thing for template instantiation, but
|
|
|
|
// probably not for other clients.
|
|
|
|
if (Result->isFunctionType() || Result->isReferenceType())
|
|
|
|
return Result;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-06-05 10:41:15 +04:00
|
|
|
if (!Quals.empty()) {
|
|
|
|
Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
|
|
|
|
TLB.push<QualifiedTypeLoc>(Result);
|
|
|
|
// No location information to preserve.
|
|
|
|
}
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
/// \brief Transforms a type that was written in a scope specifier,
|
|
|
|
/// given an object type, the results of unqualified lookup, and
|
|
|
|
/// an already-instantiated prefix.
|
|
|
|
///
|
|
|
|
/// The object type is provided iff the scope specifier qualifies the
|
|
|
|
/// member of a dependent member-access expression. The prefix is
|
|
|
|
/// provided iff the the scope specifier in which this appears has a
|
|
|
|
/// prefix.
|
|
|
|
///
|
|
|
|
/// This is private to TreeTransform.
|
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
|
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *UnqualLookup,
|
|
|
|
NestedNameSpecifier *Prefix) {
|
|
|
|
if (getDerived().AlreadyTransformed(T))
|
|
|
|
return T;
|
|
|
|
|
|
|
|
TypeSourceInfo *TSI =
|
|
|
|
SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
|
|
|
|
|
|
|
|
TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
|
|
|
|
UnqualLookup, Prefix);
|
|
|
|
if (!TSI) return QualType();
|
|
|
|
return TSI->getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
TypeSourceInfo *
|
|
|
|
TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
|
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *UnqualLookup,
|
|
|
|
NestedNameSpecifier *Prefix) {
|
|
|
|
// TODO: in some cases, we might be some verification to do here.
|
|
|
|
if (ObjectType.isNull())
|
|
|
|
return getDerived().TransformType(TSI);
|
|
|
|
|
|
|
|
QualType T = TSI->getType();
|
|
|
|
if (getDerived().AlreadyTransformed(T))
|
|
|
|
return TSI;
|
|
|
|
|
|
|
|
TypeLocBuilder TLB;
|
|
|
|
QualType Result;
|
|
|
|
|
|
|
|
if (isa<TemplateSpecializationType>(T)) {
|
|
|
|
TemplateSpecializationTypeLoc TL
|
|
|
|
= cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
|
|
|
|
|
|
|
|
TemplateName Template =
|
|
|
|
getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
|
|
|
|
ObjectType, UnqualLookup);
|
|
|
|
if (Template.isNull()) return 0;
|
|
|
|
|
|
|
|
Result = getDerived()
|
|
|
|
.TransformTemplateSpecializationType(TLB, TL, Template);
|
|
|
|
} else if (isa<DependentTemplateSpecializationType>(T)) {
|
|
|
|
DependentTemplateSpecializationTypeLoc TL
|
|
|
|
= cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
|
|
|
|
|
|
|
|
Result = getDerived()
|
|
|
|
.TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
|
|
|
|
} else {
|
|
|
|
// Nothing special needs to be done for these.
|
|
|
|
Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Result.isNull()) return 0;
|
|
|
|
return TLB.getTypeSourceInfo(SemaRef.Context, Result);
|
|
|
|
}
|
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
template <class TyLoc> static inline
|
|
|
|
QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
|
|
|
|
TyLoc NewT = TLB.push<TyLoc>(T.getType());
|
|
|
|
NewT.setNameLoc(T.getNameLoc());
|
|
|
|
return T.getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
BuiltinTypeLoc T) {
|
2010-01-18 21:04:31 +03:00
|
|
|
BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
|
|
|
|
NewT.setBuiltinLoc(T.getBuiltinLoc());
|
|
|
|
if (T.needsExtraLocalData())
|
|
|
|
NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
|
|
|
|
return T.getType();
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
ComplexTypeLoc T) {
|
2009-10-21 04:40:46 +04:00
|
|
|
// FIXME: recurse?
|
|
|
|
return TransformTypeSpecType(TLB, T);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
PointerTypeLoc TL) {
|
2010-05-05 19:23:54 +04:00
|
|
|
QualType PointeeType
|
|
|
|
= getDerived().TransformType(TLB, TL.getPointeeLoc());
|
2010-04-22 20:44:27 +04:00
|
|
|
if (PointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
2010-05-15 15:32:37 +04:00
|
|
|
if (PointeeType->getAs<ObjCObjectType>()) {
|
2010-04-22 20:44:27 +04:00
|
|
|
// A dependent pointer type 'T *' has is being transformed such
|
|
|
|
// that an Objective-C class type is being replaced for 'T'. The
|
|
|
|
// resulting pointer type is an ObjCObjectPointerType, not a
|
|
|
|
// PointerType.
|
2010-05-15 15:32:37 +04:00
|
|
|
Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-05-15 15:32:37 +04:00
|
|
|
ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
|
|
|
|
NewT.setStarLoc(TL.getStarLoc());
|
2010-04-22 20:44:27 +04:00
|
|
|
return Result;
|
|
|
|
}
|
2010-11-12 11:19:04 +03:00
|
|
|
|
2010-04-22 20:44:27 +04:00
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
PointeeType != TL.getPointeeLoc().getType()) {
|
|
|
|
Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-22 20:44:27 +04:00
|
|
|
PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
|
|
|
|
NewT.setSigilLoc(TL.getSigilLoc());
|
2010-05-05 19:23:54 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
2009-10-21 04:40:46 +04:00
|
|
|
TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
BlockPointerTypeLoc TL) {
|
2010-04-22 20:46:21 +04:00
|
|
|
QualType PointeeType
|
2010-05-05 19:23:54 +04:00
|
|
|
= getDerived().TransformType(TLB, TL.getPointeeLoc());
|
|
|
|
if (PointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
PointeeType != TL.getPointeeLoc().getType()) {
|
|
|
|
Result = getDerived().RebuildBlockPointerType(PointeeType,
|
2010-04-22 20:46:21 +04:00
|
|
|
TL.getSigilLoc());
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
2010-04-22 20:50:51 +04:00
|
|
|
BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
|
2010-04-22 20:46:21 +04:00
|
|
|
NewT.setSigilLoc(TL.getSigilLoc());
|
|
|
|
return Result;
|
2009-10-21 04:40:46 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-30 03:06:24 +03:00
|
|
|
/// Transforms a reference type. Note that somewhat paradoxically we
|
|
|
|
/// don't care whether the type itself is an l-value type or an r-value
|
|
|
|
/// type; we only care if the type was *written* as an l-value type
|
|
|
|
/// or an r-value type.
|
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
ReferenceTypeLoc TL) {
|
2009-10-30 03:06:24 +03:00
|
|
|
const ReferenceType *T = TL.getTypePtr();
|
|
|
|
|
|
|
|
// Note that this works with the pointee-as-written.
|
|
|
|
QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
|
|
|
|
if (PointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
PointeeType != T->getPointeeTypeAsWritten()) {
|
|
|
|
Result = getDerived().RebuildReferenceType(PointeeType,
|
|
|
|
T->isSpelledAsLValue(),
|
|
|
|
TL.getSigilLoc());
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
// r-value references can be rebuilt as l-value references.
|
|
|
|
ReferenceTypeLoc NewTL;
|
|
|
|
if (isa<LValueReferenceType>(Result))
|
|
|
|
NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
|
|
|
|
else
|
|
|
|
NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
|
|
|
|
NewTL.setSigilLoc(TL.getSigilLoc());
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
LValueReferenceTypeLoc TL) {
|
|
|
|
return TransformReferenceType(TLB, TL);
|
2009-10-21 04:40:46 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
RValueReferenceTypeLoc TL) {
|
|
|
|
return TransformReferenceType(TLB, TL);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType
|
2009-10-21 04:40:46 +04:00
|
|
|
TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
MemberPointerTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const MemberPointerType *T = TL.getTypePtr();
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (PointeeType.isNull())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
// TODO: preserve source information for this.
|
|
|
|
QualType ClassType
|
|
|
|
= getDerived().TransformType(QualType(T->getClass(), 0));
|
2009-08-04 20:50:30 +04:00
|
|
|
if (ClassType.isNull())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
PointeeType != T->getPointeeType() ||
|
|
|
|
ClassType != QualType(T->getClass(), 0)) {
|
2009-10-30 03:06:24 +03:00
|
|
|
Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
|
|
|
|
TL.getStarLoc());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2009-08-04 20:50:30 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
|
|
|
|
NewTL.setSigilLoc(TL.getSigilLoc());
|
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
2009-10-21 04:40:46 +04:00
|
|
|
TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
ConstantArrayTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const ConstantArrayType *T = TL.getTypePtr();
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (ElementType.isNull())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
ElementType != T->getElementType()) {
|
|
|
|
Result = getDerived().RebuildConstantArrayType(ElementType,
|
|
|
|
T->getSizeModifier(),
|
|
|
|
T->getSize(),
|
2009-10-30 03:06:24 +03:00
|
|
|
T->getIndexTypeCVRQualifiers(),
|
|
|
|
TL.getBracketsRange());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
|
|
|
|
NewTL.setLBracketLoc(TL.getLBracketLoc());
|
|
|
|
NewTL.setRBracketLoc(TL.getRBracketLoc());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
Expr *Size = TL.getSizeExpr();
|
|
|
|
if (Size) {
|
2010-08-27 03:41:50 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
2009-10-21 04:40:46 +04:00
|
|
|
Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
|
|
|
|
}
|
|
|
|
NewTL.setSizeExpr(Size);
|
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-08-04 20:50:30 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformIncompleteArrayType(
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
IncompleteArrayTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const IncompleteArrayType *T = TL.getTypePtr();
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (ElementType.isNull())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
ElementType != T->getElementType()) {
|
|
|
|
Result = getDerived().RebuildIncompleteArrayType(ElementType,
|
|
|
|
T->getSizeModifier(),
|
2009-10-30 03:06:24 +03:00
|
|
|
T->getIndexTypeCVRQualifiers(),
|
|
|
|
TL.getBracketsRange());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
|
|
|
|
NewTL.setLBracketLoc(TL.getLBracketLoc());
|
|
|
|
NewTL.setRBracketLoc(TL.getRBracketLoc());
|
|
|
|
NewTL.setSizeExpr(0);
|
2009-08-04 20:50:30 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
VariableArrayTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const VariableArrayType *T = TL.getTypePtr();
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (ElementType.isNull())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
// Array bounds are not potentially evaluated contexts
|
2010-08-27 03:41:50 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
2009-08-05 02:27:00 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SizeResult
|
2009-10-21 04:40:46 +04:00
|
|
|
= getDerived().TransformExpr(T->getSizeExpr());
|
|
|
|
if (SizeResult.isInvalid())
|
2009-08-04 20:50:30 +04:00
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Size = SizeResult.take();
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
ElementType != T->getElementType() ||
|
|
|
|
Size != T->getSizeExpr()) {
|
|
|
|
Result = getDerived().RebuildVariableArrayType(ElementType,
|
|
|
|
T->getSizeModifier(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Size,
|
2009-10-21 04:40:46 +04:00
|
|
|
T->getIndexTypeCVRQualifiers(),
|
2009-10-30 03:06:24 +03:00
|
|
|
TL.getBracketsRange());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
|
|
|
|
NewTL.setLBracketLoc(TL.getLBracketLoc());
|
|
|
|
NewTL.setRBracketLoc(TL.getRBracketLoc());
|
|
|
|
NewTL.setSizeExpr(Size);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
DependentSizedArrayTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const DependentSizedArrayType *T = TL.getTypePtr();
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (ElementType.isNull())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
// Array bounds are not potentially evaluated contexts
|
2010-08-27 03:41:50 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SizeResult
|
2009-10-21 04:40:46 +04:00
|
|
|
= getDerived().TransformExpr(T->getSizeExpr());
|
|
|
|
if (SizeResult.isInvalid())
|
2009-08-04 20:50:30 +04:00
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
Expr *Size = static_cast<Expr*>(SizeResult.get());
|
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
ElementType != T->getElementType() ||
|
|
|
|
Size != T->getSizeExpr()) {
|
|
|
|
Result = getDerived().RebuildDependentSizedArrayType(ElementType,
|
|
|
|
T->getSizeModifier(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Size,
|
2009-10-21 04:40:46 +04:00
|
|
|
T->getIndexTypeCVRQualifiers(),
|
2009-10-30 03:06:24 +03:00
|
|
|
TL.getBracketsRange());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-10-21 04:40:46 +04:00
|
|
|
else SizeResult.take();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
// We might have any sort of array type now, but fortunately they
|
|
|
|
// all have the same location layout.
|
|
|
|
ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
|
|
|
|
NewTL.setLBracketLoc(TL.getLBracketLoc());
|
|
|
|
NewTL.setRBracketLoc(TL.getRBracketLoc());
|
|
|
|
NewTL.setSizeExpr(Size);
|
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-08-04 20:50:30 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
DependentSizedExtVectorTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const DependentSizedExtVectorType *T = TL.getTypePtr();
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
// FIXME: ext vector locs should be nested
|
2009-08-04 20:50:30 +04:00
|
|
|
QualType ElementType = getDerived().TransformType(T->getElementType());
|
|
|
|
if (ElementType.isNull())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
// Vector sizes are not potentially evaluated contexts
|
2010-08-27 03:41:50 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
2009-08-05 02:27:00 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (Size.isInvalid())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
2009-10-23 21:55:45 +04:00
|
|
|
ElementType != T->getElementType() ||
|
|
|
|
Size.get() != T->getSizeExpr()) {
|
2009-10-21 04:40:46 +04:00
|
|
|
Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
|
2010-08-24 03:25:46 +04:00
|
|
|
Size.take(),
|
2009-08-04 20:50:30 +04:00
|
|
|
T->getAttributeLoc());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Result might be dependent or not.
|
|
|
|
if (isa<DependentSizedExtVectorType>(Result)) {
|
|
|
|
DependentSizedExtVectorTypeLoc NewTL
|
|
|
|
= TLB.push<DependentSizedExtVectorTypeLoc>(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
|
|
|
} else {
|
|
|
|
ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
VectorTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const VectorType *T = TL.getTypePtr();
|
2009-08-04 20:50:30 +04:00
|
|
|
QualType ElementType = getDerived().TransformType(T->getElementType());
|
|
|
|
if (ElementType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
ElementType != T->getElementType()) {
|
2010-02-05 03:12:22 +03:00
|
|
|
Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
|
2010-11-11 00:56:12 +03:00
|
|
|
T->getVectorKind());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
ExtVectorTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const VectorType *T = TL.getTypePtr();
|
2009-08-04 20:50:30 +04:00
|
|
|
QualType ElementType = getDerived().TransformType(T->getElementType());
|
|
|
|
if (ElementType.isNull())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
ElementType != T->getElementType()) {
|
|
|
|
Result = getDerived().RebuildExtVectorType(ElementType,
|
|
|
|
T->getNumElements(),
|
|
|
|
/*FIXME*/ SourceLocation());
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-03-11 12:03:00 +03:00
|
|
|
ParmVarDecl *
|
2011-01-15 01:40:04 +03:00
|
|
|
TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
|
|
|
|
llvm::Optional<unsigned> NumExpansions) {
|
2010-03-11 12:03:00 +03:00
|
|
|
TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
|
2011-01-15 01:40:04 +03:00
|
|
|
TypeSourceInfo *NewDI = 0;
|
|
|
|
|
|
|
|
if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
|
|
|
|
// If we're substituting into a pack expansion type and we know the
|
|
|
|
TypeLoc OldTL = OldDI->getTypeLoc();
|
|
|
|
PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
|
|
|
|
|
|
|
|
TypeLocBuilder TLB;
|
|
|
|
TypeLoc NewTL = OldDI->getTypeLoc();
|
|
|
|
TLB.reserve(NewTL.getFullDataSize());
|
|
|
|
|
|
|
|
QualType Result = getDerived().TransformType(TLB,
|
|
|
|
OldExpansionTL.getPatternLoc());
|
|
|
|
if (Result.isNull())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Result = RebuildPackExpansionType(Result,
|
|
|
|
OldExpansionTL.getPatternLoc().getSourceRange(),
|
|
|
|
OldExpansionTL.getEllipsisLoc(),
|
|
|
|
NumExpansions);
|
|
|
|
if (Result.isNull())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PackExpansionTypeLoc NewExpansionTL
|
|
|
|
= TLB.push<PackExpansionTypeLoc>(Result);
|
|
|
|
NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
|
|
|
|
NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
|
|
|
|
} else
|
|
|
|
NewDI = getDerived().TransformType(OldDI);
|
2010-03-11 12:03:00 +03:00
|
|
|
if (!NewDI)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (NewDI == OldDI)
|
|
|
|
return OldParm;
|
|
|
|
else
|
|
|
|
return ParmVarDecl::Create(SemaRef.Context,
|
|
|
|
OldParm->getDeclContext(),
|
|
|
|
OldParm->getLocation(),
|
|
|
|
OldParm->getIdentifier(),
|
|
|
|
NewDI->getType(),
|
|
|
|
NewDI,
|
|
|
|
OldParm->getStorageClass(),
|
2010-04-20 02:54:31 +04:00
|
|
|
OldParm->getStorageClassAsWritten(),
|
2010-03-11 12:03:00 +03:00
|
|
|
/* DefArg */ NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
bool TreeTransform<Derived>::
|
2011-01-07 03:20:55 +03:00
|
|
|
TransformFunctionTypeParams(SourceLocation Loc,
|
|
|
|
ParmVarDecl **Params, unsigned NumParams,
|
|
|
|
const QualType *ParamTypes,
|
|
|
|
llvm::SmallVectorImpl<QualType> &OutParamTypes,
|
|
|
|
llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
|
|
|
|
for (unsigned i = 0; i != NumParams; ++i) {
|
|
|
|
if (ParmVarDecl *OldParm = Params[i]) {
|
2011-01-15 01:40:04 +03:00
|
|
|
llvm::Optional<unsigned> NumExpansions;
|
2011-01-06 02:12:31 +03:00
|
|
|
if (OldParm->isParameterPack()) {
|
|
|
|
// We have a function parameter pack that may need to be expanded.
|
|
|
|
llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
|
|
|
|
|
|
|
|
// Find the parameter packs that could be expanded.
|
2011-01-06 02:16:57 +03:00
|
|
|
TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
|
|
|
|
PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
|
|
|
|
TypeLoc Pattern = ExpansionTL.getPatternLoc();
|
|
|
|
SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
|
2011-01-06 02:12:31 +03:00
|
|
|
|
|
|
|
// Determine whether we should expand the parameter packs.
|
|
|
|
bool ShouldExpand = false;
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
bool RetainExpansion = false;
|
2011-01-15 01:40:04 +03:00
|
|
|
llvm::Optional<unsigned> OrigNumExpansions
|
|
|
|
= ExpansionTL.getTypePtr()->getNumExpansions();
|
|
|
|
NumExpansions = OrigNumExpansions;
|
2011-01-06 02:16:57 +03:00
|
|
|
if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
|
|
|
|
Pattern.getSourceRange(),
|
2011-01-06 02:12:31 +03:00
|
|
|
Unexpanded.data(),
|
|
|
|
Unexpanded.size(),
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
ShouldExpand,
|
|
|
|
RetainExpansion,
|
|
|
|
NumExpansions)) {
|
2011-01-06 02:12:31 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldExpand) {
|
|
|
|
// Expand the function parameter pack into multiple, separate
|
|
|
|
// parameters.
|
Implement substitution of a function parameter pack for its set of
instantiated function parameters, enabling instantiation of arbitrary
pack expansions involving function parameter packs. At this point, we
can now correctly compile a simple, variadic print() example:
#include <iostream>
#include <string>
void print() {}
template<typename Head, typename ...Tail>
void print(const Head &head, const Tail &...tail) {
std::cout << head;
print(tail...);
}
int main() {
std::string hello = "Hello";
print(hello, ", world!", " ", 2011, '\n');
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123000 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-07 19:43:16 +03:00
|
|
|
getDerived().ExpandingFunctionParameterPack(OldParm);
|
2011-01-14 20:04:44 +03:00
|
|
|
for (unsigned I = 0; I != *NumExpansions; ++I) {
|
2011-01-06 02:12:31 +03:00
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
|
|
|
|
ParmVarDecl *NewParm
|
2011-01-15 01:40:04 +03:00
|
|
|
= getDerived().TransformFunctionTypeParam(OldParm,
|
|
|
|
OrigNumExpansions);
|
2011-01-06 02:12:31 +03:00
|
|
|
if (!NewParm)
|
|
|
|
return true;
|
|
|
|
|
2011-01-07 03:20:55 +03:00
|
|
|
OutParamTypes.push_back(NewParm->getType());
|
|
|
|
if (PVars)
|
|
|
|
PVars->push_back(NewParm);
|
2011-01-06 02:12:31 +03:00
|
|
|
}
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
|
|
|
|
// If we're supposed to retain a pack expansion, do so by temporarily
|
|
|
|
// forgetting the partially-substituted parameter pack.
|
|
|
|
if (RetainExpansion) {
|
|
|
|
ForgetPartiallySubstitutedPackRAII Forget(getDerived());
|
|
|
|
ParmVarDecl *NewParm
|
2011-01-15 01:40:04 +03:00
|
|
|
= getDerived().TransformFunctionTypeParam(OldParm,
|
|
|
|
OrigNumExpansions);
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
if (!NewParm)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
OutParamTypes.push_back(NewParm->getType());
|
|
|
|
if (PVars)
|
|
|
|
PVars->push_back(NewParm);
|
|
|
|
}
|
|
|
|
|
2011-01-06 02:12:31 +03:00
|
|
|
// We're done with the pack expansion.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll substitute the parameter now without expanding the pack
|
|
|
|
// expansion.
|
|
|
|
}
|
|
|
|
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
|
2011-01-15 01:40:04 +03:00
|
|
|
ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
|
|
|
|
NumExpansions);
|
2010-03-11 12:03:00 +03:00
|
|
|
if (!NewParm)
|
|
|
|
return true;
|
2011-01-06 02:12:31 +03:00
|
|
|
|
2011-01-07 03:20:55 +03:00
|
|
|
OutParamTypes.push_back(NewParm->getType());
|
|
|
|
if (PVars)
|
|
|
|
PVars->push_back(NewParm);
|
2011-01-06 02:12:31 +03:00
|
|
|
continue;
|
|
|
|
}
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
// Deal with the possibility that we don't have a parameter
|
|
|
|
// declaration for this parameter.
|
2011-01-07 03:20:55 +03:00
|
|
|
QualType OldType = ParamTypes[i];
|
2011-01-06 02:12:31 +03:00
|
|
|
bool IsPackExpansion = false;
|
2011-01-14 20:04:44 +03:00
|
|
|
llvm::Optional<unsigned> NumExpansions;
|
2011-01-06 02:12:31 +03:00
|
|
|
if (const PackExpansionType *Expansion
|
|
|
|
= dyn_cast<PackExpansionType>(OldType)) {
|
|
|
|
// We have a function parameter pack that may need to be expanded.
|
|
|
|
QualType Pattern = Expansion->getPattern();
|
|
|
|
llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
|
|
|
|
getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
|
|
|
|
|
|
|
|
// Determine whether we should expand the parameter packs.
|
|
|
|
bool ShouldExpand = false;
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
bool RetainExpansion = false;
|
2011-01-07 03:20:55 +03:00
|
|
|
if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
|
2011-01-06 02:12:31 +03:00
|
|
|
Unexpanded.data(),
|
|
|
|
Unexpanded.size(),
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
ShouldExpand,
|
|
|
|
RetainExpansion,
|
|
|
|
NumExpansions)) {
|
2010-03-11 12:03:00 +03:00
|
|
|
return true;
|
2011-01-06 02:12:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldExpand) {
|
|
|
|
// Expand the function parameter pack into multiple, separate
|
|
|
|
// parameters.
|
2011-01-14 20:04:44 +03:00
|
|
|
for (unsigned I = 0; I != *NumExpansions; ++I) {
|
2011-01-06 02:12:31 +03:00
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
|
|
|
|
QualType NewType = getDerived().TransformType(Pattern);
|
|
|
|
if (NewType.isNull())
|
|
|
|
return true;
|
|
|
|
|
2011-01-07 03:20:55 +03:00
|
|
|
OutParamTypes.push_back(NewType);
|
|
|
|
if (PVars)
|
|
|
|
PVars->push_back(0);
|
2011-01-06 02:12:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We're done with the pack expansion.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-10 23:53:55 +03:00
|
|
|
// If we're supposed to retain a pack expansion, do so by temporarily
|
|
|
|
// forgetting the partially-substituted parameter pack.
|
|
|
|
if (RetainExpansion) {
|
|
|
|
ForgetPartiallySubstitutedPackRAII Forget(getDerived());
|
|
|
|
QualType NewType = getDerived().TransformType(Pattern);
|
|
|
|
if (NewType.isNull())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
OutParamTypes.push_back(NewType);
|
|
|
|
if (PVars)
|
|
|
|
PVars->push_back(0);
|
|
|
|
}
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
|
2011-01-06 02:12:31 +03:00
|
|
|
// We'll substitute the parameter now without expanding the pack
|
|
|
|
// expansion.
|
|
|
|
OldType = Expansion->getPattern();
|
|
|
|
IsPackExpansion = true;
|
2009-10-21 04:40:46 +04:00
|
|
|
}
|
2011-01-06 02:12:31 +03:00
|
|
|
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
|
|
|
|
QualType NewType = getDerived().TransformType(OldType);
|
|
|
|
if (NewType.isNull())
|
|
|
|
return true;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-06 02:12:31 +03:00
|
|
|
if (IsPackExpansion)
|
2011-01-14 20:04:44 +03:00
|
|
|
NewType = getSema().Context.getPackExpansionType(NewType,
|
|
|
|
NumExpansions);
|
2011-01-06 02:12:31 +03:00
|
|
|
|
2011-01-07 03:20:55 +03:00
|
|
|
OutParamTypes.push_back(NewType);
|
|
|
|
if (PVars)
|
|
|
|
PVars->push_back(0);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-03-11 12:03:00 +03:00
|
|
|
return false;
|
2011-01-06 02:12:31 +03:00
|
|
|
}
|
2010-03-11 12:03:00 +03:00
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
FunctionProtoTypeLoc TL) {
|
When instantiating a function type, instantiate the return type before
instantiating the parameters. In a perfect world, this wouldn't
matter, and compilers are free to instantiate in any order they
want. However, every other compiler seems to instantiate the return
type first, and some code (in this case, Boost.Polygon) depends on
this and SFINAE to avoid instantiating something that shouldn't be
instantiated.
We could fight this battle, and insist that Clang is allowed to do
what it does, but it's not beneficial: it's more predictable to
instantiate this way, in source order. When we implement
late-specified return types, we'll need to instantiate the return type
last when it was late-specified, hence the FIXME.
We now compile Boost.Polygon properly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112561 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-31 04:26:14 +04:00
|
|
|
// Transform the parameters and return type.
|
|
|
|
//
|
|
|
|
// We instantiate in source order, with the return type first followed by
|
|
|
|
// the parameters, because users tend to expect this (even if they shouldn't
|
|
|
|
// rely on it!).
|
|
|
|
//
|
2010-10-01 22:44:50 +04:00
|
|
|
// When the function has a trailing return type, we instantiate the
|
|
|
|
// parameters before the return type, since the return type can then refer
|
|
|
|
// to the parameters themselves (via decltype, sizeof, etc.).
|
|
|
|
//
|
2010-03-11 12:03:00 +03:00
|
|
|
llvm::SmallVector<QualType, 4> ParamTypes;
|
|
|
|
llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
|
2011-01-19 09:33:43 +03:00
|
|
|
const FunctionProtoType *T = TL.getTypePtr();
|
When instantiating a function type, instantiate the return type before
instantiating the parameters. In a perfect world, this wouldn't
matter, and compilers are free to instantiate in any order they
want. However, every other compiler seems to instantiate the return
type first, and some code (in this case, Boost.Polygon) depends on
this and SFINAE to avoid instantiating something that shouldn't be
instantiated.
We could fight this battle, and insist that Clang is allowed to do
what it does, but it's not beneficial: it's more predictable to
instantiate this way, in source order. When we implement
late-specified return types, we'll need to instantiate the return type
last when it was late-specified, hence the FIXME.
We now compile Boost.Polygon properly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112561 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-31 04:26:14 +04:00
|
|
|
|
2010-10-01 22:44:50 +04:00
|
|
|
QualType ResultType;
|
|
|
|
|
|
|
|
if (TL.getTrailingReturn()) {
|
2011-01-07 03:20:55 +03:00
|
|
|
if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
|
|
|
|
TL.getParmArray(),
|
|
|
|
TL.getNumArgs(),
|
|
|
|
TL.getTypePtr()->arg_type_begin(),
|
|
|
|
ParamTypes, &ParamDecls))
|
2010-10-01 22:44:50 +04:00
|
|
|
return QualType();
|
|
|
|
|
|
|
|
ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
|
|
|
|
if (ResultType.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
|
|
|
|
if (ResultType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
2011-01-07 03:20:55 +03:00
|
|
|
if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
|
|
|
|
TL.getParmArray(),
|
|
|
|
TL.getNumArgs(),
|
|
|
|
TL.getTypePtr()->arg_type_begin(),
|
|
|
|
ParamTypes, &ParamDecls))
|
2010-10-01 22:44:50 +04:00
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
ResultType != T->getResultType() ||
|
2011-01-07 22:27:47 +03:00
|
|
|
T->getNumArgs() != ParamTypes.size() ||
|
2009-10-21 04:40:46 +04:00
|
|
|
!std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
|
|
|
|
Result = getDerived().RebuildFunctionProtoType(ResultType,
|
|
|
|
ParamTypes.data(),
|
|
|
|
ParamTypes.size(),
|
|
|
|
T->isVariadic(),
|
2010-08-05 06:54:05 +04:00
|
|
|
T->getTypeQuals(),
|
|
|
|
T->getExtInfo());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
|
|
|
|
NewTL.setLParenLoc(TL.getLParenLoc());
|
|
|
|
NewTL.setRParenLoc(TL.getRParenLoc());
|
2010-10-01 22:44:50 +04:00
|
|
|
NewTL.setTrailingReturn(TL.getTrailingReturn());
|
2009-10-21 04:40:46 +04:00
|
|
|
for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
|
|
|
|
NewTL.setArg(i, ParamDecls[i]);
|
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
FunctionNoProtoTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const FunctionNoProtoType *T = TL.getTypePtr();
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
|
|
|
|
if (ResultType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
ResultType != T->getResultType())
|
|
|
|
Result = getDerived().RebuildFunctionNoProtoType(ResultType);
|
|
|
|
|
|
|
|
FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
|
|
|
|
NewTL.setLParenLoc(TL.getLParenLoc());
|
|
|
|
NewTL.setRParenLoc(TL.getRParenLoc());
|
2010-10-01 22:44:50 +04:00
|
|
|
NewTL.setTrailingReturn(false);
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-12-05 01:46:56 +03:00
|
|
|
template<typename Derived> QualType
|
|
|
|
TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
UnresolvedUsingTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const UnresolvedUsingType *T = TL.getTypePtr();
|
2010-03-01 18:56:25 +03:00
|
|
|
Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
|
2009-12-05 01:46:56 +03:00
|
|
|
if (!D)
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
|
|
|
|
Result = getDerived().RebuildUnresolvedUsingType(D);
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We might get an arbitrary type spec type back. We should at
|
|
|
|
// least always get a type spec type, though.
|
|
|
|
TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
TypedefTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const TypedefType *T = TL.getTypePtr();
|
2009-08-04 20:50:30 +04:00
|
|
|
TypedefDecl *Typedef
|
2010-03-01 18:56:25 +03:00
|
|
|
= cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
|
|
|
|
T->getDecl()));
|
2009-08-04 20:50:30 +04:00
|
|
|
if (!Typedef)
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
Typedef != T->getDecl()) {
|
|
|
|
Result = getDerived().RebuildTypedefType(Typedef);
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
TypeOfExprTypeLoc TL) {
|
2009-08-05 02:27:00 +04:00
|
|
|
// typeof expressions are not potentially evaluated contexts
|
2010-08-27 03:41:50 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (E.isInvalid())
|
|
|
|
return QualType();
|
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
2010-01-13 23:03:27 +03:00
|
|
|
E.get() != TL.getUnderlyingExpr()) {
|
2010-10-12 04:20:44 +04:00
|
|
|
Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-10-21 04:40:46 +04:00
|
|
|
else E.take();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
|
2010-01-13 23:03:27 +03:00
|
|
|
NewTL.setTypeofLoc(TL.getTypeofLoc());
|
|
|
|
NewTL.setLParenLoc(TL.getLParenLoc());
|
|
|
|
NewTL.setRParenLoc(TL.getRParenLoc());
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
TypeOfTypeLoc TL) {
|
2010-01-13 23:03:27 +03:00
|
|
|
TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
|
|
|
|
TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
|
|
|
|
if (!New_Under_TI)
|
2009-08-04 20:50:30 +04:00
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
2010-01-13 23:03:27 +03:00
|
|
|
if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
|
|
|
|
Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
|
2010-01-13 23:03:27 +03:00
|
|
|
NewTL.setTypeofLoc(TL.getTypeofLoc());
|
|
|
|
NewTL.setLParenLoc(TL.getLParenLoc());
|
|
|
|
NewTL.setRParenLoc(TL.getRParenLoc());
|
|
|
|
NewTL.setUnderlyingTInfo(New_Under_TI);
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
DecltypeTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const DecltypeType *T = TL.getTypePtr();
|
2009-10-21 04:40:46 +04:00
|
|
|
|
2009-08-05 02:27:00 +04:00
|
|
|
// decltype expressions are not potentially evaluated contexts
|
2010-08-27 03:41:50 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (E.isInvalid())
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
E.get() != T->getUnderlyingExpr()) {
|
2010-10-12 04:20:44 +04:00
|
|
|
Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-10-21 04:40:46 +04:00
|
|
|
else E.take();
|
|
|
|
|
|
|
|
DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
RecordTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const RecordType *T = TL.getTypePtr();
|
2009-08-04 20:50:30 +04:00
|
|
|
RecordDecl *Record
|
2010-03-01 18:56:25 +03:00
|
|
|
= cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
|
|
|
|
T->getDecl()));
|
2009-08-04 20:50:30 +04:00
|
|
|
if (!Record)
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
Record != T->getDecl()) {
|
|
|
|
Result = getDerived().RebuildRecordType(Record);
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
EnumTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const EnumType *T = TL.getTypePtr();
|
2009-08-04 20:50:30 +04:00
|
|
|
EnumDecl *Enum
|
2010-03-01 18:56:25 +03:00
|
|
|
= cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
|
|
|
|
T->getDecl()));
|
2009-08-04 20:50:30 +04:00
|
|
|
if (!Enum)
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
Enum != T->getDecl()) {
|
|
|
|
Result = getDerived().RebuildEnumType(Enum);
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-05 04:15:47 +04:00
|
|
|
|
2010-03-10 06:28:59 +03:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformInjectedClassNameType(
|
|
|
|
TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
InjectedClassNameTypeLoc TL) {
|
2010-03-10 06:28:59 +03:00
|
|
|
Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
|
|
|
|
TL.getTypePtr()->getDecl());
|
|
|
|
if (!D) return QualType();
|
|
|
|
|
|
|
|
QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
|
|
|
|
TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
TemplateTypeParmTypeLoc TL) {
|
2009-10-21 04:40:46 +04:00
|
|
|
return TransformTypeSpecType(TLB, TL);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
2009-10-18 13:09:24 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
|
2009-10-21 04:40:46 +04:00
|
|
|
TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
SubstTemplateTypeParmTypeLoc TL) {
|
2009-10-21 04:40:46 +04:00
|
|
|
return TransformTypeSpecType(TLB, TL);
|
2009-10-18 13:09:24 +04:00
|
|
|
}
|
|
|
|
|
2011-01-14 05:55:32 +03:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
|
|
|
|
TypeLocBuilder &TLB,
|
|
|
|
SubstTemplateTypeParmPackTypeLoc TL) {
|
|
|
|
return TransformTypeSpecType(TLB, TL);
|
|
|
|
}
|
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
|
2010-11-12 11:19:04 +03:00
|
|
|
TypeLocBuilder &TLB,
|
|
|
|
TemplateSpecializationTypeLoc TL) {
|
|
|
|
const TemplateSpecializationType *T = TL.getTypePtr();
|
2009-10-29 21:45:58 +03:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
TemplateName Template
|
|
|
|
= getDerived().TransformTemplateName(T->getTemplateName());
|
|
|
|
if (Template.isNull())
|
|
|
|
return QualType();
|
2009-10-29 11:12:44 +03:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
|
2009-10-20 02:04:39 +04:00
|
|
|
}
|
2010-11-12 11:19:04 +03:00
|
|
|
|
2010-12-21 02:36:19 +03:00
|
|
|
namespace {
|
|
|
|
/// \brief Simple iterator that traverses the template arguments in a
|
|
|
|
/// container that provides a \c getArgLoc() member function.
|
|
|
|
///
|
|
|
|
/// This iterator is intended to be used with the iterator form of
|
|
|
|
/// \c TreeTransform<Derived>::TransformTemplateArguments().
|
|
|
|
template<typename ArgLocContainer>
|
|
|
|
class TemplateArgumentLocContainerIterator {
|
|
|
|
ArgLocContainer *Container;
|
|
|
|
unsigned Index;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef TemplateArgumentLoc value_type;
|
|
|
|
typedef TemplateArgumentLoc reference;
|
|
|
|
typedef int difference_type;
|
|
|
|
typedef std::input_iterator_tag iterator_category;
|
|
|
|
|
|
|
|
class pointer {
|
|
|
|
TemplateArgumentLoc Arg;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
|
|
|
|
|
|
|
|
const TemplateArgumentLoc *operator->() const {
|
|
|
|
return &Arg;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TemplateArgumentLocContainerIterator() {}
|
|
|
|
|
|
|
|
TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
|
|
|
|
unsigned Index)
|
|
|
|
: Container(&Container), Index(Index) { }
|
|
|
|
|
|
|
|
TemplateArgumentLocContainerIterator &operator++() {
|
|
|
|
++Index;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemplateArgumentLocContainerIterator operator++(int) {
|
|
|
|
TemplateArgumentLocContainerIterator Old(*this);
|
|
|
|
++(*this);
|
|
|
|
return Old;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemplateArgumentLoc operator*() const {
|
|
|
|
return Container->getArgLoc(Index);
|
|
|
|
}
|
|
|
|
|
|
|
|
pointer operator->() const {
|
|
|
|
return pointer(Container->getArgLoc(Index));
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator==(const TemplateArgumentLocContainerIterator &X,
|
2010-12-22 00:51:48 +03:00
|
|
|
const TemplateArgumentLocContainerIterator &Y) {
|
2010-12-21 02:36:19 +03:00
|
|
|
return X.Container == Y.Container && X.Index == Y.Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
|
2010-12-22 00:51:48 +03:00
|
|
|
const TemplateArgumentLocContainerIterator &Y) {
|
2010-12-21 02:36:19 +03:00
|
|
|
return !(X == Y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
template <typename Derived>
|
2009-08-04 20:50:30 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
|
2009-10-29 11:12:44 +03:00
|
|
|
TypeLocBuilder &TLB,
|
|
|
|
TemplateSpecializationTypeLoc TL,
|
2010-11-12 11:19:04 +03:00
|
|
|
TemplateName Template) {
|
2009-11-23 04:53:49 +03:00
|
|
|
TemplateArgumentListInfo NewTemplateArgs;
|
|
|
|
NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
|
|
|
|
NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
|
2010-12-21 02:36:19 +03:00
|
|
|
typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
|
|
|
|
ArgIterator;
|
|
|
|
if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
|
|
|
|
ArgIterator(TL, TL.getNumArgs()),
|
|
|
|
NewTemplateArgs))
|
2010-12-20 20:42:22 +03:00
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
// FIXME: maybe don't rebuild if all the template arguments are the same.
|
|
|
|
|
|
|
|
QualType Result =
|
|
|
|
getDerived().RebuildTemplateSpecializationType(Template,
|
|
|
|
TL.getTemplateNameLoc(),
|
2009-11-23 04:53:49 +03:00
|
|
|
NewTemplateArgs);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
if (!Result.isNull()) {
|
|
|
|
TemplateSpecializationTypeLoc NewTL
|
|
|
|
= TLB.push<TemplateSpecializationTypeLoc>(Result);
|
|
|
|
NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
|
|
|
|
NewTL.setLAngleLoc(TL.getLAngleLoc());
|
|
|
|
NewTL.setRAngleLoc(TL.getRAngleLoc());
|
|
|
|
for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
|
|
|
|
NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-29 11:12:44 +03:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType
|
2010-05-12 01:36:43 +04:00
|
|
|
TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
ElaboratedTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const ElaboratedType *T = TL.getTypePtr();
|
2010-05-12 01:36:43 +04:00
|
|
|
|
|
|
|
NestedNameSpecifier *NNS = 0;
|
|
|
|
// NOTE: the qualifier in an ElaboratedType is optional.
|
|
|
|
if (T->getQualifier() != 0) {
|
|
|
|
NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
|
2010-11-12 11:19:04 +03:00
|
|
|
TL.getQualifierRange());
|
2010-05-12 01:36:43 +04:00
|
|
|
if (!NNS)
|
|
|
|
return QualType();
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
|
|
|
|
if (NamedT.isNull())
|
|
|
|
return QualType();
|
2010-05-14 20:34:09 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
NNS != T->getQualifier() ||
|
2010-05-20 01:37:53 +04:00
|
|
|
NamedT != T->getNamedType()) {
|
2010-11-04 22:04:38 +03:00
|
|
|
Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
|
|
|
|
T->getKeyword(), NNS, NamedT);
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
2009-08-04 20:50:30 +04:00
|
|
|
|
2010-05-12 01:36:43 +04:00
|
|
|
ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
|
2010-05-20 01:37:53 +04:00
|
|
|
NewTL.setKeywordLoc(TL.getKeywordLoc());
|
|
|
|
NewTL.setQualifierRange(TL.getQualifierRange());
|
2009-10-21 04:40:46 +04:00
|
|
|
|
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-06 04:58:22 +03:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformAttributedType(
|
|
|
|
TypeLocBuilder &TLB,
|
|
|
|
AttributedTypeLoc TL) {
|
|
|
|
const AttributedType *oldType = TL.getTypePtr();
|
|
|
|
QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
|
|
|
|
if (modifiedType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType result = TL.getType();
|
|
|
|
|
|
|
|
// FIXME: dependent operand expressions?
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
modifiedType != oldType->getModifiedType()) {
|
|
|
|
// TODO: this is really lame; we should really be rebuilding the
|
|
|
|
// equivalent type from first principles.
|
|
|
|
QualType equivalentType
|
|
|
|
= getDerived().TransformType(oldType->getEquivalentType());
|
|
|
|
if (equivalentType.isNull())
|
|
|
|
return QualType();
|
|
|
|
result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
|
|
|
|
modifiedType,
|
|
|
|
equivalentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
|
|
|
|
newTL.setAttrNameLoc(TL.getAttrNameLoc());
|
|
|
|
if (TL.hasAttrOperand())
|
|
|
|
newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
|
|
|
|
if (TL.hasAttrExprOperand())
|
|
|
|
newTL.setAttrExprOperand(TL.getAttrExprOperand());
|
|
|
|
else if (TL.hasAttrEnumOperand())
|
|
|
|
newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-12-10 19:29:40 +03:00
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
|
|
|
|
ParenTypeLoc TL) {
|
|
|
|
QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
|
|
|
|
if (Inner.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
Inner != TL.getInnerLoc().getType()) {
|
|
|
|
Result = getDerived().RebuildParenType(Inner);
|
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
|
|
|
|
NewTL.setLParenLoc(TL.getLParenLoc());
|
|
|
|
NewTL.setRParenLoc(TL.getRParenLoc());
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-03-31 21:34:00 +04:00
|
|
|
QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
DependentNameTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const DependentNameType *T = TL.getTypePtr();
|
2009-10-29 11:12:44 +03:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
NestedNameSpecifier *NNS
|
2010-05-20 01:37:53 +04:00
|
|
|
= getDerived().TransformNestedNameSpecifier(T->getQualifier(),
|
2010-11-12 11:19:04 +03:00
|
|
|
TL.getQualifierRange());
|
2009-08-04 20:50:30 +04:00
|
|
|
if (!NNS)
|
|
|
|
return QualType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-06-11 04:33:02 +04:00
|
|
|
QualType Result
|
|
|
|
= getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
|
|
|
|
T->getIdentifier(),
|
|
|
|
TL.getKeywordLoc(),
|
|
|
|
TL.getQualifierRange(),
|
|
|
|
TL.getNameLoc());
|
2009-10-21 04:40:46 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
2010-05-20 01:37:53 +04:00
|
|
|
if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
|
|
|
|
QualType NamedT = ElabT->getNamedType();
|
2010-06-11 04:33:02 +04:00
|
|
|
TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
|
|
|
|
|
2010-05-20 01:37:53 +04:00
|
|
|
ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
|
|
|
|
NewTL.setKeywordLoc(TL.getKeywordLoc());
|
|
|
|
NewTL.setQualifierRange(TL.getQualifierRange());
|
2010-06-11 04:33:02 +04:00
|
|
|
} else {
|
2010-05-20 01:37:53 +04:00
|
|
|
DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
|
|
|
|
NewTL.setKeywordLoc(TL.getKeywordLoc());
|
|
|
|
NewTL.setQualifierRange(TL.getQualifierRange());
|
|
|
|
NewTL.setNameLoc(TL.getNameLoc());
|
|
|
|
}
|
2009-10-21 04:40:46 +04:00
|
|
|
return Result;
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-06-11 04:33:02 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::
|
|
|
|
TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
DependentTemplateSpecializationTypeLoc TL) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const DependentTemplateSpecializationType *T = TL.getTypePtr();
|
2010-06-11 04:33:02 +04:00
|
|
|
|
|
|
|
NestedNameSpecifier *NNS
|
|
|
|
= getDerived().TransformNestedNameSpecifier(T->getQualifier(),
|
2010-11-12 11:19:04 +03:00
|
|
|
TL.getQualifierRange());
|
2010-06-11 04:33:02 +04:00
|
|
|
if (!NNS)
|
|
|
|
return QualType();
|
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
return getDerived()
|
|
|
|
.TransformDependentTemplateSpecializationType(TLB, TL, NNS);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::
|
|
|
|
TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
|
|
|
|
DependentTemplateSpecializationTypeLoc TL,
|
|
|
|
NestedNameSpecifier *NNS) {
|
2011-01-19 09:33:43 +03:00
|
|
|
const DependentTemplateSpecializationType *T = TL.getTypePtr();
|
2010-11-12 11:19:04 +03:00
|
|
|
|
2010-06-11 04:33:02 +04:00
|
|
|
TemplateArgumentListInfo NewTemplateArgs;
|
|
|
|
NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
|
|
|
|
NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
|
2010-12-21 02:36:19 +03:00
|
|
|
|
|
|
|
typedef TemplateArgumentLocContainerIterator<
|
|
|
|
DependentTemplateSpecializationTypeLoc> ArgIterator;
|
|
|
|
if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
|
|
|
|
ArgIterator(TL, TL.getNumArgs()),
|
|
|
|
NewTemplateArgs))
|
2010-12-20 20:42:22 +03:00
|
|
|
return QualType();
|
2010-06-11 04:33:02 +04:00
|
|
|
|
2010-09-09 03:56:00 +04:00
|
|
|
QualType Result
|
|
|
|
= getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
|
|
|
|
NNS,
|
|
|
|
TL.getQualifierRange(),
|
|
|
|
T->getIdentifier(),
|
|
|
|
TL.getNameLoc(),
|
|
|
|
NewTemplateArgs);
|
2010-06-11 04:33:02 +04:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
|
|
|
|
QualType NamedT = ElabT->getNamedType();
|
|
|
|
|
|
|
|
// Copy information relevant to the template specialization.
|
|
|
|
TemplateSpecializationTypeLoc NamedTL
|
|
|
|
= TLB.push<TemplateSpecializationTypeLoc>(NamedT);
|
|
|
|
NamedTL.setLAngleLoc(TL.getLAngleLoc());
|
|
|
|
NamedTL.setRAngleLoc(TL.getRAngleLoc());
|
|
|
|
for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
|
|
|
|
NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
|
|
|
|
|
|
|
|
// Copy information relevant to the elaborated type.
|
|
|
|
ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
|
|
|
|
NewTL.setKeywordLoc(TL.getKeywordLoc());
|
|
|
|
NewTL.setQualifierRange(TL.getQualifierRange());
|
|
|
|
} else {
|
2010-06-17 20:03:49 +04:00
|
|
|
TypeLoc NewTL(Result, TL.getOpaqueData());
|
|
|
|
TLB.pushFullCopy(NewTL);
|
2010-06-11 04:33:02 +04:00
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-12-20 05:24:11 +03:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
|
|
|
|
PackExpansionTypeLoc TL) {
|
2011-01-12 20:07:58 +03:00
|
|
|
QualType Pattern
|
|
|
|
= getDerived().TransformType(TLB, TL.getPatternLoc());
|
|
|
|
if (Pattern.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType Result = TL.getType();
|
|
|
|
if (getDerived().AlwaysRebuild() ||
|
|
|
|
Pattern != TL.getPatternLoc().getType()) {
|
|
|
|
Result = getDerived().RebuildPackExpansionType(Pattern,
|
|
|
|
TL.getPatternLoc().getSourceRange(),
|
2011-01-14 20:04:44 +03:00
|
|
|
TL.getEllipsisLoc(),
|
|
|
|
TL.getTypePtr()->getNumExpansions());
|
2011-01-12 20:07:58 +03:00
|
|
|
if (Result.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
|
|
|
|
NewT.setEllipsisLoc(TL.getEllipsisLoc());
|
|
|
|
return Result;
|
2010-12-20 05:24:11 +03:00
|
|
|
}
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
ObjCInterfaceTypeLoc TL) {
|
2010-04-22 21:28:13 +04:00
|
|
|
// ObjCInterfaceType is never dependent.
|
2010-05-15 15:32:37 +04:00
|
|
|
TLB.pushFullCopy(TL);
|
|
|
|
return TL.getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
ObjCObjectTypeLoc TL) {
|
2010-05-15 15:32:37 +04:00
|
|
|
// ObjCObjectType is never dependent.
|
|
|
|
TLB.pushFullCopy(TL);
|
2010-04-22 21:28:13 +04:00
|
|
|
return TL.getType();
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2009-10-21 04:40:46 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
|
2010-11-12 11:19:04 +03:00
|
|
|
ObjCObjectPointerTypeLoc TL) {
|
2010-04-22 21:28:13 +04:00
|
|
|
// ObjCObjectPointerType is never dependent.
|
2010-05-15 15:32:37 +04:00
|
|
|
TLB.pushFullCopy(TL);
|
2010-04-22 21:28:13 +04:00
|
|
|
return TL.getType();
|
2009-09-29 23:42:55 +04:00
|
|
|
}
|
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Statement transformation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-08-20 11:17:43 +04:00
|
|
|
TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
|
|
|
|
return getDerived().TransformCompoundStmt(S, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
|
2009-08-20 11:17:43 +04:00
|
|
|
bool IsStmtExpr) {
|
2010-08-27 23:56:05 +04:00
|
|
|
bool SubStmtInvalid = false;
|
2009-08-20 11:17:43 +04:00
|
|
|
bool SubStmtChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Stmt*> Statements(getSema());
|
2009-08-20 11:17:43 +04:00
|
|
|
for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
|
|
|
|
B != BEnd; ++B) {
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Result = getDerived().TransformStmt(*B);
|
2010-08-27 23:56:05 +04:00
|
|
|
if (Result.isInvalid()) {
|
|
|
|
// Immediately fail if this was a DeclStmt, since it's very
|
|
|
|
// likely that this will cause problems for future statements.
|
|
|
|
if (isa<DeclStmt>(*B))
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
// Otherwise, just keep processing substatements and fail later.
|
|
|
|
SubStmtInvalid = true;
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
SubStmtChanged = SubStmtChanged || Result.get() != *B;
|
|
|
|
Statements.push_back(Result.takeAs<Stmt>());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-27 23:56:05 +04:00
|
|
|
if (SubStmtInvalid)
|
|
|
|
return StmtError();
|
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
!SubStmtChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
|
|
|
|
move_arg(Statements),
|
|
|
|
S->getRBracLoc(),
|
|
|
|
IsStmtExpr);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult LHS, RHS;
|
2009-11-19 06:14:00 +03:00
|
|
|
{
|
|
|
|
// The case value expressions are not potentially evaluated.
|
2010-08-27 03:41:50 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-19 06:14:00 +03:00
|
|
|
// Transform the left-hand case value.
|
|
|
|
LHS = getDerived().TransformExpr(S->getLHS());
|
|
|
|
if (LHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-19 06:14:00 +03:00
|
|
|
// Transform the right-hand case value (for the GNU case-range extension).
|
|
|
|
RHS = getDerived().TransformExpr(S->getRHS());
|
|
|
|
if (RHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-11-19 06:14:00 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Build the case statement.
|
|
|
|
// Case statements are always rebuilt so that they will attached to their
|
|
|
|
// transformed switch statement.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
LHS.get(),
|
2009-08-20 11:17:43 +04:00
|
|
|
S->getEllipsisLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
RHS.get(),
|
2009-08-20 11:17:43 +04:00
|
|
|
S->getColonLoc());
|
|
|
|
if (Case.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the statement following the case
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (SubStmt.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Attach the body to the case statement
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the statement following the default case
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (SubStmt.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Default statements are always rebuilt
|
|
|
|
return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
SubStmt.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (SubStmt.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// FIXME: Pass the real colon location in.
|
|
|
|
SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
|
|
|
|
return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
|
2010-09-28 18:54:07 +04:00
|
|
|
SubStmt.get(), S->HasUnusedAttribute());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the condition
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Cond;
|
2009-11-24 02:44:04 +03:00
|
|
|
VarDecl *ConditionVar = 0;
|
|
|
|
if (S->getConditionVariable()) {
|
2010-05-05 19:23:54 +04:00
|
|
|
ConditionVar
|
2009-11-24 02:44:04 +03:00
|
|
|
= cast_or_null<VarDecl>(
|
2010-03-01 20:25:41 +03:00
|
|
|
getDerived().TransformDefinition(
|
|
|
|
S->getConditionVariable()->getLocation(),
|
|
|
|
S->getConditionVariable()));
|
2009-11-24 02:44:04 +03:00
|
|
|
if (!ConditionVar)
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-11-25 03:27:52 +03:00
|
|
|
} else {
|
2009-11-24 02:44:04 +03:00
|
|
|
Cond = getDerived().TransformExpr(S->getCond());
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-11-25 03:27:52 +03:00
|
|
|
if (Cond.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 02:20:28 +04:00
|
|
|
|
|
|
|
// Convert the condition to a boolean value.
|
2010-05-09 03:34:38 +04:00
|
|
|
if (S->getCond()) {
|
2010-12-21 01:05:00 +03:00
|
|
|
ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
|
|
|
|
Cond.get());
|
2010-05-09 03:34:38 +04:00
|
|
|
if (CondE.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 02:20:28 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Cond = CondE.get();
|
2010-05-09 03:34:38 +04:00
|
|
|
}
|
2009-11-25 03:27:52 +03:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
|
|
|
|
if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 02:20:28 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the "then" branch.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Then = getDerived().TransformStmt(S->getThen());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Then.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the "else" branch.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Else = getDerived().TransformStmt(S->getElse());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Else.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-08-24 03:25:46 +04:00
|
|
|
FullCond.get() == S->getCond() &&
|
2009-11-25 03:27:52 +03:00
|
|
|
ConditionVar == S->getConditionVariable() &&
|
2009-08-20 11:17:43 +04:00
|
|
|
Then.get() == S->getThen() &&
|
|
|
|
Else.get() == S->getElse())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-05-09 02:20:28 +04:00
|
|
|
return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
|
2010-11-20 05:04:01 +03:00
|
|
|
Then.get(),
|
2010-08-24 03:25:46 +04:00
|
|
|
S->getElseLoc(), Else.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the condition.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Cond;
|
2009-11-24 20:07:59 +03:00
|
|
|
VarDecl *ConditionVar = 0;
|
|
|
|
if (S->getConditionVariable()) {
|
2010-05-05 19:23:54 +04:00
|
|
|
ConditionVar
|
2009-11-24 20:07:59 +03:00
|
|
|
= cast_or_null<VarDecl>(
|
2010-03-01 20:25:41 +03:00
|
|
|
getDerived().TransformDefinition(
|
|
|
|
S->getConditionVariable()->getLocation(),
|
|
|
|
S->getConditionVariable()));
|
2009-11-24 20:07:59 +03:00
|
|
|
if (!ConditionVar)
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-11-25 03:27:52 +03:00
|
|
|
} else {
|
2009-11-24 20:07:59 +03:00
|
|
|
Cond = getDerived().TransformExpr(S->getCond());
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-11-25 03:27:52 +03:00
|
|
|
if (Cond.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-11-25 03:27:52 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Rebuild the switch statement.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Switch
|
2010-08-24 03:25:46 +04:00
|
|
|
= getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
|
2010-05-06 21:25:47 +04:00
|
|
|
ConditionVar);
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Switch.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the body of the switch statement.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Body = getDerived().TransformStmt(S->getBody());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Body.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Complete the switch statement.
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
|
|
|
|
Body.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the condition
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Cond;
|
2009-11-25 00:15:44 +03:00
|
|
|
VarDecl *ConditionVar = 0;
|
|
|
|
if (S->getConditionVariable()) {
|
2010-05-05 19:23:54 +04:00
|
|
|
ConditionVar
|
2009-11-25 00:15:44 +03:00
|
|
|
= cast_or_null<VarDecl>(
|
2010-03-01 20:25:41 +03:00
|
|
|
getDerived().TransformDefinition(
|
|
|
|
S->getConditionVariable()->getLocation(),
|
|
|
|
S->getConditionVariable()));
|
2009-11-25 00:15:44 +03:00
|
|
|
if (!ConditionVar)
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-11-25 03:27:52 +03:00
|
|
|
} else {
|
2009-11-25 00:15:44 +03:00
|
|
|
Cond = getDerived().TransformExpr(S->getCond());
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-11-25 03:27:52 +03:00
|
|
|
if (Cond.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 03:34:38 +04:00
|
|
|
|
|
|
|
if (S->getCond()) {
|
|
|
|
// Convert the condition to a boolean value.
|
2010-12-21 01:05:00 +03:00
|
|
|
ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
|
|
|
|
Cond.get());
|
2010-05-09 03:34:38 +04:00
|
|
|
if (CondE.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-08-24 03:25:46 +04:00
|
|
|
Cond = CondE;
|
2010-05-09 03:34:38 +04:00
|
|
|
}
|
2009-11-25 03:27:52 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
|
|
|
|
if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 02:20:28 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the body
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Body = getDerived().TransformStmt(S->getBody());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Body.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-08-24 03:25:46 +04:00
|
|
|
FullCond.get() == S->getCond() &&
|
2009-11-25 03:27:52 +03:00
|
|
|
ConditionVar == S->getConditionVariable() &&
|
2009-08-20 11:17:43 +04:00
|
|
|
Body.get() == S->getBody())
|
2010-08-24 03:25:46 +04:00
|
|
|
return Owned(S);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-05-09 02:20:28 +04:00
|
|
|
return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
|
2010-08-24 03:25:46 +04:00
|
|
|
ConditionVar, Body.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-08-20 11:17:43 +04:00
|
|
|
TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
|
|
|
|
// Transform the body
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Body = getDerived().TransformStmt(S->getBody());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Body.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-05-09 02:20:28 +04:00
|
|
|
// Transform the condition
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Cond = getDerived().TransformExpr(S->getCond());
|
2010-05-09 02:20:28 +04:00
|
|
|
if (Cond.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 02:20:28 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Cond.get() == S->getCond() &&
|
|
|
|
Body.get() == S->getBody())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
|
|
|
|
/*FIXME:*/S->getWhileLoc(), Cond.get(),
|
2009-08-20 11:17:43 +04:00
|
|
|
S->getRParenLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the initialization statement
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Init = getDerived().TransformStmt(S->getInit());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Init.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the condition
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Cond;
|
2009-11-25 03:27:52 +03:00
|
|
|
VarDecl *ConditionVar = 0;
|
|
|
|
if (S->getConditionVariable()) {
|
2010-05-05 19:23:54 +04:00
|
|
|
ConditionVar
|
2009-11-25 03:27:52 +03:00
|
|
|
= cast_or_null<VarDecl>(
|
2010-03-01 20:25:41 +03:00
|
|
|
getDerived().TransformDefinition(
|
|
|
|
S->getConditionVariable()->getLocation(),
|
|
|
|
S->getConditionVariable()));
|
2009-11-25 03:27:52 +03:00
|
|
|
if (!ConditionVar)
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-11-25 03:27:52 +03:00
|
|
|
} else {
|
|
|
|
Cond = getDerived().TransformExpr(S->getCond());
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-11-25 03:27:52 +03:00
|
|
|
if (Cond.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 03:34:38 +04:00
|
|
|
|
|
|
|
if (S->getCond()) {
|
|
|
|
// Convert the condition to a boolean value.
|
2010-12-21 01:05:00 +03:00
|
|
|
ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
|
|
|
|
Cond.get());
|
2010-05-09 03:34:38 +04:00
|
|
|
if (CondE.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 03:34:38 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Cond = CondE.get();
|
2010-05-09 03:34:38 +04:00
|
|
|
}
|
2009-11-25 03:27:52 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
|
|
|
|
if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 02:20:28 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the increment
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Inc = getDerived().TransformExpr(S->getInc());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Inc.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
|
|
|
|
if (S->getInc() && !FullInc.get())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-09 02:20:28 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the body
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Body = getDerived().TransformStmt(S->getBody());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Body.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Init.get() == S->getInit() &&
|
2010-08-24 03:25:46 +04:00
|
|
|
FullCond.get() == S->getCond() &&
|
2009-08-20 11:17:43 +04:00
|
|
|
Inc.get() == S->getInc() &&
|
|
|
|
Body.get() == S->getBody())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Init.get(), FullCond, ConditionVar,
|
|
|
|
FullInc, S->getRParenLoc(), Body.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
// Goto statements must always be rebuilt, to resolve the label.
|
2009-09-09 19:08:12 +04:00
|
|
|
return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
|
2009-08-20 11:17:43 +04:00
|
|
|
S->getLabel());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Target = getDerived().TransformExpr(S->getTarget());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Target.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Target.get() == S->getTarget())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Target.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result = getDerived().TransformExpr(S->getRetValue());
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-08-20 11:17:43 +04:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
// FIXME: We always rebuild the return statement because there is no way
|
2009-08-20 11:17:43 +04:00
|
|
|
// to tell whether the return type of the function has changed.
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
bool DeclChanged = false;
|
|
|
|
llvm::SmallVector<Decl *, 4> Decls;
|
|
|
|
for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
|
|
|
|
D != DEnd; ++D) {
|
2010-03-01 20:25:41 +03:00
|
|
|
Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
|
|
|
|
*D);
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!Transformed)
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (Transformed != *D)
|
|
|
|
DeclChanged = true;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
Decls.push_back(Transformed);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() && !DeclChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
|
2009-08-20 11:17:43 +04:00
|
|
|
S->getStartLoc(), S->getEndLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
|
2009-08-20 11:17:43 +04:00
|
|
|
assert(false && "SwitchCase is abstract and cannot be transformed");
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-08-20 11:17:43 +04:00
|
|
|
TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> Constraints(getSema());
|
|
|
|
ASTOwningVector<Expr*> Exprs(getSema());
|
2010-01-31 01:25:16 +03:00
|
|
|
llvm::SmallVector<IdentifierInfo *, 4> Names;
|
2010-01-30 23:05:21 +03:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult AsmString;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> Clobbers(getSema());
|
2010-01-24 08:50:09 +03:00
|
|
|
|
|
|
|
bool ExprsChanged = false;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
// Go through the outputs.
|
|
|
|
for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
|
2010-01-31 01:25:16 +03:00
|
|
|
Names.push_back(S->getOutputIdentifier(I));
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
// No need to transform the constraint literal.
|
2010-10-26 11:05:15 +04:00
|
|
|
Constraints.push_back(S->getOutputConstraintLiteral(I));
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
// Transform the output expr.
|
|
|
|
Expr *OutputExpr = S->getOutputExpr(I);
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result = getDerived().TransformExpr(OutputExpr);
|
2010-01-24 08:50:09 +03:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
ExprsChanged |= Result.get() != OutputExpr;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Exprs.push_back(Result.get());
|
2010-01-24 08:50:09 +03:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
// Go through the inputs.
|
|
|
|
for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
|
2010-01-31 01:25:16 +03:00
|
|
|
Names.push_back(S->getInputIdentifier(I));
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
// No need to transform the constraint literal.
|
2010-10-26 11:05:15 +04:00
|
|
|
Constraints.push_back(S->getInputConstraintLiteral(I));
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
// Transform the input expr.
|
|
|
|
Expr *InputExpr = S->getInputExpr(I);
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result = getDerived().TransformExpr(InputExpr);
|
2010-01-24 08:50:09 +03:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
ExprsChanged |= Result.get() != InputExpr;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
Exprs.push_back(Result.get());
|
2010-01-24 08:50:09 +03:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-01-24 08:50:09 +03:00
|
|
|
if (!getDerived().AlwaysRebuild() && !ExprsChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2010-01-24 08:50:09 +03:00
|
|
|
|
|
|
|
// Go through the clobbers.
|
|
|
|
for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
|
2010-10-26 11:05:15 +04:00
|
|
|
Clobbers.push_back(S->getClobber(I));
|
2010-01-24 08:50:09 +03:00
|
|
|
|
|
|
|
// No need to transform the asm string literal.
|
|
|
|
AsmString = SemaRef.Owned(S->getAsmString());
|
|
|
|
|
|
|
|
return getDerived().RebuildAsmStmt(S->getAsmLoc(),
|
|
|
|
S->isSimple(),
|
|
|
|
S->isVolatile(),
|
|
|
|
S->getNumOutputs(),
|
|
|
|
S->getNumInputs(),
|
2010-01-30 23:05:21 +03:00
|
|
|
Names.data(),
|
2010-01-24 08:50:09 +03:00
|
|
|
move_arg(Constraints),
|
|
|
|
move_arg(Exprs),
|
2010-08-24 03:25:46 +04:00
|
|
|
AsmString.get(),
|
2010-01-24 08:50:09 +03:00
|
|
|
move_arg(Clobbers),
|
|
|
|
S->getRParenLoc(),
|
|
|
|
S->isMSAsm());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
|
2010-04-23 03:59:56 +04:00
|
|
|
// Transform the body of the @try.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
|
2010-04-23 03:59:56 +04:00
|
|
|
if (TryBody.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-24 02:50:49 +04:00
|
|
|
// Transform the @catch statements (if present).
|
|
|
|
bool AnyCatchChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Stmt*> CatchStmts(SemaRef);
|
2010-04-24 02:50:49 +04:00
|
|
|
for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
|
2010-04-23 03:59:56 +04:00
|
|
|
if (Catch.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-04-24 02:50:49 +04:00
|
|
|
if (Catch.get() != S->getCatchStmt(I))
|
|
|
|
AnyCatchChanged = true;
|
|
|
|
CatchStmts.push_back(Catch.release());
|
2010-04-23 03:59:56 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 03:59:56 +04:00
|
|
|
// Transform the @finally statement (if present).
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Finally;
|
2010-04-23 03:59:56 +04:00
|
|
|
if (S->getFinallyStmt()) {
|
|
|
|
Finally = getDerived().TransformStmt(S->getFinallyStmt());
|
|
|
|
if (Finally.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-04-23 03:59:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If nothing changed, just retain this statement.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
TryBody.get() == S->getTryBody() &&
|
2010-04-24 02:50:49 +04:00
|
|
|
!AnyCatchChanged &&
|
2010-04-23 03:59:56 +04:00
|
|
|
Finally.get() == S->getFinallyStmt())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 03:59:56 +04:00
|
|
|
// Build a new statement.
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
|
|
|
|
move_arg(CatchStmts), Finally.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
|
2010-04-26 21:57:08 +04:00
|
|
|
// Transform the @catch parameter, if there is one.
|
|
|
|
VarDecl *Var = 0;
|
|
|
|
if (VarDecl *FromVar = S->getCatchParamDecl()) {
|
|
|
|
TypeSourceInfo *TSInfo = 0;
|
|
|
|
if (FromVar->getTypeSourceInfo()) {
|
|
|
|
TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
|
|
|
|
if (!TSInfo)
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-04-26 21:57:08 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-26 21:57:08 +04:00
|
|
|
QualType T;
|
|
|
|
if (TSInfo)
|
|
|
|
T = TSInfo->getType();
|
|
|
|
else {
|
|
|
|
T = getDerived().TransformType(FromVar->getType());
|
|
|
|
if (T.isNull())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-04-26 21:57:08 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-26 21:57:08 +04:00
|
|
|
Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
|
|
|
|
if (!Var)
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-04-26 21:57:08 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
|
2010-04-26 21:57:08 +04:00
|
|
|
if (Body.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
|
2010-04-26 21:57:08 +04:00
|
|
|
S->getRParenLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Var, Body.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
|
2010-04-23 03:59:56 +04:00
|
|
|
// Transform the body.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
|
2010-04-23 03:59:56 +04:00
|
|
|
if (Body.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 03:59:56 +04:00
|
|
|
// If nothing changed, just retain this statement.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Body.get() == S->getFinallyBody())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2010-04-23 03:59:56 +04:00
|
|
|
|
|
|
|
// Build a new statement.
|
|
|
|
return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Body.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-09-09 19:08:12 +04:00
|
|
|
TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Operand;
|
2010-04-23 01:44:01 +04:00
|
|
|
if (S->getThrowExpr()) {
|
|
|
|
Operand = getDerived().TransformExpr(S->getThrowExpr());
|
|
|
|
if (Operand.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-04-23 01:44:01 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 01:44:01 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Operand.get() == S->getThrowExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return getSema().Owned(S);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-08-20 11:17:43 +04:00
|
|
|
TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
|
2009-09-09 19:08:12 +04:00
|
|
|
ObjCAtSynchronizedStmt *S) {
|
2010-04-23 02:01:21 +04:00
|
|
|
// Transform the object we are locking.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
|
2010-04-23 02:01:21 +04:00
|
|
|
if (Object.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 02:01:21 +04:00
|
|
|
// Transform the body.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
|
2010-04-23 02:01:21 +04:00
|
|
|
if (Body.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 02:01:21 +04:00
|
|
|
// If nothing change, just retain the current statement.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Object.get() == S->getSynchExpr() &&
|
|
|
|
Body.get() == S->getSynchBody())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2010-04-23 02:01:21 +04:00
|
|
|
|
|
|
|
// Build a new statement.
|
|
|
|
return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Object.get(), Body.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-08-20 11:17:43 +04:00
|
|
|
TreeTransform<Derived>::TransformObjCForCollectionStmt(
|
2009-09-09 19:08:12 +04:00
|
|
|
ObjCForCollectionStmt *S) {
|
2010-04-23 03:10:45 +04:00
|
|
|
// Transform the element statement.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Element = getDerived().TransformStmt(S->getElement());
|
2010-04-23 03:10:45 +04:00
|
|
|
if (Element.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 03:10:45 +04:00
|
|
|
// Transform the collection expression.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Collection = getDerived().TransformExpr(S->getCollection());
|
2010-04-23 03:10:45 +04:00
|
|
|
if (Collection.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 03:10:45 +04:00
|
|
|
// Transform the body.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Body = getDerived().TransformStmt(S->getBody());
|
2010-04-23 03:10:45 +04:00
|
|
|
if (Body.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 03:10:45 +04:00
|
|
|
// If nothing changed, just retain this statement.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Element.get() == S->getElement() &&
|
|
|
|
Collection.get() == S->getCollection() &&
|
|
|
|
Body.get() == S->getBody())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-23 03:10:45 +04:00
|
|
|
// Build a new statement.
|
|
|
|
return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
|
|
|
|
/*FIXME:*/S->getForLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Element.get(),
|
|
|
|
Collection.get(),
|
2010-04-23 03:10:45 +04:00
|
|
|
S->getRParenLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Body.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-08-20 11:17:43 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
|
|
|
|
// Transform the exception declaration, if any.
|
|
|
|
VarDecl *Var = 0;
|
|
|
|
if (S->getExceptionDecl()) {
|
|
|
|
VarDecl *ExceptionDecl = S->getExceptionDecl();
|
2010-09-09 21:09:21 +04:00
|
|
|
TypeSourceInfo *T = getDerived().TransformType(
|
|
|
|
ExceptionDecl->getTypeSourceInfo());
|
|
|
|
if (!T)
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-09-09 21:09:21 +04:00
|
|
|
Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
|
2009-08-20 11:17:43 +04:00
|
|
|
ExceptionDecl->getIdentifier(),
|
2010-09-09 21:09:21 +04:00
|
|
|
ExceptionDecl->getLocation());
|
2010-07-25 22:17:45 +04:00
|
|
|
if (!Var || Var->isInvalidDecl())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the actual exception handler.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
|
2010-07-25 22:17:45 +04:00
|
|
|
if (Handler.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
!Var &&
|
|
|
|
Handler.get() == S->getHandlerBlock())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
|
|
|
|
Var,
|
2010-08-24 03:25:46 +04:00
|
|
|
Handler.get());
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult
|
2009-08-20 11:17:43 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
|
|
|
|
// Transform the try block itself.
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult TryBlock
|
2009-08-20 11:17:43 +04:00
|
|
|
= getDerived().TransformCompoundStmt(S->getTryBlock());
|
|
|
|
if (TryBlock.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// Transform the handlers.
|
|
|
|
bool HandlerChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Stmt*> Handlers(SemaRef);
|
2009-08-20 11:17:43 +04:00
|
|
|
for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult Handler
|
2009-08-20 11:17:43 +04:00
|
|
|
= getDerived().TransformCXXCatchStmt(S->getHandler(I));
|
|
|
|
if (Handler.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return StmtError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
|
|
|
|
Handlers.push_back(Handler.takeAs<Stmt>());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
TryBlock.get() == S->getTryBlock() &&
|
|
|
|
!HandlerChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(S);
|
2009-08-20 11:17:43 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
|
2009-09-09 19:08:12 +04:00
|
|
|
move_arg(Handlers));
|
2009-08-20 11:17:43 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-08-11 09:31:07 +04:00
|
|
|
// Expression transformation
|
2009-08-04 20:50:30 +04:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
|
2009-10-23 22:54:35 +04:00
|
|
|
NestedNameSpecifier *Qualifier = 0;
|
|
|
|
if (E->getQualifier()) {
|
|
|
|
Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
|
2010-02-25 07:46:04 +03:00
|
|
|
E->getQualifierRange());
|
2009-10-23 22:54:35 +04:00
|
|
|
if (!Qualifier)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-10-23 22:54:35 +04:00
|
|
|
}
|
2009-12-08 12:08:17 +03:00
|
|
|
|
|
|
|
ValueDecl *ND
|
2010-03-01 18:56:25 +03:00
|
|
|
= cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
|
|
|
|
E->getDecl()));
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!ND)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-18 01:27:17 +04:00
|
|
|
DeclarationNameInfo NameInfo = E->getNameInfo();
|
|
|
|
if (NameInfo.getName()) {
|
|
|
|
NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
|
|
|
|
if (!NameInfo.getName())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-08-18 01:27:17 +04:00
|
|
|
}
|
2010-08-12 02:01:17 +04:00
|
|
|
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2009-10-23 22:54:35 +04:00
|
|
|
Qualifier == E->getQualifier() &&
|
|
|
|
ND == E->getDecl() &&
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo.getName() == E->getDecl()->getDeclName() &&
|
2010-08-20 03:49:38 +04:00
|
|
|
!E->hasExplicitTemplateArgs()) {
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-12-08 12:08:17 +03:00
|
|
|
// Mark it referenced in the new context regardless.
|
|
|
|
// FIXME: this is a bit instantiation-specific.
|
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
|
2009-10-23 22:54:35 +04:00
|
|
|
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-10-23 22:54:35 +04:00
|
|
|
}
|
2009-12-08 12:08:17 +03:00
|
|
|
|
|
|
|
TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
|
2010-08-20 03:49:38 +04:00
|
|
|
if (E->hasExplicitTemplateArgs()) {
|
2009-12-08 12:08:17 +03:00
|
|
|
TemplateArgs = &TransArgs;
|
|
|
|
TransArgs.setLAngleLoc(E->getLAngleLoc());
|
|
|
|
TransArgs.setRAngleLoc(E->getRAngleLoc());
|
2010-12-20 20:31:10 +03:00
|
|
|
if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
|
|
|
|
E->getNumTemplateArgs(),
|
|
|
|
TransArgs))
|
|
|
|
return ExprError();
|
2009-12-08 12:08:17 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 22:54:35 +04:00
|
|
|
return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
|
2010-08-12 02:01:17 +04:00
|
|
|
ND, NameInfo, TemplateArgs);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getRParen());
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
|
|
|
|
E->getOpcode(),
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
|
|
|
|
// Transform the type.
|
|
|
|
TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
|
|
|
|
if (!Type)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
// Transform all of the components into components similar to what the
|
|
|
|
// parser uses.
|
2010-05-05 19:23:54 +04:00
|
|
|
// FIXME: It would be slightly more efficient in the non-dependent case to
|
|
|
|
// just map FieldDecls, rather than requiring the rebuilder to look for
|
|
|
|
// the fields again. However, __builtin_offsetof is rare enough in
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
// template code that we don't care.
|
|
|
|
bool ExprChanged = false;
|
2010-08-27 03:41:50 +04:00
|
|
|
typedef Sema::OffsetOfComponent Component;
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
typedef OffsetOfExpr::OffsetOfNode Node;
|
|
|
|
llvm::SmallVector<Component, 4> Components;
|
|
|
|
for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
|
|
|
|
const Node &ON = E->getComponent(I);
|
|
|
|
Component Comp;
|
2010-05-01 00:35:01 +04:00
|
|
|
Comp.isBrackets = true;
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
Comp.LocStart = ON.getRange().getBegin();
|
|
|
|
Comp.LocEnd = ON.getRange().getEnd();
|
|
|
|
switch (ON.getKind()) {
|
|
|
|
case Node::Array: {
|
|
|
|
Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Index = getDerived().TransformExpr(FromIndex);
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
if (Index.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
ExprChanged = ExprChanged || Index.get() != FromIndex;
|
|
|
|
Comp.isBrackets = true;
|
2010-08-24 03:25:46 +04:00
|
|
|
Comp.U.E = Index.get();
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
break;
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
case Node::Field:
|
|
|
|
case Node::Identifier:
|
|
|
|
Comp.isBrackets = false;
|
|
|
|
Comp.U.IdentInfo = ON.getFieldName();
|
2010-04-29 02:43:14 +04:00
|
|
|
if (!Comp.U.IdentInfo)
|
|
|
|
continue;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
break;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-29 04:18:15 +04:00
|
|
|
case Node::Base:
|
|
|
|
// Will be recomputed during the rebuild.
|
|
|
|
continue;
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
Components.push_back(Comp);
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
// If nothing changed, retain the existing expression.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Type == E->getTypeSourceInfo() &&
|
|
|
|
!ExprChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
// Build a new offsetof expression.
|
|
|
|
return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
|
|
|
|
Components.data(), Components.size(),
|
|
|
|
E->getRParenLoc());
|
2010-11-16 02:31:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
ExprResult
|
|
|
|
TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
|
|
|
|
assert(getDerived().AlreadyTransformed(E->getType()) &&
|
|
|
|
"opaque value expression requires transformation");
|
|
|
|
return SemaRef.Owned(E);
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102542 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-29 02:16:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
if (E->isArgumentType()) {
|
2009-12-07 05:54:59 +03:00
|
|
|
TypeSourceInfo *OldT = E->getArgumentTypeInfo();
|
2009-10-28 03:29:27 +03:00
|
|
|
|
2009-12-07 05:54:59 +03:00
|
|
|
TypeSourceInfo *NewT = getDerived().TransformType(OldT);
|
2009-11-04 10:28:41 +03:00
|
|
|
if (!NewT)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-04 10:28:41 +03:00
|
|
|
if (!getDerived().AlwaysRebuild() && OldT == NewT)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-04 10:28:41 +03:00
|
|
|
return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
|
2009-09-09 19:08:12 +04:00
|
|
|
E->isSizeOf(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getSourceRange());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr;
|
2009-09-09 19:08:12 +04:00
|
|
|
{
|
2009-08-11 09:31:07 +04:00
|
|
|
// C++0x [expr.sizeof]p1:
|
|
|
|
// The operand is either an expression, which is an unevaluated operand
|
|
|
|
// [...]
|
2010-08-27 03:41:50 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
|
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->isSizeOf(),
|
|
|
|
E->getSourceRange());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult LHS = getDerived().TransformExpr(E->getLHS());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (LHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RHS = getDerived().TransformExpr(E->getRHS());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (RHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
LHS.get() == E->getLHS() &&
|
|
|
|
RHS.get() == E->getRHS())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildArraySubscriptExpr(LHS.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
/*FIXME:*/E->getLHS()->getLocStart(),
|
2010-08-24 03:25:46 +04:00
|
|
|
RHS.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getRBracketLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
// Transform the callee.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Callee = getDerived().TransformExpr(E->getCallee());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Callee.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-08-11 09:31:07 +04:00
|
|
|
|
|
|
|
// Transform arguments.
|
|
|
|
bool ArgChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> Args(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
|
|
|
|
&ArgChanged))
|
|
|
|
return ExprError();
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Callee.get() == E->getCallee() &&
|
|
|
|
!ArgChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// FIXME: Wrong source location information for the '('.
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation FakeLParenLoc
|
2009-08-11 09:31:07 +04:00
|
|
|
= ((Expr *)Callee.get())->getSourceRange().getBegin();
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
move_arg(Args),
|
|
|
|
E->getRParenLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Base = getDerived().TransformExpr(E->getBase());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-09-01 03:41:50 +04:00
|
|
|
NestedNameSpecifier *Qualifier = 0;
|
|
|
|
if (E->hasQualifier()) {
|
2009-09-09 19:08:12 +04:00
|
|
|
Qualifier
|
2009-09-01 03:41:50 +04:00
|
|
|
= getDerived().TransformNestedNameSpecifier(E->getQualifier(),
|
2010-02-25 07:46:04 +03:00
|
|
|
E->getQualifierRange());
|
2009-09-01 04:37:14 +04:00
|
|
|
if (Qualifier == 0)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-01 03:41:50 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-12-04 09:40:45 +03:00
|
|
|
ValueDecl *Member
|
2010-03-01 18:56:25 +03:00
|
|
|
= cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
|
|
|
|
E->getMemberDecl()));
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!Member)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-03-31 01:47:33 +04:00
|
|
|
NamedDecl *FoundDecl = E->getFoundDecl();
|
|
|
|
if (FoundDecl == E->getMemberDecl()) {
|
|
|
|
FoundDecl = Member;
|
|
|
|
} else {
|
|
|
|
FoundDecl = cast_or_null<NamedDecl>(
|
|
|
|
getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
|
|
|
|
if (!FoundDecl)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-03-31 01:47:33 +04:00
|
|
|
}
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Base.get() == E->getBase() &&
|
2009-09-01 03:41:50 +04:00
|
|
|
Qualifier == E->getQualifier() &&
|
2009-11-05 02:20:05 +03:00
|
|
|
Member == E->getMemberDecl() &&
|
2010-03-31 01:47:33 +04:00
|
|
|
FoundDecl == E->getFoundDecl() &&
|
2010-08-20 03:49:38 +04:00
|
|
|
!E->hasExplicitTemplateArgs()) {
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-12-22 08:24:09 +03:00
|
|
|
// Mark it referenced in the new context regardless.
|
|
|
|
// FIXME: this is a bit instantiation-specific.
|
|
|
|
SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-12-22 08:24:09 +03:00
|
|
|
}
|
2009-08-11 09:31:07 +04:00
|
|
|
|
2009-11-23 04:53:49 +03:00
|
|
|
TemplateArgumentListInfo TransArgs;
|
2010-08-20 03:49:38 +04:00
|
|
|
if (E->hasExplicitTemplateArgs()) {
|
2009-11-23 04:53:49 +03:00
|
|
|
TransArgs.setLAngleLoc(E->getLAngleLoc());
|
|
|
|
TransArgs.setRAngleLoc(E->getRAngleLoc());
|
2010-12-20 20:31:10 +03:00
|
|
|
if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
|
|
|
|
E->getNumTemplateArgs(),
|
|
|
|
TransArgs))
|
|
|
|
return ExprError();
|
2009-11-05 02:20:05 +03:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// FIXME: Bogus source location for the operator
|
|
|
|
SourceLocation FakeOperatorLoc
|
|
|
|
= SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
|
|
|
|
|
2010-01-15 11:34:02 +03:00
|
|
|
// FIXME: to do this check properly, we will need to preserve the
|
|
|
|
// first-qualifier-in-scope here, just in case we had a dependent
|
|
|
|
// base (and therefore couldn't do the check) and a
|
|
|
|
// nested-name-qualifier (and therefore could do the lookup).
|
|
|
|
NamedDecl *FirstQualifierInScope = 0;
|
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
E->isArrow(),
|
2009-09-01 03:41:50 +04:00
|
|
|
Qualifier,
|
|
|
|
E->getQualifierRange(),
|
2010-08-12 02:01:17 +04:00
|
|
|
E->getMemberNameInfo(),
|
2009-11-05 02:20:05 +03:00
|
|
|
Member,
|
2010-03-31 01:47:33 +04:00
|
|
|
FoundDecl,
|
2010-08-20 03:49:38 +04:00
|
|
|
(E->hasExplicitTemplateArgs()
|
2009-11-23 04:53:49 +03:00
|
|
|
? &TransArgs : 0),
|
2010-01-15 11:34:02 +03:00
|
|
|
FirstQualifierInScope);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult LHS = getDerived().TransformExpr(E->getLHS());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (LHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RHS = getDerived().TransformExpr(E->getRHS());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (RHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
LHS.get() == E->getLHS() &&
|
|
|
|
RHS.get() == E->getRHS())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
|
2010-08-24 03:25:46 +04:00
|
|
|
LHS.get(), RHS.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-08-11 09:31:07 +04:00
|
|
|
TreeTransform<Derived>::TransformCompoundAssignOperator(
|
2009-12-08 12:21:05 +03:00
|
|
|
CompoundAssignOperator *E) {
|
|
|
|
return getDerived().TransformBinaryOperator(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Cond = getDerived().TransformExpr(E->getCond());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Cond.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult LHS = getDerived().TransformExpr(E->getLHS());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (LHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RHS = getDerived().TransformExpr(E->getRHS());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (RHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Cond.get() == E->getCond() &&
|
|
|
|
LHS.get() == E->getLHS() &&
|
|
|
|
RHS.get() == E->getRHS())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildConditionalOperator(Cond.get(),
|
2009-08-26 18:37:04 +04:00
|
|
|
E->getQuestionLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
LHS.get(),
|
2009-08-26 18:37:04 +04:00
|
|
|
E->getColonLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
RHS.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
|
2009-12-12 21:16:41 +03:00
|
|
|
// Implicit casts are eliminated during transformation, since they
|
|
|
|
// will be recomputed by semantic analysis after transformation.
|
2009-12-14 22:27:10 +03:00
|
|
|
return getDerived().TransformExpr(E->getSubExprAsWritten());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
|
2010-09-09 20:55:46 +04:00
|
|
|
TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
|
|
|
|
if (!Type)
|
|
|
|
return ExprError();
|
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr
|
2009-12-14 22:27:10 +03:00
|
|
|
= getDerived().TransformExpr(E->getSubExprAsWritten());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-09-09 20:55:46 +04:00
|
|
|
Type == E->getTypeInfoAsWritten() &&
|
2009-08-11 09:31:07 +04:00
|
|
|
SubExpr.get() == E->getSubExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-01-15 21:39:57 +03:00
|
|
|
return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
|
2010-09-09 20:55:46 +04:00
|
|
|
Type,
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getRParenLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
|
2010-01-18 22:35:47 +03:00
|
|
|
TypeSourceInfo *OldT = E->getTypeSourceInfo();
|
|
|
|
TypeSourceInfo *NewT = getDerived().TransformType(OldT);
|
|
|
|
if (!NewT)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Init = getDerived().TransformExpr(E->getInitializer());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Init.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-01-18 22:35:47 +03:00
|
|
|
OldT == NewT &&
|
2009-08-11 09:31:07 +04:00
|
|
|
Init.get() == E->getInitializer())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
|
2010-01-20 01:33:45 +03:00
|
|
|
// Note: the expression type doesn't necessarily match the
|
|
|
|
// type-as-written, but that's okay, because it should always be
|
|
|
|
// derivable from the initializer.
|
|
|
|
|
2010-01-18 22:35:47 +03:00
|
|
|
return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
|
2009-08-11 09:31:07 +04:00
|
|
|
/*FIXME:*/E->getInitializer()->getLocEnd(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Init.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Base = getDerived().TransformExpr(E->getBase());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Base.get() == E->getBase())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// FIXME: Bad source location
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation FakeOperatorLoc
|
2009-08-11 09:31:07 +04:00
|
|
|
= SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getAccessorLoc(),
|
|
|
|
E->getAccessor());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
bool InitChanged = false;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*, 4> Inits(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
|
|
|
|
Inits, &InitChanged))
|
|
|
|
return ExprError();
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() && !InitChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
|
2009-11-09 20:16:50 +03:00
|
|
|
E->getRBraceLoc(), E->getType());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
Designation Desig;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// transform the initializer value
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Init = getDerived().TransformExpr(E->getInit());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Init.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// transform the designators.
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
|
2009-08-11 09:31:07 +04:00
|
|
|
bool ExprChanged = false;
|
|
|
|
for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
|
|
|
|
DEnd = E->designators_end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
if (D->isFieldDesignator()) {
|
|
|
|
Desig.AddDesignator(Designator::getField(D->getFieldName(),
|
|
|
|
D->getDotLoc(),
|
|
|
|
D->getFieldLoc()));
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (D->isArrayDesignator()) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Index.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
Desig.AddDesignator(Designator::getArray(Index.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
D->getLBracketLoc()));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
|
|
|
|
ArrayExprs.push_back(Index.release());
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
assert(D->isArrayRangeDesignator() && "New kind of designator?");
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Start
|
2009-08-11 09:31:07 +04:00
|
|
|
= getDerived().TransformExpr(E->getArrayRangeStart(*D));
|
|
|
|
if (Start.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
|
2009-08-11 09:31:07 +04:00
|
|
|
if (End.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
Desig.AddDesignator(Designator::getArrayRange(Start.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
End.get(),
|
|
|
|
D->getLBracketLoc(),
|
|
|
|
D->getEllipsisLoc()));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
|
|
|
|
End.get() != E->getArrayRangeEnd(*D);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
ArrayExprs.push_back(Start.release());
|
|
|
|
ArrayExprs.push_back(End.release());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Init.get() == E->getInit() &&
|
|
|
|
!ExprChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
|
|
|
|
E->getEqualOrColonLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
E->usesGNUSyntax(), Init.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-08-11 09:31:07 +04:00
|
|
|
TreeTransform<Derived>::TransformImplicitValueInitExpr(
|
2009-12-08 12:21:05 +03:00
|
|
|
ImplicitValueInitExpr *E) {
|
2009-10-28 03:29:27 +03:00
|
|
|
TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-10-28 03:29:27 +03:00
|
|
|
// FIXME: Will we ever have proper type location here? Will we actually
|
|
|
|
// need to transform the type?
|
2009-08-11 09:31:07 +04:00
|
|
|
QualType T = getDerived().TransformType(E->getType());
|
|
|
|
if (T.isNull())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
T == E->getType())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildImplicitValueInitExpr(T);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
|
2010-08-10 18:27:00 +04:00
|
|
|
TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
|
|
|
|
if (!TInfo)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-08-10 14:06:15 +04:00
|
|
|
TInfo == E->getWrittenTypeInfo() &&
|
2009-08-11 09:31:07 +04:00
|
|
|
SubExpr.get() == E->getSubExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
|
2010-08-10 14:06:15 +04:00
|
|
|
TInfo, E->getRParenLoc());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
bool ArgumentChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*, 4> Inits(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
|
|
|
|
&ArgumentChanged))
|
|
|
|
return ExprError();
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildParenListExpr(E->getLParenLoc(),
|
|
|
|
move_arg(Inits),
|
|
|
|
E->getRParenLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Transform an address-of-label expression.
|
|
|
|
///
|
|
|
|
/// By default, the transformation of an address-of-label expression always
|
|
|
|
/// rebuilds the expression, so that the label identifier can be resolved to
|
|
|
|
/// the corresponding label statement by semantic analysis.
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
|
|
|
|
E->getLabel());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
StmtResult SubStmt
|
2009-08-11 09:31:07 +04:00
|
|
|
= getDerived().TransformCompoundStmt(E->getSubStmt(), true);
|
|
|
|
if (SubStmt.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
SubStmt.get() == E->getSubStmt())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildStmtExpr(E->getLParenLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
SubStmt.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getRParenLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Cond = getDerived().TransformExpr(E->getCond());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Cond.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult LHS = getDerived().TransformExpr(E->getLHS());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (LHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult RHS = getDerived().TransformExpr(E->getRHS());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (RHS.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Cond.get() == E->getCond() &&
|
|
|
|
LHS.get() == E->getLHS() &&
|
|
|
|
RHS.get() == E->getRHS())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Cond.get(), LHS.get(), RHS.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getRParenLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
|
2009-12-13 23:44:55 +03:00
|
|
|
switch (E->getOperator()) {
|
|
|
|
case OO_New:
|
|
|
|
case OO_Delete:
|
|
|
|
case OO_Array_New:
|
|
|
|
case OO_Array_Delete:
|
|
|
|
llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-12-13 23:44:55 +03:00
|
|
|
case OO_Call: {
|
|
|
|
// This is a call to an object's operator().
|
|
|
|
assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
|
|
|
|
|
|
|
|
// Transform the object itself.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Object = getDerived().TransformExpr(E->getArg(0));
|
2009-12-13 23:44:55 +03:00
|
|
|
if (Object.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-13 23:44:55 +03:00
|
|
|
|
|
|
|
// FIXME: Poor location information
|
|
|
|
SourceLocation FakeLParenLoc
|
|
|
|
= SemaRef.PP.getLocForEndOfToken(
|
|
|
|
static_cast<Expr *>(Object.get())->getLocEnd());
|
|
|
|
|
|
|
|
// Transform the call arguments.
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> Args(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
|
|
|
|
Args))
|
|
|
|
return ExprError();
|
2009-12-13 23:44:55 +03:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
|
2009-12-13 23:44:55 +03:00
|
|
|
move_arg(Args),
|
|
|
|
E->getLocEnd());
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
|
|
|
|
case OO_##Name:
|
|
|
|
#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
|
|
|
|
#include "clang/Basic/OperatorKinds.def"
|
|
|
|
case OO_Subscript:
|
|
|
|
// Handled below.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OO_Conditional:
|
|
|
|
llvm_unreachable("conditional operator is not actually overloadable");
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-13 23:44:55 +03:00
|
|
|
|
|
|
|
case OO_None:
|
|
|
|
case NUM_OVERLOADED_OPERATORS:
|
|
|
|
llvm_unreachable("not an overloaded operator?");
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-13 23:44:55 +03:00
|
|
|
}
|
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Callee = getDerived().TransformExpr(E->getCallee());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Callee.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult First = getDerived().TransformExpr(E->getArg(0));
|
2009-08-11 09:31:07 +04:00
|
|
|
if (First.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-08-11 09:31:07 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Second;
|
2009-08-11 09:31:07 +04:00
|
|
|
if (E->getNumArgs() == 2) {
|
|
|
|
Second = getDerived().TransformExpr(E->getArg(1));
|
|
|
|
if (Second.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Callee.get() == E->getCallee() &&
|
|
|
|
First.get() == E->getArg(0) &&
|
2009-09-09 19:08:12 +04:00
|
|
|
(E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
|
|
|
|
E->getOperatorLoc(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Callee.get(),
|
|
|
|
First.get(),
|
|
|
|
Second.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
|
|
|
|
return getDerived().TransformCallExpr(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
|
2010-09-09 20:55:46 +04:00
|
|
|
TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
|
|
|
|
if (!Type)
|
|
|
|
return ExprError();
|
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr
|
2009-12-14 22:27:10 +03:00
|
|
|
= getDerived().TransformExpr(E->getSubExprAsWritten());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-09-09 20:55:46 +04:00
|
|
|
Type == E->getTypeInfoAsWritten() &&
|
2009-08-11 09:31:07 +04:00
|
|
|
SubExpr.get() == E->getSubExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// FIXME: Poor source location information here.
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation FakeLAngleLoc
|
2009-08-11 09:31:07 +04:00
|
|
|
= SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
|
|
|
|
SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
|
|
|
|
SourceLocation FakeRParenLoc
|
|
|
|
= SemaRef.PP.getLocForEndOfToken(
|
|
|
|
E->getSubExpr()->getSourceRange().getEnd());
|
|
|
|
return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
|
2009-09-09 19:08:12 +04:00
|
|
|
E->getStmtClass(),
|
2009-08-11 09:31:07 +04:00
|
|
|
FakeLAngleLoc,
|
2010-09-09 20:55:46 +04:00
|
|
|
Type,
|
2009-08-11 09:31:07 +04:00
|
|
|
FakeRAngleLoc,
|
|
|
|
FakeRAngleLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
FakeRParenLoc);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
|
|
|
|
return getDerived().TransformCXXNamedCastExpr(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
|
|
|
|
return getDerived().TransformCXXNamedCastExpr(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-08-11 09:31:07 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
|
2009-12-08 12:21:05 +03:00
|
|
|
CXXReinterpretCastExpr *E) {
|
|
|
|
return getDerived().TransformCXXNamedCastExpr(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
|
|
|
|
return getDerived().TransformCXXNamedCastExpr(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-08-11 09:31:07 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
|
2009-12-08 12:21:05 +03:00
|
|
|
CXXFunctionalCastExpr *E) {
|
2010-09-09 20:55:46 +04:00
|
|
|
TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
|
|
|
|
if (!Type)
|
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr
|
2009-12-14 22:27:10 +03:00
|
|
|
= getDerived().TransformExpr(E->getSubExprAsWritten());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-09-09 20:55:46 +04:00
|
|
|
Type == E->getTypeInfoAsWritten() &&
|
2009-08-11 09:31:07 +04:00
|
|
|
SubExpr.get() == E->getSubExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-09-09 20:55:46 +04:00
|
|
|
return getDerived().RebuildCXXFunctionalCastExpr(Type,
|
2009-08-11 09:31:07 +04:00
|
|
|
/*FIXME:*/E->getSubExpr()->getLocStart(),
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getRParenLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
if (E->isTypeOperand()) {
|
2010-04-27 02:37:10 +04:00
|
|
|
TypeSourceInfo *TInfo
|
|
|
|
= getDerived().TransformType(E->getTypeOperandSourceInfo());
|
|
|
|
if (!TInfo)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-04-27 02:37:10 +04:00
|
|
|
TInfo == E->getTypeOperandSourceInfo())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-04-27 02:37:10 +04:00
|
|
|
return getDerived().RebuildCXXTypeidExpr(E->getType(),
|
|
|
|
E->getLocStart(),
|
|
|
|
TInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getLocEnd());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// We don't know whether the expression is potentially evaluated until
|
|
|
|
// after we perform semantic analysis, so the expression is potentially
|
|
|
|
// potentially evaluated.
|
2009-09-09 19:08:12 +04:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef,
|
2010-08-27 03:41:50 +04:00
|
|
|
Sema::PotentiallyPotentiallyEvaluated);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
SubExpr.get() == E->getExprOperand())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-04-27 02:37:10 +04:00
|
|
|
return getDerived().RebuildCXXTypeidExpr(E->getType(),
|
|
|
|
E->getLocStart(),
|
2010-08-24 03:25:46 +04:00
|
|
|
SubExpr.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getLocEnd());
|
|
|
|
}
|
|
|
|
|
2010-09-08 16:20:18 +04:00
|
|
|
template<typename Derived>
|
|
|
|
ExprResult
|
|
|
|
TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
|
|
|
|
if (E->isTypeOperand()) {
|
|
|
|
TypeSourceInfo *TInfo
|
|
|
|
= getDerived().TransformType(E->getTypeOperandSourceInfo());
|
|
|
|
if (!TInfo)
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
TInfo == E->getTypeOperandSourceInfo())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-09-08 16:20:18 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildCXXTypeidExpr(E->getType(),
|
|
|
|
E->getLocStart(),
|
|
|
|
TInfo,
|
|
|
|
E->getLocEnd());
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't know whether the expression is potentially evaluated until
|
|
|
|
// after we perform semantic analysis, so the expression is potentially
|
|
|
|
// potentially evaluated.
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
|
|
|
|
|
|
|
|
ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
|
|
|
|
if (SubExpr.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
SubExpr.get() == E->getExprOperand())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-09-08 16:20:18 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildCXXUuidofExpr(E->getType(),
|
|
|
|
E->getLocStart(),
|
|
|
|
SubExpr.get(),
|
|
|
|
E->getLocEnd());
|
|
|
|
}
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-08-11 09:31:07 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
|
2009-12-08 12:21:05 +03:00
|
|
|
CXXNullPtrLiteralExpr *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
|
2010-09-09 20:55:46 +04:00
|
|
|
DeclContext *DC = getSema().getFunctionLevelDeclContext();
|
|
|
|
CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
|
|
|
|
QualType T = MD->getThisType(getSema().Context);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-09-09 20:55:46 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() && T == E->getType())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-01-08 02:12:05 +03:00
|
|
|
return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (SubExpr.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
SubExpr.get() == E->getSubExpr())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
|
2009-09-09 19:08:12 +04:00
|
|
|
ParmVarDecl *Param
|
2010-03-01 18:56:25 +03:00
|
|
|
= cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
|
|
|
|
E->getParam()));
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!Param)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-02-08 09:42:49 +03:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2009-08-11 09:31:07 +04:00
|
|
|
Param == E->getParam())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-12-24 02:03:06 +03:00
|
|
|
return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2010-09-08 04:15:04 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
|
|
|
|
CXXScalarValueInitExpr *E) {
|
|
|
|
TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
|
|
|
|
if (!T)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-09-08 04:15:04 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-09-08 04:15:04 +04:00
|
|
|
T == E->getTypeSourceInfo())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-09-08 04:15:04 +04:00
|
|
|
return getDerived().RebuildCXXScalarValueInitExpr(T,
|
|
|
|
/*FIXME:*/T->getTypeLoc().getEndLoc(),
|
2010-07-08 10:14:04 +04:00
|
|
|
E->getRParenLoc());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
// Transform the type that we're allocating
|
2010-09-08 01:49:58 +04:00
|
|
|
TypeSourceInfo *AllocTypeInfo
|
|
|
|
= getDerived().TransformType(E->getAllocatedTypeSourceInfo());
|
|
|
|
if (!AllocTypeInfo)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// Transform the size of the array we're allocating (if any).
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (ArraySize.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// Transform the placement arguments (if any).
|
|
|
|
bool ArgumentChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> PlacementArgs(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
if (getDerived().TransformExprs(E->getPlacementArgs(),
|
|
|
|
E->getNumPlacementArgs(), true,
|
|
|
|
PlacementArgs, &ArgumentChanged))
|
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-20 11:17:43 +04:00
|
|
|
// transform the constructor arguments (if any).
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
|
|
|
|
ConstructorArgs, &ArgumentChanged))
|
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-02-26 03:38:10 +03:00
|
|
|
// Transform constructor, new operator, and delete operator.
|
|
|
|
CXXConstructorDecl *Constructor = 0;
|
|
|
|
if (E->getConstructor()) {
|
|
|
|
Constructor = cast_or_null<CXXConstructorDecl>(
|
2010-03-01 18:56:25 +03:00
|
|
|
getDerived().TransformDecl(E->getLocStart(),
|
|
|
|
E->getConstructor()));
|
2010-02-26 03:38:10 +03:00
|
|
|
if (!Constructor)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-02-26 03:38:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionDecl *OperatorNew = 0;
|
|
|
|
if (E->getOperatorNew()) {
|
|
|
|
OperatorNew = cast_or_null<FunctionDecl>(
|
2010-03-01 18:56:25 +03:00
|
|
|
getDerived().TransformDecl(E->getLocStart(),
|
|
|
|
E->getOperatorNew()));
|
2010-02-26 03:38:10 +03:00
|
|
|
if (!OperatorNew)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-02-26 03:38:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionDecl *OperatorDelete = 0;
|
|
|
|
if (E->getOperatorDelete()) {
|
|
|
|
OperatorDelete = cast_or_null<FunctionDecl>(
|
2010-03-01 18:56:25 +03:00
|
|
|
getDerived().TransformDecl(E->getLocStart(),
|
|
|
|
E->getOperatorDelete()));
|
2010-02-26 03:38:10 +03:00
|
|
|
if (!OperatorDelete)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-02-26 03:38:10 +03:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-09-08 01:49:58 +04:00
|
|
|
AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
|
2009-08-11 09:31:07 +04:00
|
|
|
ArraySize.get() == E->getArraySize() &&
|
2010-02-26 03:38:10 +03:00
|
|
|
Constructor == E->getConstructor() &&
|
|
|
|
OperatorNew == E->getOperatorNew() &&
|
|
|
|
OperatorDelete == E->getOperatorDelete() &&
|
|
|
|
!ArgumentChanged) {
|
|
|
|
// Mark any declarations we need as referenced.
|
|
|
|
// FIXME: instantiation-specific.
|
|
|
|
if (Constructor)
|
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
|
|
|
|
if (OperatorNew)
|
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
|
|
|
|
if (OperatorDelete)
|
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-02-26 03:38:10 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-09-08 01:49:58 +04:00
|
|
|
QualType AllocType = AllocTypeInfo->getType();
|
2009-12-22 20:13:37 +03:00
|
|
|
if (!ArraySize.get()) {
|
|
|
|
// If no array size was specified, but the new expression was
|
|
|
|
// instantiated with an array type (e.g., "new T" where T is
|
|
|
|
// instantiated with "int[4]"), extract the outer bound from the
|
|
|
|
// array type as our array size. We do this with constant and
|
|
|
|
// dependently-sized array types.
|
|
|
|
const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
|
|
|
|
if (!ArrayT) {
|
|
|
|
// Do nothing
|
|
|
|
} else if (const ConstantArrayType *ConsArrayT
|
|
|
|
= dyn_cast<ConstantArrayType>(ArrayT)) {
|
2010-05-05 19:23:54 +04:00
|
|
|
ArraySize
|
2010-08-28 13:06:06 +04:00
|
|
|
= SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
|
|
|
|
ConsArrayT->getSize(),
|
|
|
|
SemaRef.Context.getSizeType(),
|
|
|
|
/*FIXME:*/E->getLocStart()));
|
2009-12-22 20:13:37 +03:00
|
|
|
AllocType = ConsArrayT->getElementType();
|
|
|
|
} else if (const DependentSizedArrayType *DepArrayT
|
|
|
|
= dyn_cast<DependentSizedArrayType>(ArrayT)) {
|
|
|
|
if (DepArrayT->getSizeExpr()) {
|
2010-10-26 11:05:15 +04:00
|
|
|
ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
|
2009-12-22 20:13:37 +03:00
|
|
|
AllocType = DepArrayT->getElementType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-08 01:49:58 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildCXXNewExpr(E->getLocStart(),
|
|
|
|
E->isGlobalNew(),
|
|
|
|
/*FIXME:*/E->getLocStart(),
|
|
|
|
move_arg(PlacementArgs),
|
|
|
|
/*FIXME:*/E->getLocStart(),
|
2010-07-13 19:54:32 +04:00
|
|
|
E->getTypeIdParens(),
|
2009-08-11 09:31:07 +04:00
|
|
|
AllocType,
|
2010-09-08 01:49:58 +04:00
|
|
|
AllocTypeInfo,
|
2010-08-24 03:25:46 +04:00
|
|
|
ArraySize.get(),
|
2009-08-11 09:31:07 +04:00
|
|
|
/*FIXME:*/E->getLocStart(),
|
|
|
|
move_arg(ConstructorArgs),
|
2009-09-09 19:08:12 +04:00
|
|
|
E->getLocEnd());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Operand = getDerived().TransformExpr(E->getArgument());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Operand.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-02-26 03:38:10 +03:00
|
|
|
// Transform the delete operator, if known.
|
|
|
|
FunctionDecl *OperatorDelete = 0;
|
|
|
|
if (E->getOperatorDelete()) {
|
|
|
|
OperatorDelete = cast_or_null<FunctionDecl>(
|
2010-03-01 18:56:25 +03:00
|
|
|
getDerived().TransformDecl(E->getLocStart(),
|
|
|
|
E->getOperatorDelete()));
|
2010-02-26 03:38:10 +03:00
|
|
|
if (!OperatorDelete)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-02-26 03:38:10 +03:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-02-26 03:38:10 +03:00
|
|
|
Operand.get() == E->getArgument() &&
|
|
|
|
OperatorDelete == E->getOperatorDelete()) {
|
|
|
|
// Mark any declarations we need as referenced.
|
|
|
|
// FIXME: instantiation-specific.
|
|
|
|
if (OperatorDelete)
|
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
|
2010-09-15 02:55:20 +04:00
|
|
|
|
|
|
|
if (!E->getArgument()->isTypeDependent()) {
|
|
|
|
QualType Destroyed = SemaRef.Context.getBaseElementType(
|
|
|
|
E->getDestroyedType());
|
|
|
|
if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
|
|
|
|
CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
|
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocStart(),
|
|
|
|
SemaRef.LookupDestructor(Record));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-02-26 03:38:10 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
|
|
|
|
E->isGlobalDelete(),
|
|
|
|
E->isArrayForm(),
|
2010-08-24 03:25:46 +04:00
|
|
|
Operand.get());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-09-04 21:36:40 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
|
2009-12-08 12:21:05 +03:00
|
|
|
CXXPseudoDestructorExpr *E) {
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Base = getDerived().TransformExpr(E->getBase());
|
2009-09-04 21:36:40 +04:00
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 09:47:05 +04:00
|
|
|
ParsedType ObjectTypePtr;
|
2010-02-25 04:56:36 +03:00
|
|
|
bool MayBePseudoDestructor = false;
|
2010-08-24 03:25:46 +04:00
|
|
|
Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
|
2010-02-25 04:56:36 +03:00
|
|
|
E->getOperatorLoc(),
|
|
|
|
E->isArrow()? tok::arrow : tok::period,
|
|
|
|
ObjectTypePtr,
|
|
|
|
MayBePseudoDestructor);
|
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 09:47:05 +04:00
|
|
|
QualType ObjectType = ObjectTypePtr.get();
|
2010-11-12 11:19:04 +03:00
|
|
|
NestedNameSpecifier *Qualifier = E->getQualifier();
|
|
|
|
if (Qualifier) {
|
|
|
|
Qualifier
|
|
|
|
= getDerived().TransformNestedNameSpecifier(E->getQualifier(),
|
|
|
|
E->getQualifierRange(),
|
|
|
|
ObjectType);
|
|
|
|
if (!Qualifier)
|
|
|
|
return ExprError();
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-02-25 04:56:36 +03:00
|
|
|
PseudoDestructorTypeStorage Destroyed;
|
|
|
|
if (E->getDestroyedTypeInfo()) {
|
|
|
|
TypeSourceInfo *DestroyedTypeInfo
|
2010-11-12 11:19:04 +03:00
|
|
|
= getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
|
|
|
|
ObjectType, 0, Qualifier);
|
2010-02-25 04:56:36 +03:00
|
|
|
if (!DestroyedTypeInfo)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-02-25 04:56:36 +03:00
|
|
|
Destroyed = DestroyedTypeInfo;
|
|
|
|
} else if (ObjectType->isDependentType()) {
|
|
|
|
// We aren't likely to be able to resolve the identifier down to a type
|
|
|
|
// now anyway, so just retain the identifier.
|
|
|
|
Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
|
|
|
|
E->getDestroyedTypeLoc());
|
|
|
|
} else {
|
|
|
|
// Look for a destructor known with the given name.
|
|
|
|
CXXScopeSpec SS;
|
|
|
|
if (Qualifier) {
|
|
|
|
SS.setScopeRep(Qualifier);
|
|
|
|
SS.setRange(E->getQualifierRange());
|
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 09:47:05 +04:00
|
|
|
ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
|
2010-02-25 04:56:36 +03:00
|
|
|
*E->getDestroyedTypeIdentifier(),
|
|
|
|
E->getDestroyedTypeLoc(),
|
|
|
|
/*Scope=*/0,
|
|
|
|
SS, ObjectTypePtr,
|
|
|
|
false);
|
|
|
|
if (!T)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-02-25 04:56:36 +03:00
|
|
|
Destroyed
|
|
|
|
= SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
|
|
|
|
E->getDestroyedTypeLoc());
|
|
|
|
}
|
2010-02-25 02:40:28 +03:00
|
|
|
|
|
|
|
TypeSourceInfo *ScopeTypeInfo = 0;
|
|
|
|
if (E->getScopeTypeInfo()) {
|
2010-11-12 11:19:04 +03:00
|
|
|
ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
|
2010-02-25 02:40:28 +03:00
|
|
|
if (!ScopeTypeInfo)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-04 21:36:40 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
|
2009-09-04 21:36:40 +04:00
|
|
|
E->getOperatorLoc(),
|
|
|
|
E->isArrow(),
|
|
|
|
Qualifier,
|
2010-02-25 02:40:28 +03:00
|
|
|
E->getQualifierRange(),
|
|
|
|
ScopeTypeInfo,
|
|
|
|
E->getColonColonLoc(),
|
2010-02-25 02:50:37 +03:00
|
|
|
E->getTildeLoc(),
|
2010-02-25 04:56:36 +03:00
|
|
|
Destroyed);
|
2009-09-04 21:36:40 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-09-04 21:36:40 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-11-21 11:51:07 +03:00
|
|
|
TreeTransform<Derived>::TransformUnresolvedLookupExpr(
|
2009-12-08 12:21:05 +03:00
|
|
|
UnresolvedLookupExpr *Old) {
|
2009-11-24 22:00:30 +03:00
|
|
|
TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
|
|
|
|
|
|
|
|
LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
|
|
|
|
Sema::LookupOrdinaryName);
|
|
|
|
|
|
|
|
// Transform all the decls.
|
|
|
|
for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
|
|
|
|
E = Old->decls_end(); I != E; ++I) {
|
2010-03-01 18:56:25 +03:00
|
|
|
NamedDecl *InstD = static_cast<NamedDecl*>(
|
|
|
|
getDerived().TransformDecl(Old->getNameLoc(),
|
|
|
|
*I));
|
2009-12-10 12:41:52 +03:00
|
|
|
if (!InstD) {
|
|
|
|
// Silently ignore these if a UsingShadowDecl instantiated to nothing.
|
|
|
|
// This can happen because of dependent hiding.
|
|
|
|
if (isa<UsingShadowDecl>(*I))
|
|
|
|
continue;
|
|
|
|
else
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-10 12:41:52 +03:00
|
|
|
}
|
2009-11-24 22:00:30 +03:00
|
|
|
|
|
|
|
// Expand using declarations.
|
|
|
|
if (isa<UsingDecl>(InstD)) {
|
|
|
|
UsingDecl *UD = cast<UsingDecl>(InstD);
|
|
|
|
for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
|
|
|
|
E = UD->shadow_end(); I != E; ++I)
|
|
|
|
R.addDecl(*I);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
R.addDecl(InstD);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resolve a kind, but don't do any further analysis. If it's
|
|
|
|
// ambiguous, the callee needs to deal with it.
|
|
|
|
R.resolveKind();
|
|
|
|
|
|
|
|
// Rebuild the nested-name qualifier, if present.
|
|
|
|
CXXScopeSpec SS;
|
|
|
|
NestedNameSpecifier *Qualifier = 0;
|
|
|
|
if (Old->getQualifier()) {
|
|
|
|
Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
|
2010-02-25 07:46:04 +03:00
|
|
|
Old->getQualifierRange());
|
2009-11-24 22:00:30 +03:00
|
|
|
if (!Qualifier)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-11-24 22:00:30 +03:00
|
|
|
SS.setScopeRep(Qualifier);
|
|
|
|
SS.setRange(Old->getQualifierRange());
|
2010-05-05 19:23:54 +04:00
|
|
|
}
|
|
|
|
|
2010-04-27 22:19:34 +04:00
|
|
|
if (Old->getNamingClass()) {
|
2010-04-27 20:10:10 +04:00
|
|
|
CXXRecordDecl *NamingClass
|
|
|
|
= cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
|
|
|
|
Old->getNameLoc(),
|
|
|
|
Old->getNamingClass()));
|
|
|
|
if (!NamingClass)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 20:10:10 +04:00
|
|
|
R.setNamingClass(NamingClass);
|
2009-11-24 22:00:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we have no template arguments, it's a normal declaration name.
|
|
|
|
if (!Old->hasExplicitTemplateArgs())
|
|
|
|
return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
|
|
|
|
|
|
|
|
// If we have template arguments, rebuild them, then rebuild the
|
|
|
|
// templateid expression.
|
|
|
|
TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
|
2010-12-20 20:31:10 +03:00
|
|
|
if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
|
|
|
|
Old->getNumTemplateArgs(),
|
|
|
|
TransArgs))
|
|
|
|
return ExprError();
|
2009-11-24 22:00:30 +03:00
|
|
|
|
|
|
|
return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
|
|
|
|
TransArgs);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
|
2010-09-09 20:14:44 +04:00
|
|
|
TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
|
|
|
|
if (!T)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-09-09 20:14:44 +04:00
|
|
|
T == E->getQueriedTypeSourceInfo())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getLocStart(),
|
|
|
|
T,
|
|
|
|
E->getLocEnd());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-12-07 03:08:36 +03:00
|
|
|
template<typename Derived>
|
|
|
|
ExprResult
|
|
|
|
TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
|
|
|
|
TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
|
|
|
|
if (!LhsT)
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
|
|
|
|
if (!RhsT)
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
|
|
|
|
return SemaRef.Owned(E);
|
|
|
|
|
|
|
|
return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
|
|
|
|
E->getLocStart(),
|
|
|
|
LhsT, RhsT,
|
|
|
|
E->getLocEnd());
|
|
|
|
}
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-11-20 01:55:06 +03:00
|
|
|
TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
|
2010-08-12 02:01:17 +04:00
|
|
|
DependentScopeDeclRefExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
NestedNameSpecifier *NNS
|
2009-10-22 21:20:55 +04:00
|
|
|
= getDerived().TransformNestedNameSpecifier(E->getQualifier(),
|
2010-02-25 07:46:04 +03:00
|
|
|
E->getQualifierRange());
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!NNS)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
// TODO: If this is a conversion-function-id, verify that the
|
|
|
|
// destination type name (if present) resolves the same way after
|
|
|
|
// instantiation as it did in the local scope.
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationNameInfo NameInfo
|
|
|
|
= getDerived().TransformDeclarationNameInfo(E->getNameInfo());
|
|
|
|
if (!NameInfo.getName())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-24 22:00:30 +03:00
|
|
|
if (!E->hasExplicitTemplateArgs()) {
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
NNS == E->getQualifier() &&
|
2010-08-12 02:01:17 +04:00
|
|
|
// Note: it is sufficient to compare the Name component of NameInfo:
|
|
|
|
// if name has not changed, DNLoc has not changed either.
|
|
|
|
NameInfo.getName() == E->getDeclName())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-24 22:00:30 +03:00
|
|
|
return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
|
|
|
|
E->getQualifierRange(),
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo,
|
2009-11-24 22:00:30 +03:00
|
|
|
/*TemplateArgs*/ 0);
|
2009-10-22 21:20:55 +04:00
|
|
|
}
|
2009-11-23 04:53:49 +03:00
|
|
|
|
|
|
|
TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
|
2010-12-20 20:31:10 +03:00
|
|
|
if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
|
|
|
|
E->getNumTemplateArgs(),
|
|
|
|
TransArgs))
|
|
|
|
return ExprError();
|
2009-08-11 09:31:07 +04:00
|
|
|
|
2009-11-24 22:00:30 +03:00
|
|
|
return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
|
|
|
|
E->getQualifierRange(),
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo,
|
2009-11-24 22:00:30 +03:00
|
|
|
&TransArgs);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
|
2010-02-03 06:01:57 +03:00
|
|
|
// CXXConstructExprs are always implicit, so when we have a
|
|
|
|
// 1-argument construction we just transform that argument.
|
|
|
|
if (E->getNumArgs() == 1 ||
|
|
|
|
(E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
|
|
|
|
return getDerived().TransformExpr(E->getArg(0));
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
|
|
|
|
|
|
|
|
QualType T = getDerived().TransformType(E->getType());
|
|
|
|
if (T.isNull())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-08-11 09:31:07 +04:00
|
|
|
|
|
|
|
CXXConstructorDecl *Constructor
|
|
|
|
= cast_or_null<CXXConstructorDecl>(
|
2010-03-01 18:56:25 +03:00
|
|
|
getDerived().TransformDecl(E->getLocStart(),
|
|
|
|
E->getConstructor()));
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!Constructor)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
bool ArgumentChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> Args(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
|
|
|
|
&ArgumentChanged))
|
|
|
|
return ExprError();
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
T == E->getType() &&
|
|
|
|
Constructor == E->getConstructor() &&
|
2010-02-26 03:01:57 +03:00
|
|
|
!ArgumentChanged) {
|
2010-02-26 03:38:10 +03:00
|
|
|
// Mark the constructor as referenced.
|
|
|
|
// FIXME: Instantiation-specific
|
2010-02-26 03:01:57 +03:00
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-02-26 03:01:57 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-12-14 19:27:04 +03:00
|
|
|
return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
|
|
|
|
Constructor, E->isElidable(),
|
2010-08-22 21:20:18 +04:00
|
|
|
move_arg(Args),
|
|
|
|
E->requiresZeroInitialization(),
|
2010-10-25 12:47:36 +04:00
|
|
|
E->getConstructionKind(),
|
|
|
|
E->getParenRange());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
/// \brief Transform a C++ temporary-binding expression.
|
|
|
|
///
|
2009-12-24 21:51:59 +03:00
|
|
|
/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
|
|
|
|
/// transform the subexpression and return that.
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
|
2009-12-24 21:51:59 +03:00
|
|
|
return getDerived().TransformExpr(E->getSubExpr());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-12-06 11:20:24 +03:00
|
|
|
/// \brief Transform a C++ expression that contains cleanups that should
|
|
|
|
/// be run after the expression is evaluated.
|
2009-08-11 09:31:07 +04:00
|
|
|
///
|
2010-12-06 11:20:24 +03:00
|
|
|
/// Since ExprWithCleanups nodes are implicitly generated, we
|
2009-12-24 21:51:59 +03:00
|
|
|
/// just transform the subexpression and return that.
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2010-12-06 11:20:24 +03:00
|
|
|
TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
|
2009-12-24 21:51:59 +03:00
|
|
|
return getDerived().TransformExpr(E->getSubExpr());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-08-11 09:31:07 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
|
2010-09-08 04:15:04 +04:00
|
|
|
CXXTemporaryObjectExpr *E) {
|
|
|
|
TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
|
|
|
|
if (!T)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
CXXConstructorDecl *Constructor
|
|
|
|
= cast_or_null<CXXConstructorDecl>(
|
2010-05-05 19:23:54 +04:00
|
|
|
getDerived().TransformDecl(E->getLocStart(),
|
2010-03-01 18:56:25 +03:00
|
|
|
E->getConstructor()));
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!Constructor)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
bool ArgumentChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> Args(SemaRef);
|
2009-08-11 09:31:07 +04:00
|
|
|
Args.reserve(E->getNumArgs());
|
2011-01-03 22:04:46 +03:00
|
|
|
if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
|
|
|
|
&ArgumentChanged))
|
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-09-08 04:15:04 +04:00
|
|
|
T == E->getTypeSourceInfo() &&
|
2009-08-11 09:31:07 +04:00
|
|
|
Constructor == E->getConstructor() &&
|
2010-03-02 20:18:33 +03:00
|
|
|
!ArgumentChanged) {
|
|
|
|
// FIXME: Instantiation-specific
|
2010-09-08 04:15:04 +04:00
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.MaybeBindToTemporary(E);
|
2010-03-02 20:18:33 +03:00
|
|
|
}
|
2010-09-08 04:15:04 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildCXXTemporaryObjectExpr(T,
|
|
|
|
/*FIXME:*/T->getTypeLoc().getEndLoc(),
|
2009-08-11 09:31:07 +04:00
|
|
|
move_arg(Args),
|
|
|
|
E->getLocEnd());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-08-11 09:31:07 +04:00
|
|
|
TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
|
2009-12-08 12:21:05 +03:00
|
|
|
CXXUnresolvedConstructExpr *E) {
|
2010-09-08 04:15:04 +04:00
|
|
|
TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
|
|
|
|
if (!T)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
bool ArgumentChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> Args(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
Args.reserve(E->arg_size());
|
|
|
|
if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
|
|
|
|
&ArgumentChanged))
|
|
|
|
return ExprError();
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-09-08 04:15:04 +04:00
|
|
|
T == E->getTypeSourceInfo() &&
|
2009-08-11 09:31:07 +04:00
|
|
|
!ArgumentChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// FIXME: we're faking the locations of the commas
|
2010-09-08 04:15:04 +04:00
|
|
|
return getDerived().RebuildCXXUnresolvedConstructExpr(T,
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getLParenLoc(),
|
|
|
|
move_arg(Args),
|
|
|
|
E->getRParenLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-11-20 01:55:06 +03:00
|
|
|
TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
|
2010-08-12 02:01:17 +04:00
|
|
|
CXXDependentScopeMemberExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
// Transform the base of the expression.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Base((Expr*) 0);
|
2009-12-02 01:10:20 +03:00
|
|
|
Expr *OldBase;
|
|
|
|
QualType BaseType;
|
|
|
|
QualType ObjectType;
|
|
|
|
if (!E->isImplicitAccess()) {
|
|
|
|
OldBase = E->getBase();
|
|
|
|
Base = getDerived().TransformExpr(OldBase);
|
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-12-02 01:10:20 +03:00
|
|
|
// Start the member reference and compute the object's type.
|
2010-08-24 09:47:05 +04:00
|
|
|
ParsedType ObjectTy;
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97045 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-24 21:44:31 +03:00
|
|
|
bool MayBePseudoDestructor = false;
|
2010-08-24 03:25:46 +04:00
|
|
|
Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
|
2009-12-02 01:10:20 +03:00
|
|
|
E->getOperatorLoc(),
|
2009-09-03 20:14:30 +04:00
|
|
|
E->isArrow()? tok::arrow : tok::period,
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97045 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-24 21:44:31 +03:00
|
|
|
ObjectTy,
|
|
|
|
MayBePseudoDestructor);
|
2009-12-02 01:10:20 +03:00
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-02 01:10:20 +03:00
|
|
|
|
2010-08-24 09:47:05 +04:00
|
|
|
ObjectType = ObjectTy.get();
|
2009-12-02 01:10:20 +03:00
|
|
|
BaseType = ((Expr*) Base.get())->getType();
|
|
|
|
} else {
|
|
|
|
OldBase = 0;
|
|
|
|
BaseType = getDerived().TransformType(E->getBaseType());
|
|
|
|
ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-20 09:58:46 +04:00
|
|
|
// Transform the first part of the nested-name-specifier that qualifies
|
|
|
|
// the member name.
|
2009-09-04 01:38:09 +04:00
|
|
|
NamedDecl *FirstQualifierInScope
|
2009-10-20 09:58:46 +04:00
|
|
|
= getDerived().TransformFirstQualifierInScope(
|
|
|
|
E->getFirstQualifierFoundInScope(),
|
|
|
|
E->getQualifierRange().getBegin());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-09-03 20:14:30 +04:00
|
|
|
NestedNameSpecifier *Qualifier = 0;
|
|
|
|
if (E->getQualifier()) {
|
|
|
|
Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
|
|
|
|
E->getQualifierRange(),
|
2009-12-02 01:10:20 +03:00
|
|
|
ObjectType,
|
|
|
|
FirstQualifierInScope);
|
2009-09-03 20:14:30 +04:00
|
|
|
if (!Qualifier)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-03 20:14:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-11-12 11:19:04 +03:00
|
|
|
// TODO: If this is a conversion-function-id, verify that the
|
|
|
|
// destination type name (if present) resolves the same way after
|
|
|
|
// instantiation as it did in the local scope.
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationNameInfo NameInfo
|
2010-11-12 11:19:04 +03:00
|
|
|
= getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
|
2010-08-12 02:01:17 +04:00
|
|
|
if (!NameInfo.getName())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-12-02 01:10:20 +03:00
|
|
|
if (!E->hasExplicitTemplateArgs()) {
|
2009-09-09 04:23:06 +04:00
|
|
|
// This is a reference to a member without an explicitly-specified
|
|
|
|
// template argument list. Optimize for this common case.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2009-12-02 01:10:20 +03:00
|
|
|
Base.get() == OldBase &&
|
|
|
|
BaseType == E->getBaseType() &&
|
2009-09-09 04:23:06 +04:00
|
|
|
Qualifier == E->getQualifier() &&
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo.getName() == E->getMember() &&
|
2009-09-09 04:23:06 +04:00
|
|
|
FirstQualifierInScope == E->getFirstQualifierFoundInScope())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
|
2009-12-02 01:10:20 +03:00
|
|
|
BaseType,
|
2009-09-09 04:23:06 +04:00
|
|
|
E->isArrow(),
|
|
|
|
E->getOperatorLoc(),
|
|
|
|
Qualifier,
|
|
|
|
E->getQualifierRange(),
|
2009-12-01 01:42:35 +03:00
|
|
|
FirstQualifierInScope,
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo,
|
2009-12-01 01:42:35 +03:00
|
|
|
/*TemplateArgs*/ 0);
|
2009-09-09 04:23:06 +04:00
|
|
|
}
|
|
|
|
|
2009-11-23 04:53:49 +03:00
|
|
|
TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
|
2010-12-20 20:31:10 +03:00
|
|
|
if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
|
|
|
|
E->getNumTemplateArgs(),
|
|
|
|
TransArgs))
|
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
|
2009-12-02 01:10:20 +03:00
|
|
|
BaseType,
|
2009-08-11 09:31:07 +04:00
|
|
|
E->isArrow(),
|
|
|
|
E->getOperatorLoc(),
|
2009-09-03 20:14:30 +04:00
|
|
|
Qualifier,
|
|
|
|
E->getQualifierRange(),
|
2009-09-09 04:23:06 +04:00
|
|
|
FirstQualifierInScope,
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo,
|
2009-12-01 01:42:35 +03:00
|
|
|
&TransArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
|
2009-12-01 01:42:35 +03:00
|
|
|
// Transform the base of the expression.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Base((Expr*) 0);
|
2009-12-02 01:10:20 +03:00
|
|
|
QualType BaseType;
|
|
|
|
if (!Old->isImplicitAccess()) {
|
|
|
|
Base = getDerived().TransformExpr(Old->getBase());
|
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-02 01:10:20 +03:00
|
|
|
BaseType = ((Expr*) Base.get())->getType();
|
|
|
|
} else {
|
|
|
|
BaseType = getDerived().TransformType(Old->getBaseType());
|
|
|
|
}
|
2009-12-01 01:42:35 +03:00
|
|
|
|
|
|
|
NestedNameSpecifier *Qualifier = 0;
|
|
|
|
if (Old->getQualifier()) {
|
|
|
|
Qualifier
|
|
|
|
= getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
|
2010-02-25 07:46:04 +03:00
|
|
|
Old->getQualifierRange());
|
2009-12-01 01:42:35 +03:00
|
|
|
if (Qualifier == 0)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-01 01:42:35 +03:00
|
|
|
}
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
LookupResult R(SemaRef, Old->getMemberNameInfo(),
|
2009-12-01 01:42:35 +03:00
|
|
|
Sema::LookupOrdinaryName);
|
|
|
|
|
|
|
|
// Transform all the decls.
|
|
|
|
for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
|
|
|
|
E = Old->decls_end(); I != E; ++I) {
|
2010-03-01 18:56:25 +03:00
|
|
|
NamedDecl *InstD = static_cast<NamedDecl*>(
|
|
|
|
getDerived().TransformDecl(Old->getMemberLoc(),
|
|
|
|
*I));
|
2009-12-10 12:41:52 +03:00
|
|
|
if (!InstD) {
|
|
|
|
// Silently ignore these if a UsingShadowDecl instantiated to nothing.
|
|
|
|
// This can happen because of dependent hiding.
|
|
|
|
if (isa<UsingShadowDecl>(*I))
|
|
|
|
continue;
|
|
|
|
else
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-12-10 12:41:52 +03:00
|
|
|
}
|
2009-12-01 01:42:35 +03:00
|
|
|
|
|
|
|
// Expand using declarations.
|
|
|
|
if (isa<UsingDecl>(InstD)) {
|
|
|
|
UsingDecl *UD = cast<UsingDecl>(InstD);
|
|
|
|
for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
|
|
|
|
E = UD->shadow_end(); I != E; ++I)
|
|
|
|
R.addDecl(*I);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
R.addDecl(InstD);
|
|
|
|
}
|
|
|
|
|
|
|
|
R.resolveKind();
|
|
|
|
|
2010-04-27 22:19:34 +04:00
|
|
|
// Determine the naming class.
|
2010-05-19 05:37:01 +04:00
|
|
|
if (Old->getNamingClass()) {
|
2010-05-05 19:23:54 +04:00
|
|
|
CXXRecordDecl *NamingClass
|
2010-04-27 22:19:34 +04:00
|
|
|
= cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
|
2010-04-27 20:10:10 +04:00
|
|
|
Old->getMemberLoc(),
|
|
|
|
Old->getNamingClass()));
|
|
|
|
if (!NamingClass)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 20:10:10 +04:00
|
|
|
R.setNamingClass(NamingClass);
|
2010-04-27 22:19:34 +04:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-12-01 01:42:35 +03:00
|
|
|
TemplateArgumentListInfo TransArgs;
|
|
|
|
if (Old->hasExplicitTemplateArgs()) {
|
|
|
|
TransArgs.setLAngleLoc(Old->getLAngleLoc());
|
|
|
|
TransArgs.setRAngleLoc(Old->getRAngleLoc());
|
2010-12-20 20:31:10 +03:00
|
|
|
if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
|
|
|
|
Old->getNumTemplateArgs(),
|
|
|
|
TransArgs))
|
|
|
|
return ExprError();
|
2009-12-01 01:42:35 +03:00
|
|
|
}
|
2010-01-15 11:34:02 +03:00
|
|
|
|
|
|
|
// FIXME: to do this check properly, we will need to preserve the
|
|
|
|
// first-qualifier-in-scope here, just in case we had a dependent
|
|
|
|
// base (and therefore couldn't do the check) and a
|
|
|
|
// nested-name-qualifier (and therefore could do the lookup).
|
|
|
|
NamedDecl *FirstQualifierInScope = 0;
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
|
2009-12-02 01:10:20 +03:00
|
|
|
BaseType,
|
2009-12-01 01:42:35 +03:00
|
|
|
Old->getOperatorLoc(),
|
|
|
|
Old->isArrow(),
|
|
|
|
Qualifier,
|
|
|
|
Old->getQualifierRange(),
|
2010-01-15 11:34:02 +03:00
|
|
|
FirstQualifierInScope,
|
2009-12-01 01:42:35 +03:00
|
|
|
R,
|
|
|
|
(Old->hasExplicitTemplateArgs()
|
|
|
|
? &TransArgs : 0));
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2010-09-11 00:55:43 +04:00
|
|
|
template<typename Derived>
|
|
|
|
ExprResult
|
|
|
|
TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
|
|
|
|
ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
|
|
|
|
if (SubExpr.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-09-11 00:55:43 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
|
|
|
|
}
|
|
|
|
|
2011-01-03 20:17:50 +03:00
|
|
|
template<typename Derived>
|
|
|
|
ExprResult
|
|
|
|
TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
|
2011-01-13 03:19:55 +03:00
|
|
|
ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
|
|
|
|
if (Pattern.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
|
|
|
|
return SemaRef.Owned(E);
|
|
|
|
|
2011-01-15 00:20:45 +03:00
|
|
|
return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
|
|
|
|
E->getNumExpansions());
|
2011-01-03 20:17:50 +03:00
|
|
|
}
|
2011-01-04 20:33:58 +03:00
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
ExprResult
|
|
|
|
TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
|
|
|
|
// If E is not value-dependent, then nothing will change when we transform it.
|
|
|
|
// Note: This is an instantiation-centric view.
|
|
|
|
if (!E->isValueDependent())
|
|
|
|
return SemaRef.Owned(E);
|
|
|
|
|
|
|
|
// Note: None of the implementations of TryExpandParameterPacks can ever
|
|
|
|
// produce a diagnostic when given only a single unexpanded parameter pack,
|
|
|
|
// so
|
|
|
|
UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
|
|
|
|
bool ShouldExpand = false;
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
bool RetainExpansion = false;
|
2011-01-14 20:04:44 +03:00
|
|
|
llvm::Optional<unsigned> NumExpansions;
|
2011-01-04 20:33:58 +03:00
|
|
|
if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
|
|
|
|
&Unexpanded, 1,
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
ShouldExpand, RetainExpansion,
|
|
|
|
NumExpansions))
|
2011-01-04 20:33:58 +03:00
|
|
|
return ExprError();
|
|
|
|
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 10:32:04 +03:00
|
|
|
if (!ShouldExpand || RetainExpansion)
|
2011-01-04 20:33:58 +03:00
|
|
|
return SemaRef.Owned(E);
|
2011-01-03 20:17:50 +03:00
|
|
|
|
2011-01-04 20:33:58 +03:00
|
|
|
// We now know the length of the parameter pack, so build a new expression
|
|
|
|
// that stores that length.
|
|
|
|
return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
|
|
|
|
E->getPackLoc(), E->getRParenLoc(),
|
2011-01-14 20:04:44 +03:00
|
|
|
*NumExpansions);
|
2011-01-04 20:33:58 +03:00
|
|
|
}
|
|
|
|
|
2011-01-15 04:15:58 +03:00
|
|
|
template<typename Derived>
|
|
|
|
ExprResult
|
|
|
|
TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
|
|
|
|
SubstNonTypeTemplateParmPackExpr *E) {
|
|
|
|
// Default behavior is to do nothing with this transformation.
|
|
|
|
return SemaRef.Owned(E);
|
|
|
|
}
|
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
|
2010-04-20 19:39:42 +04:00
|
|
|
TypeSourceInfo *EncodedTypeInfo
|
|
|
|
= getDerived().TransformType(E->getEncodedTypeSourceInfo());
|
|
|
|
if (!EncodedTypeInfo)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
2010-04-20 19:39:42 +04:00
|
|
|
EncodedTypeInfo == E->getEncodedTypeSourceInfo())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
|
|
|
|
return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
|
2010-04-20 19:39:42 +04:00
|
|
|
EncodedTypeInfo,
|
2009-08-11 09:31:07 +04:00
|
|
|
E->getRParenLoc());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
|
2010-04-22 20:44:27 +04:00
|
|
|
// Transform arguments.
|
|
|
|
bool ArgChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> Args(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
Args.reserve(E->getNumArgs());
|
|
|
|
if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
|
|
|
|
&ArgChanged))
|
|
|
|
return ExprError();
|
|
|
|
|
2010-04-22 20:44:27 +04:00
|
|
|
if (E->getReceiverKind() == ObjCMessageExpr::Class) {
|
|
|
|
// Class message: transform the receiver type.
|
|
|
|
TypeSourceInfo *ReceiverTypeInfo
|
|
|
|
= getDerived().TransformType(E->getClassReceiverTypeInfo());
|
|
|
|
if (!ReceiverTypeInfo)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-22 20:44:27 +04:00
|
|
|
// If nothing changed, just retain the existing message send.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-04-22 20:44:27 +04:00
|
|
|
|
|
|
|
// Build a new class message send.
|
|
|
|
return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
|
|
|
|
E->getSelector(),
|
2010-12-10 23:08:27 +03:00
|
|
|
E->getSelectorLoc(),
|
2010-04-22 20:44:27 +04:00
|
|
|
E->getMethodDecl(),
|
|
|
|
E->getLeftLoc(),
|
|
|
|
move_arg(Args),
|
|
|
|
E->getRightLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instance message: transform the receiver
|
|
|
|
assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
|
|
|
|
"Only class and instance messages may be instantiated");
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Receiver
|
2010-04-22 20:44:27 +04:00
|
|
|
= getDerived().TransformExpr(E->getInstanceReceiver());
|
|
|
|
if (Receiver.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-04-22 20:44:27 +04:00
|
|
|
|
|
|
|
// If nothing changed, just retain the existing message send.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-22 20:44:27 +04:00
|
|
|
// Build a new instance message send.
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildObjCMessageExpr(Receiver.get(),
|
2010-04-22 20:44:27 +04:00
|
|
|
E->getSelector(),
|
2010-12-10 23:08:27 +03:00
|
|
|
E->getSelectorLoc(),
|
2010-04-22 20:44:27 +04:00
|
|
|
E->getMethodDecl(),
|
|
|
|
E->getLeftLoc(),
|
|
|
|
move_arg(Args),
|
|
|
|
E->getRightLoc());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
|
2010-04-27 00:11:03 +04:00
|
|
|
// Transform the base expression.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Base = getDerived().TransformExpr(E->getBase());
|
2010-04-27 00:11:03 +04:00
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-04-27 00:11:03 +04:00
|
|
|
|
|
|
|
// We don't need to transform the ivar; it will never change.
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 00:11:03 +04:00
|
|
|
// If nothing changed, just retain the existing expression.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Base.get() == E->getBase())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
|
2010-04-27 00:11:03 +04:00
|
|
|
E->getLocation(),
|
|
|
|
E->isArrow(), E->isFreeIvar());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
|
2010-12-02 04:19:52 +03:00
|
|
|
// 'super' and types never change. Property never changes. Just
|
|
|
|
// retain the existing expression.
|
|
|
|
if (!E->isObjectReceiver())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-10-14 20:04:05 +04:00
|
|
|
|
2010-04-27 00:47:02 +04:00
|
|
|
// Transform the base expression.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Base = getDerived().TransformExpr(E->getBase());
|
2010-04-27 00:47:02 +04:00
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 00:47:02 +04:00
|
|
|
// We don't need to transform the property; it will never change.
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 00:47:02 +04:00
|
|
|
// If nothing changed, just retain the existing expression.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Base.get() == E->getBase())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-08-11 09:31:07 +04:00
|
|
|
|
2010-12-02 04:19:52 +03:00
|
|
|
if (E->isExplicitProperty())
|
|
|
|
return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
|
|
|
|
E->getExplicitProperty(),
|
|
|
|
E->getLocation());
|
|
|
|
|
|
|
|
return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
|
|
|
|
E->getType(),
|
|
|
|
E->getImplicitPropertyGetter(),
|
|
|
|
E->getImplicitPropertySetter(),
|
|
|
|
E->getLocation());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
|
2010-04-27 00:11:03 +04:00
|
|
|
// Transform the base expression.
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Base = getDerived().TransformExpr(E->getBase());
|
2010-04-27 00:11:03 +04:00
|
|
|
if (Base.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-04-27 00:11:03 +04:00
|
|
|
// If nothing changed, just retain the existing expression.
|
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
Base.get() == E->getBase())
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
|
2010-04-27 00:11:03 +04:00
|
|
|
E->isArrow());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
|
2009-08-11 09:31:07 +04:00
|
|
|
bool ArgumentChanged = false;
|
2010-08-23 10:44:23 +04:00
|
|
|
ASTOwningVector<Expr*> SubExprs(SemaRef);
|
2011-01-03 22:04:46 +03:00
|
|
|
SubExprs.reserve(E->getNumSubExprs());
|
|
|
|
if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
|
|
|
|
SubExprs, &ArgumentChanged))
|
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
!ArgumentChanged)
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
|
|
|
|
move_arg(SubExprs),
|
|
|
|
E->getRParenLoc());
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
|
2010-07-09 22:44:02 +04:00
|
|
|
SourceLocation CaretLoc(E->getExprLoc());
|
|
|
|
|
|
|
|
SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
|
|
|
|
BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
|
|
|
|
CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
|
|
|
|
llvm::SmallVector<ParmVarDecl*, 4> Params;
|
|
|
|
llvm::SmallVector<QualType, 4> ParamTypes;
|
|
|
|
|
|
|
|
// Parameter substitution.
|
Implement substitution of a function parameter pack for its set of
instantiated function parameters, enabling instantiation of arbitrary
pack expansions involving function parameter packs. At this point, we
can now correctly compile a simple, variadic print() example:
#include <iostream>
#include <string>
void print() {}
template<typename Head, typename ...Tail>
void print(const Head &head, const Tail &...tail) {
std::cout << head;
print(tail...);
}
int main() {
std::string hello = "Hello";
print(hello, ", world!", " ", 2011, '\n');
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123000 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-07 19:43:16 +03:00
|
|
|
// FIXME: Variadic templates
|
2010-07-09 22:44:02 +04:00
|
|
|
const BlockDecl *BD = E->getBlockDecl();
|
|
|
|
for (BlockDecl::param_const_iterator P = BD->param_begin(),
|
|
|
|
EN = BD->param_end(); P != EN; ++P) {
|
|
|
|
ParmVarDecl *OldParm = (*P);
|
2011-01-15 01:40:04 +03:00
|
|
|
ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
|
|
|
|
llvm::Optional<unsigned>());
|
2010-07-09 22:44:02 +04:00
|
|
|
Params.push_back(NewParm);
|
|
|
|
ParamTypes.push_back(NewParm->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionType *BExprFunctionType = E->getFunctionType();
|
|
|
|
QualType BExprResultType = BExprFunctionType->getResultType();
|
|
|
|
if (!BExprResultType.isNull()) {
|
|
|
|
if (!BExprResultType->isDependentType())
|
|
|
|
CurBlock->ReturnType = BExprResultType;
|
|
|
|
else if (BExprResultType != SemaRef.Context.DependentTy)
|
|
|
|
CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
|
|
|
|
}
|
2011-01-05 15:14:39 +03:00
|
|
|
|
2010-07-09 22:44:02 +04:00
|
|
|
QualType FunctionType = getDerived().RebuildFunctionProtoType(
|
|
|
|
CurBlock->ReturnType,
|
|
|
|
ParamTypes.data(),
|
|
|
|
ParamTypes.size(),
|
|
|
|
BD->isVariadic(),
|
2010-08-05 06:54:05 +04:00
|
|
|
0,
|
|
|
|
BExprFunctionType->getExtInfo());
|
2010-07-09 22:44:02 +04:00
|
|
|
CurBlock->FunctionType = FunctionType;
|
2011-01-05 15:14:39 +03:00
|
|
|
|
|
|
|
// Set the parameters on the block decl.
|
|
|
|
if (!Params.empty())
|
|
|
|
CurBlock->TheDecl->setParams(Params.data(), Params.size());
|
|
|
|
|
|
|
|
// Transform the body
|
|
|
|
StmtResult Body = getDerived().TransformStmt(E->getBody());
|
|
|
|
if (Body.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-12-08 12:21:05 +03:00
|
|
|
TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
|
2010-07-09 22:44:02 +04:00
|
|
|
NestedNameSpecifier *Qualifier = 0;
|
|
|
|
|
|
|
|
ValueDecl *ND
|
|
|
|
= cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
|
|
|
|
E->getDecl()));
|
|
|
|
if (!ND)
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2010-08-12 02:01:17 +04:00
|
|
|
|
2010-07-09 22:44:02 +04:00
|
|
|
if (!getDerived().AlwaysRebuild() &&
|
|
|
|
ND == E->getDecl()) {
|
|
|
|
// Mark it referenced in the new context regardless.
|
|
|
|
// FIXME: this is a bit instantiation-specific.
|
|
|
|
SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
|
|
|
|
|
2010-10-26 11:05:15 +04:00
|
|
|
return SemaRef.Owned(E);
|
2010-07-09 22:44:02 +04:00
|
|
|
}
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
|
2010-07-09 22:44:02 +04:00
|
|
|
return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
|
2010-08-12 02:01:17 +04:00
|
|
|
ND, NameInfo, 0);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type reconstruction
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2009-10-30 03:06:24 +03:00
|
|
|
QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
|
|
|
|
SourceLocation Star) {
|
2010-06-05 10:41:15 +04:00
|
|
|
return SemaRef.BuildPointerType(PointeeType, Star,
|
2009-08-11 09:31:07 +04:00
|
|
|
getDerived().getBaseEntity());
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
2009-10-30 03:06:24 +03:00
|
|
|
QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
|
|
|
|
SourceLocation Star) {
|
2010-06-05 10:41:15 +04:00
|
|
|
return SemaRef.BuildBlockPointerType(PointeeType, Star,
|
2009-08-11 09:31:07 +04:00
|
|
|
getDerived().getBaseEntity());
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
2009-10-30 03:06:24 +03:00
|
|
|
TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
|
|
|
|
bool WrittenAsLValue,
|
|
|
|
SourceLocation Sigil) {
|
2010-06-05 10:41:15 +04:00
|
|
|
return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
|
2009-10-30 03:06:24 +03:00
|
|
|
Sigil, getDerived().getBaseEntity());
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType
|
2009-10-30 03:06:24 +03:00
|
|
|
TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
|
|
|
|
QualType ClassType,
|
|
|
|
SourceLocation Sigil) {
|
2010-06-05 10:41:15 +04:00
|
|
|
return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
|
2009-10-30 03:06:24 +03:00
|
|
|
Sigil, getDerived().getBaseEntity());
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType
|
2009-08-04 20:50:30 +04:00
|
|
|
TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
|
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
|
|
|
const llvm::APInt *Size,
|
|
|
|
Expr *SizeExpr,
|
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange) {
|
|
|
|
if (SizeExpr || !Size)
|
|
|
|
return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
|
|
|
|
IndexTypeQuals, BracketsRange,
|
|
|
|
getDerived().getBaseEntity());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
QualType Types[] = {
|
|
|
|
SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
|
|
|
|
SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
|
|
|
|
SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
|
2009-08-04 20:50:30 +04:00
|
|
|
};
|
|
|
|
const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
|
|
|
|
QualType SizeType;
|
|
|
|
for (unsigned I = 0; I != NumTypes; ++I)
|
|
|
|
if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
|
|
|
|
SizeType = Types[I];
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-28 13:06:06 +04:00
|
|
|
IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
|
|
|
|
/*FIXME*/BracketsRange.getBegin());
|
2009-09-09 19:08:12 +04:00
|
|
|
return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
|
2009-08-04 20:50:30 +04:00
|
|
|
IndexTypeQuals, BracketsRange,
|
2009-09-09 19:08:12 +04:00
|
|
|
getDerived().getBaseEntity());
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
|
2009-08-04 20:50:30 +04:00
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
|
|
|
const llvm::APInt &Size,
|
2009-10-30 03:06:24 +03:00
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange) {
|
2009-09-09 19:08:12 +04:00
|
|
|
return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
|
2009-10-30 03:06:24 +03:00
|
|
|
IndexTypeQuals, BracketsRange);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
|
2009-08-04 20:50:30 +04:00
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
2009-10-30 03:06:24 +03:00
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange) {
|
2009-09-09 19:08:12 +04:00
|
|
|
return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
|
2009-10-30 03:06:24 +03:00
|
|
|
IndexTypeQuals, BracketsRange);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
|
2009-08-04 20:50:30 +04:00
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SizeExpr,
|
2009-08-04 20:50:30 +04:00
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange) {
|
2009-09-09 19:08:12 +04:00
|
|
|
return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
|
2010-08-24 03:25:46 +04:00
|
|
|
SizeExpr,
|
2009-08-04 20:50:30 +04:00
|
|
|
IndexTypeQuals, BracketsRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
|
2009-08-04 20:50:30 +04:00
|
|
|
ArrayType::ArraySizeModifier SizeMod,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SizeExpr,
|
2009-08-04 20:50:30 +04:00
|
|
|
unsigned IndexTypeQuals,
|
|
|
|
SourceRange BracketsRange) {
|
2009-09-09 19:08:12 +04:00
|
|
|
return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
|
2010-08-24 03:25:46 +04:00
|
|
|
SizeExpr,
|
2009-08-04 20:50:30 +04:00
|
|
|
IndexTypeQuals, BracketsRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
|
2010-11-11 00:56:12 +03:00
|
|
|
unsigned NumElements,
|
|
|
|
VectorType::VectorKind VecKind) {
|
2009-08-04 20:50:30 +04:00
|
|
|
// FIXME: semantic checking!
|
2010-11-11 00:56:12 +03:00
|
|
|
return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
|
|
|
|
unsigned NumElements,
|
|
|
|
SourceLocation AttributeLoc) {
|
|
|
|
llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
|
|
|
|
NumElements, true);
|
|
|
|
IntegerLiteral *VectorSize
|
2010-08-28 13:06:06 +04:00
|
|
|
= IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
|
|
|
|
AttributeLoc);
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType
|
|
|
|
TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *SizeExpr,
|
2009-08-04 20:50:30 +04:00
|
|
|
SourceLocation AttributeLoc) {
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType *ParamTypes,
|
2009-08-04 20:50:30 +04:00
|
|
|
unsigned NumParamTypes,
|
2009-09-09 19:08:12 +04:00
|
|
|
bool Variadic,
|
2010-08-05 06:54:05 +04:00
|
|
|
unsigned Quals,
|
|
|
|
const FunctionType::ExtInfo &Info) {
|
2009-09-09 19:08:12 +04:00
|
|
|
return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
|
2009-08-04 20:50:30 +04:00
|
|
|
Quals,
|
|
|
|
getDerived().getBaseLocation(),
|
2010-08-05 06:54:05 +04:00
|
|
|
getDerived().getBaseEntity(),
|
|
|
|
Info);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-21 04:40:46 +04:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
|
|
|
|
return SemaRef.Context.getFunctionNoProtoType(T);
|
|
|
|
}
|
|
|
|
|
2009-12-05 01:46:56 +03:00
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
|
|
|
|
assert(D && "no decl found");
|
|
|
|
if (D->isInvalidDecl()) return QualType();
|
|
|
|
|
2010-04-22 20:44:27 +04:00
|
|
|
// FIXME: Doesn't account for ObjCInterfaceDecl!
|
2009-12-05 01:46:56 +03:00
|
|
|
TypeDecl *Ty;
|
|
|
|
if (isa<UsingDecl>(D)) {
|
|
|
|
UsingDecl *Using = cast<UsingDecl>(D);
|
|
|
|
assert(Using->isTypeName() &&
|
|
|
|
"UnresolvedUsingTypenameDecl transformed to non-typename using");
|
|
|
|
|
|
|
|
// A valid resolved using typename decl points to exactly one type decl.
|
|
|
|
assert(++Using->shadow_begin() == Using->shadow_end());
|
|
|
|
Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-12-05 01:46:56 +03:00
|
|
|
} else {
|
|
|
|
assert(isa<UnresolvedUsingTypenameDecl>(D) &&
|
|
|
|
"UnresolvedUsingTypenameDecl transformed to non-using decl");
|
|
|
|
Ty = cast<UnresolvedUsingTypenameDecl>(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SemaRef.Context.getTypeDeclType(Ty);
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
template<typename Derived>
|
2010-10-12 04:20:44 +04:00
|
|
|
QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
|
|
|
|
SourceLocation Loc) {
|
|
|
|
return SemaRef.BuildTypeofExprType(E, Loc);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
|
|
|
|
return SemaRef.Context.getTypeOfType(Underlying);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-10-12 04:20:44 +04:00
|
|
|
QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
|
|
|
|
SourceLocation Loc) {
|
|
|
|
return SemaRef.BuildDecltypeType(E, Loc);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
|
2009-10-29 11:12:44 +03:00
|
|
|
TemplateName Template,
|
|
|
|
SourceLocation TemplateNameLoc,
|
2009-11-23 04:53:49 +03:00
|
|
|
const TemplateArgumentListInfo &TemplateArgs) {
|
|
|
|
return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
|
2009-08-04 20:50:30 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
template<typename Derived>
|
|
|
|
NestedNameSpecifier *
|
|
|
|
TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
|
|
|
|
SourceRange Range,
|
2009-09-03 20:14:30 +04:00
|
|
|
IdentifierInfo &II,
|
2009-09-04 01:38:09 +04:00
|
|
|
QualType ObjectType,
|
2009-11-23 04:53:49 +03:00
|
|
|
NamedDecl *FirstQualifierInScope) {
|
2009-08-06 09:28:30 +04:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
// FIXME: The source location information is all wrong.
|
|
|
|
SS.setRange(Range);
|
|
|
|
SS.setScopeRep(Prefix);
|
|
|
|
return static_cast<NestedNameSpecifier *>(
|
2009-09-09 19:08:12 +04:00
|
|
|
SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
|
Improve support for out-of-line definitions of nested templates and
their members, including member class template, member function
templates, and member classes and functions of member templates.
To actually parse the nested-name-specifiers that qualify the name of
an out-of-line definition of a member template, e.g.,
template<typename X> template<typename Y>
X Outer<X>::Inner1<Y>::foo(Y) {
return X();
}
we need to look for the template names (e.g., "Inner1") as a member of
the current instantiation (Outer<X>), even before we have entered the
scope of the current instantiation. Since we can't do this in general
(i.e., we should not be looking into all dependent
nested-name-specifiers as if they were the current instantiation), we
rely on the parser to tell us when it is parsing a declaration
specifier sequence, and, therefore, when we should consider the
current scope specifier to be a current instantiation.
Printing of complicated, dependent nested-name-specifiers may be
somewhat broken by this commit; I'll add tests for this issue and fix
the problem (if it still exists) in a subsequent commit.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80044 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-26 02:51:20 +04:00
|
|
|
Range.getEnd(), II,
|
2009-09-04 01:38:09 +04:00
|
|
|
ObjectType,
|
|
|
|
FirstQualifierInScope,
|
2009-12-07 04:36:53 +03:00
|
|
|
false, false));
|
2009-08-06 09:28:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
NestedNameSpecifier *
|
|
|
|
TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
|
|
|
|
SourceRange Range,
|
|
|
|
NamespaceDecl *NS) {
|
|
|
|
return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
NestedNameSpecifier *
|
|
|
|
TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
|
|
|
|
SourceRange Range,
|
|
|
|
bool TemplateKW,
|
2010-02-25 07:46:04 +03:00
|
|
|
QualType T) {
|
|
|
|
if (T->isDependentType() || T->isRecordType() ||
|
2009-08-06 09:28:30 +04:00
|
|
|
(SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
|
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88969 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-17 00:35:15 +03:00
|
|
|
assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
|
2009-08-06 09:28:30 +04:00
|
|
|
return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
|
|
|
|
T.getTypePtr());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 09:28:30 +04:00
|
|
|
SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-06 10:41:21 +04:00
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
TemplateName
|
2009-08-06 10:41:21 +04:00
|
|
|
TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
|
|
|
|
bool TemplateKW,
|
|
|
|
TemplateDecl *Template) {
|
2009-09-09 19:08:12 +04:00
|
|
|
return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
|
2009-08-06 10:41:21 +04:00
|
|
|
Template);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2009-09-09 19:08:12 +04:00
|
|
|
TemplateName
|
2009-08-06 10:41:21 +04:00
|
|
|
TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
|
2010-09-09 03:56:00 +04:00
|
|
|
SourceRange QualifierRange,
|
2009-09-09 04:23:06 +04:00
|
|
|
const IdentifierInfo &II,
|
2010-11-12 11:19:04 +03:00
|
|
|
QualType ObjectType,
|
|
|
|
NamedDecl *FirstQualifierInScope) {
|
2009-08-06 10:41:21 +04:00
|
|
|
CXXScopeSpec SS;
|
2010-09-09 03:56:00 +04:00
|
|
|
SS.setRange(QualifierRange);
|
2009-09-09 19:08:12 +04:00
|
|
|
SS.setScopeRep(Qualifier);
|
2009-11-04 02:16:33 +03:00
|
|
|
UnqualifiedId Name;
|
|
|
|
Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
|
2010-06-17 03:00:59 +04:00
|
|
|
Sema::TemplateTy Template;
|
|
|
|
getSema().ActOnDependentTemplateName(/*Scope=*/0,
|
|
|
|
/*FIXME:*/getDerived().getBaseLocation(),
|
|
|
|
SS,
|
|
|
|
Name,
|
2010-08-24 09:47:05 +04:00
|
|
|
ParsedType::make(ObjectType),
|
2010-06-17 03:00:59 +04:00
|
|
|
/*EnteringContext=*/false,
|
|
|
|
Template);
|
2010-11-12 11:19:04 +03:00
|
|
|
return Template.get();
|
2009-08-06 10:41:21 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-04 03:56:37 +03:00
|
|
|
template<typename Derived>
|
|
|
|
TemplateName
|
|
|
|
TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
|
|
|
|
OverloadedOperatorKind Operator,
|
|
|
|
QualType ObjectType) {
|
|
|
|
CXXScopeSpec SS;
|
|
|
|
SS.setRange(SourceRange(getDerived().getBaseLocation()));
|
|
|
|
SS.setScopeRep(Qualifier);
|
|
|
|
UnqualifiedId Name;
|
|
|
|
SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
|
|
|
|
Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
|
|
|
|
Operator, SymbolLocations);
|
2010-06-17 03:00:59 +04:00
|
|
|
Sema::TemplateTy Template;
|
|
|
|
getSema().ActOnDependentTemplateName(/*Scope=*/0,
|
2009-11-04 03:56:37 +03:00
|
|
|
/*FIXME:*/getDerived().getBaseLocation(),
|
2010-06-17 03:00:59 +04:00
|
|
|
SS,
|
|
|
|
Name,
|
2010-08-24 09:47:05 +04:00
|
|
|
ParsedType::make(ObjectType),
|
2010-06-17 03:00:59 +04:00
|
|
|
/*EnteringContext=*/false,
|
|
|
|
Template);
|
|
|
|
return Template.template getAsVal<TemplateName>();
|
2009-11-04 03:56:37 +03:00
|
|
|
}
|
2010-05-05 19:23:54 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2009-08-11 09:31:07 +04:00
|
|
|
TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
|
|
|
|
SourceLocation OpLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *OrigCallee,
|
|
|
|
Expr *First,
|
|
|
|
Expr *Second) {
|
|
|
|
Expr *Callee = OrigCallee->IgnoreParenCasts();
|
|
|
|
bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// Determine whether this should be a builtin operation.
|
2009-10-29 23:17:01 +03:00
|
|
|
if (Op == OO_Subscript) {
|
2010-08-24 03:25:46 +04:00
|
|
|
if (!First->getType()->isOverloadableType() &&
|
|
|
|
!Second->getType()->isOverloadableType())
|
|
|
|
return getSema().CreateBuiltinArraySubscriptExpr(First,
|
|
|
|
Callee->getLocStart(),
|
|
|
|
Second, OpLoc);
|
2009-11-16 22:13:03 +03:00
|
|
|
} else if (Op == OO_Arrow) {
|
|
|
|
// -> is never a builtin operation.
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
|
|
|
|
} else if (Second == 0 || isPostIncDec) {
|
|
|
|
if (!First->getType()->isOverloadableType()) {
|
2009-08-11 09:31:07 +04:00
|
|
|
// The argument is not of overloadable type, so try to create a
|
|
|
|
// built-in unary operation.
|
2010-08-25 15:45:40 +04:00
|
|
|
UnaryOperatorKind Opc
|
2009-08-11 09:31:07 +04:00
|
|
|
= UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
|
|
|
} else {
|
2010-08-24 03:25:46 +04:00
|
|
|
if (!First->getType()->isOverloadableType() &&
|
|
|
|
!Second->getType()->isOverloadableType()) {
|
2009-08-11 09:31:07 +04:00
|
|
|
// Neither of the arguments is an overloadable type, so try to
|
|
|
|
// create a built-in binary operation.
|
2010-08-25 15:45:40 +04:00
|
|
|
BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result
|
2010-08-24 03:25:46 +04:00
|
|
|
= SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
|
2009-08-11 09:31:07 +04:00
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
return move(Result);
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
// Compute the transformed set of functions (and function templates) to be
|
2009-08-11 09:31:07 +04:00
|
|
|
// used during overload resolution.
|
2010-01-26 06:27:55 +03:00
|
|
|
UnresolvedSet<16> Functions;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
|
2009-11-21 11:51:07 +03:00
|
|
|
assert(ULE->requiresADL());
|
|
|
|
|
|
|
|
// FIXME: Do we have to check
|
|
|
|
// IsAcceptableNonMemberOperatorCandidate for each of these?
|
2010-01-26 06:27:55 +03:00
|
|
|
Functions.append(ULE->decls_begin(), ULE->decls_end());
|
2009-11-21 11:51:07 +03:00
|
|
|
} else {
|
2010-08-24 03:25:46 +04:00
|
|
|
Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
|
2009-11-21 11:51:07 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// Add any functions found via argument-dependent lookup.
|
2010-08-24 03:25:46 +04:00
|
|
|
Expr *Args[2] = { First, Second };
|
|
|
|
unsigned NumArgs = 1 + (Second != 0);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// Create the overloaded operator invocation for unary operators.
|
|
|
|
if (NumArgs == 1 || isPostIncDec) {
|
2010-08-25 15:45:40 +04:00
|
|
|
UnaryOperatorKind Opc
|
2009-08-11 09:31:07 +04:00
|
|
|
= UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-29 23:17:01 +03:00
|
|
|
if (Op == OO_Subscript)
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
|
2009-11-21 11:51:07 +03:00
|
|
|
OpLoc,
|
2010-08-24 03:25:46 +04:00
|
|
|
First,
|
|
|
|
Second);
|
2009-10-29 23:17:01 +03:00
|
|
|
|
2009-08-11 09:31:07 +04:00
|
|
|
// Create the overloaded operator invocation for binary operators.
|
2010-08-25 15:45:40 +04:00
|
|
|
BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult Result
|
2009-08-11 09:31:07 +04:00
|
|
|
= SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
|
|
|
|
if (Result.isInvalid())
|
2010-08-27 03:41:50 +04:00
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
return move(Result);
|
2009-08-11 09:31:07 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-02-25 02:40:28 +03:00
|
|
|
template<typename Derived>
|
2010-08-24 10:29:42 +04:00
|
|
|
ExprResult
|
2010-08-24 03:25:46 +04:00
|
|
|
TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
|
2010-02-25 02:40:28 +03:00
|
|
|
SourceLocation OperatorLoc,
|
|
|
|
bool isArrow,
|
|
|
|
NestedNameSpecifier *Qualifier,
|
|
|
|
SourceRange QualifierRange,
|
|
|
|
TypeSourceInfo *ScopeType,
|
|
|
|
SourceLocation CCLoc,
|
2010-02-25 02:50:37 +03:00
|
|
|
SourceLocation TildeLoc,
|
2010-02-25 04:56:36 +03:00
|
|
|
PseudoDestructorTypeStorage Destroyed) {
|
2010-02-25 02:40:28 +03:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
if (Qualifier) {
|
|
|
|
SS.setRange(QualifierRange);
|
|
|
|
SS.setScopeRep(Qualifier);
|
|
|
|
}
|
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
QualType BaseType = Base->getType();
|
|
|
|
if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
|
2010-02-25 02:40:28 +03:00
|
|
|
(!isArrow && !BaseType->getAs<RecordType>()) ||
|
2010-05-05 19:23:54 +04:00
|
|
|
(isArrow && BaseType->getAs<PointerType>() &&
|
2010-02-25 16:04:33 +03:00
|
|
|
!BaseType->getAs<PointerType>()->getPointeeType()
|
|
|
|
->template getAs<RecordType>())){
|
2010-02-25 02:40:28 +03:00
|
|
|
// This pseudo-destructor expression is still a pseudo-destructor.
|
2010-08-24 03:25:46 +04:00
|
|
|
return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
|
2010-02-25 02:40:28 +03:00
|
|
|
isArrow? tok::arrow : tok::period,
|
2010-02-25 02:50:37 +03:00
|
|
|
SS, ScopeType, CCLoc, TildeLoc,
|
2010-02-25 04:56:36 +03:00
|
|
|
Destroyed,
|
2010-02-25 02:40:28 +03:00
|
|
|
/*FIXME?*/true);
|
|
|
|
}
|
2010-08-12 02:01:17 +04:00
|
|
|
|
2010-02-25 04:56:36 +03:00
|
|
|
TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
|
|
|
|
SemaRef.Context.getCanonicalType(DestroyedType->getType())));
|
|
|
|
DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
|
|
|
|
NameInfo.setNamedTypeInfo(DestroyedType);
|
|
|
|
|
2010-02-25 02:40:28 +03:00
|
|
|
// FIXME: the ScopeType should be tacked onto SS.
|
2010-08-12 02:01:17 +04:00
|
|
|
|
2010-08-24 03:25:46 +04:00
|
|
|
return getSema().BuildMemberReferenceExpr(Base, BaseType,
|
2010-02-25 02:40:28 +03:00
|
|
|
OperatorLoc, isArrow,
|
|
|
|
SS, /*FIXME: FirstQualifier*/ 0,
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo,
|
2010-02-25 02:40:28 +03:00
|
|
|
/*TemplateArgs*/ 0);
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:50:30 +04:00
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
|