Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 16 | |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "TypeLocBuilder.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
| 23 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 24 | #include "clang/AST/Stmt.h" |
| 25 | #include "clang/AST/StmtCXX.h" |
| 26 | #include "clang/AST/StmtObjC.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/AST/StmtOpenMP.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Designator.h" |
| 29 | #include "clang/Sema/Lookup.h" |
| 30 | #include "clang/Sema/Ownership.h" |
| 31 | #include "clang/Sema/ParsedTemplate.h" |
| 32 | #include "clang/Sema/ScopeInfo.h" |
| 33 | #include "clang/Sema/SemaDiagnostic.h" |
| 34 | #include "clang/Sema/SemaInternal.h" |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/ArrayRef.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 36 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 37 | #include <algorithm> |
| 38 | |
| 39 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 40 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 42 | /// \brief A semantic tree transformation that allows one to transform one |
| 43 | /// abstract syntax tree into another. |
| 44 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 46 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 47 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 48 | /// instantiation is implemented as a tree transformation where the |
| 49 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 50 | /// template arguments for their corresponding template parameters; a similar |
| 51 | /// transformation is performed for non-type template parameters and |
| 52 | /// template template parameters. |
| 53 | /// |
| 54 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 56 | /// override any of the transformation or rebuild operators by providing an |
| 57 | /// operation with the same signature as the default implementation. The |
| 58 | /// overridding function should not be virtual. |
| 59 | /// |
| 60 | /// Semantic tree transformations are split into two stages, either of which |
| 61 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 62 | /// or the parts of an AST node using the various transformation functions, |
| 63 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 64 | /// node of the appropriate kind from the pieces. The default transformation |
| 65 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 66 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 67 | /// were changed by the transformation, invokes the rebuild operation to create |
| 68 | /// a new AST node. |
| 69 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 71 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 72 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 73 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 74 | /// new implementations. |
| 75 | /// |
| 76 | /// For more fine-grained transformations, subclasses can replace any of the |
| 77 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 78 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 79 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 81 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 82 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 83 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 84 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 85 | /// be able to use more efficient rebuild steps. |
| 86 | /// |
| 87 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 89 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 90 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 91 | /// default locations and entity names used for type-checking |
| 92 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 93 | template<typename Derived> |
| 94 | class TreeTransform { |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 95 | /// \brief Private RAII object that helps us forget and then re-remember |
| 96 | /// the template argument corresponding to a partially-substituted parameter |
| 97 | /// pack. |
| 98 | class ForgetPartiallySubstitutedPackRAII { |
| 99 | Derived &Self; |
| 100 | TemplateArgument Old; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 102 | public: |
| 103 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 104 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 105 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 106 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 107 | ~ForgetPartiallySubstitutedPackRAII() { |
| 108 | Self.RememberPartiallySubstitutedPack(Old); |
| 109 | } |
| 110 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 111 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 112 | protected: |
| 113 | Sema &SemaRef; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 115 | /// \brief The set of local declarations that have been transformed, for |
| 116 | /// cases where we are forced to build new declarations within the transformer |
| 117 | /// rather than in the subclass (e.g., lambda closure types). |
| 118 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 119 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 121 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 122 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 124 | /// \brief Retrieves a reference to the derived class. |
| 125 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 126 | |
| 127 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | const Derived &getDerived() const { |
| 129 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | } |
| 131 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 132 | static inline ExprResult Owned(Expr *E) { return E; } |
| 133 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 134 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 135 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 136 | /// this tree transform. |
| 137 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 139 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 140 | /// if none of the children have changed. |
| 141 | /// |
| 142 | /// Subclasses may override this function to specify when the transformation |
| 143 | /// should rebuild all AST nodes. |
Richard Smith | 2aa81a7 | 2013-11-07 20:07:17 +0000 | [diff] [blame] | 144 | /// |
| 145 | /// We must always rebuild all AST nodes when performing variadic template |
| 146 | /// pack expansion, in order to avoid violating the AST invariant that each |
| 147 | /// statement node appears at most once in its containing declaration. |
| 148 | bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 150 | /// \brief Returns the location of the entity being transformed, if that |
| 151 | /// information was not available elsewhere in the AST. |
| 152 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 154 | /// provide an alternative implementation that provides better location |
| 155 | /// information. |
| 156 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 158 | /// \brief Returns the name of the entity being transformed, if that |
| 159 | /// information was not available elsewhere in the AST. |
| 160 | /// |
| 161 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 162 | /// implementation with a more precise name. |
| 163 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 164 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 165 | /// \brief Sets the "base" location and entity when that |
| 166 | /// information is known based on another transformation. |
| 167 | /// |
| 168 | /// By default, the source location and entity are ignored. Subclasses can |
| 169 | /// override this function to provide a customized implementation. |
| 170 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 172 | /// \brief RAII object that temporarily sets the base location and entity |
| 173 | /// used for reporting diagnostics in types. |
| 174 | class TemporaryBase { |
| 175 | TreeTransform &Self; |
| 176 | SourceLocation OldLocation; |
| 177 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 179 | public: |
| 180 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 182 | OldLocation = Self.getDerived().getBaseLocation(); |
| 183 | OldEntity = Self.getDerived().getBaseEntity(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 184 | |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 185 | if (Location.isValid()) |
| 186 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 187 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 189 | ~TemporaryBase() { |
| 190 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 191 | } |
| 192 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | |
| 194 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 195 | /// transformed. |
| 196 | /// |
| 197 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 198 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 199 | /// not change. For example, template instantiation need not traverse |
| 200 | /// non-dependent types. |
| 201 | bool AlreadyTransformed(QualType T) { |
| 202 | return T.isNull(); |
| 203 | } |
| 204 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 205 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 206 | /// because it is a default argument. |
| 207 | /// |
| 208 | /// Subclasses can provide an alternative implementation of this routine to |
| 209 | /// determine which kinds of call arguments get dropped. By default, |
| 210 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 211 | bool DropCallArgument(Expr *E) { |
| 212 | return E->isDefaultArgument(); |
| 213 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 214 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 215 | /// \brief Determine whether we should expand a pack expansion with the |
| 216 | /// given set of parameter packs into separate arguments by repeatedly |
| 217 | /// transforming the pattern. |
| 218 | /// |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 219 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 220 | /// Subclasses can override this routine to provide different behavior. |
| 221 | /// |
| 222 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 223 | /// pack expansion. |
| 224 | /// |
| 225 | /// \param PatternRange The source range that covers the entire pattern of |
| 226 | /// the pack expansion. |
| 227 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 228 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 229 | /// pattern. |
| 230 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 231 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 232 | /// expand the corresponding pack expansions into separate arguments. When |
| 233 | /// set, \c NumExpansions must also be set. |
| 234 | /// |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 235 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 236 | /// pack expansion after all of the expanded arguments. This is used |
| 237 | /// when extending explicitly-specified template argument packs per |
| 238 | /// C++0x [temp.arg.explicit]p9. |
| 239 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 240 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 241 | /// the expanded form of the corresponding pack expansion. This is both an |
| 242 | /// input and an output parameter, which can be set by the caller if the |
| 243 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 244 | /// and will be set by the callee when the number of expansions is known. |
| 245 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 246 | /// set this value in other cases. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 247 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 248 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 249 | /// are to be instantiated with arguments of different lengths), false |
| 250 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 251 | /// must be set. |
| 252 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 253 | SourceRange PatternRange, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 254 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 255 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 256 | bool &RetainExpansion, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 257 | Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 258 | ShouldExpand = false; |
| 259 | return false; |
| 260 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 261 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 262 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 263 | /// when performing an instantiation that must preserve the parameter pack |
| 264 | /// use. |
| 265 | /// |
| 266 | /// This routine is meant to be overridden by the template instantiator. |
| 267 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 268 | return TemplateArgument(); |
| 269 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 270 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 271 | /// \brief "Remember" the partially-substituted pack template argument |
| 272 | /// after performing an instantiation that must preserve the parameter pack |
| 273 | /// use. |
| 274 | /// |
| 275 | /// This routine is meant to be overridden by the template instantiator. |
| 276 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 277 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 278 | /// \brief Note to the derived class when a function parameter pack is |
| 279 | /// being expanded. |
| 280 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 281 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 282 | /// \brief Transforms the given type into another type. |
| 283 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 284 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 285 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 286 | /// function. This is expensive, but we don't mind, because |
| 287 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 288 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 289 | /// |
| 290 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 291 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 293 | /// \brief Transforms the given type-with-location into a new |
| 294 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 295 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 296 | /// By default, this routine transforms a type by delegating to the |
| 297 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 298 | /// may override this function (to take over all type |
| 299 | /// transformations) or some set of the TransformXXXType functions |
| 300 | /// to alter the transformation. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 301 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 302 | |
| 303 | /// \brief Transform the given type-with-location into a new |
| 304 | /// type, collecting location information in the given builder |
| 305 | /// as necessary. |
| 306 | /// |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 307 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 309 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 310 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 312 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 313 | /// statement or the TransformExpr() function to transform an expression. |
| 314 | /// Subclasses may override this function to transform statements using some |
| 315 | /// other mechanism. |
| 316 | /// |
| 317 | /// \returns the transformed statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 318 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 320 | /// \brief Transform the given statement. |
| 321 | /// |
| 322 | /// By default, this routine transforms a statement by delegating to the |
| 323 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 324 | /// of clause. Subclasses may override this function to transform statements |
| 325 | /// using some other mechanism. |
| 326 | /// |
| 327 | /// \returns the transformed OpenMP clause. |
| 328 | OMPClause *TransformOMPClause(OMPClause *S); |
| 329 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 330 | /// \brief Transform the given expression. |
| 331 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 332 | /// By default, this routine transforms an expression by delegating to the |
| 333 | /// appropriate TransformXXXExpr function to build a new expression. |
| 334 | /// Subclasses may override this function to transform expressions using some |
| 335 | /// other mechanism. |
| 336 | /// |
| 337 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 338 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 339 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 340 | /// \brief Transform the given initializer. |
| 341 | /// |
| 342 | /// By default, this routine transforms an initializer by stripping off the |
| 343 | /// semantic nodes added by initialization, then passing the result to |
| 344 | /// TransformExpr or TransformExprs. |
| 345 | /// |
| 346 | /// \returns the transformed initializer. |
| 347 | ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit); |
| 348 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 349 | /// \brief Transform the given list of expressions. |
| 350 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 351 | /// This routine transforms a list of expressions by invoking |
| 352 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 353 | /// support for variadic templates by expanding any pack expansions (if the |
| 354 | /// derived class permits such expansion) along the way. When pack expansions |
| 355 | /// are present, the number of outputs may not equal the number of inputs. |
| 356 | /// |
| 357 | /// \param Inputs The set of expressions to be transformed. |
| 358 | /// |
| 359 | /// \param NumInputs The number of expressions in \c Inputs. |
| 360 | /// |
| 361 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 362 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 363 | /// be. |
| 364 | /// |
| 365 | /// \param Outputs The transformed input expressions will be added to this |
| 366 | /// vector. |
| 367 | /// |
| 368 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 369 | /// due to transformation. |
| 370 | /// |
| 371 | /// \returns true if an error occurred, false otherwise. |
| 372 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 373 | SmallVectorImpl<Expr *> &Outputs, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 374 | bool *ArgChanged = nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 375 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 376 | /// \brief Transform the given declaration, which is referenced from a type |
| 377 | /// or expression. |
| 378 | /// |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 379 | /// By default, acts as the identity function on declarations, unless the |
| 380 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 381 | /// may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 382 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 383 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 384 | = TransformedLocalDecls.find(D); |
| 385 | if (Known != TransformedLocalDecls.end()) |
| 386 | return Known->second; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 387 | |
| 388 | return D; |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 389 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 390 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 391 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 392 | /// place them on the new declaration. |
| 393 | /// |
| 394 | /// By default, this operation does nothing. Subclasses may override this |
| 395 | /// behavior to transform attributes. |
| 396 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 397 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 398 | /// \brief Note that a local declaration has been transformed by this |
| 399 | /// transformer. |
| 400 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 401 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 402 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 403 | /// the transformer itself has to transform the declarations. This routine |
| 404 | /// can be overridden by a subclass that keeps track of such mappings. |
| 405 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 406 | TransformedLocalDecls[Old] = New; |
| 407 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 408 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 409 | /// \brief Transform the definition of the given declaration. |
| 410 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 412 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 413 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 414 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 417 | /// \brief Transform the given declaration, which was the first part of a |
| 418 | /// nested-name-specifier in a member access expression. |
| 419 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 420 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 421 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 422 | /// the \c T in \c x->T::member |
| 423 | /// |
| 424 | /// By default, invokes TransformDecl() to transform the declaration. |
| 425 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 426 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 427 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 428 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 429 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 430 | /// \brief Transform the given nested-name-specifier with source-location |
| 431 | /// information. |
| 432 | /// |
| 433 | /// By default, transforms all of the types and declarations within the |
| 434 | /// nested-name-specifier. Subclasses may override this function to provide |
| 435 | /// alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 436 | NestedNameSpecifierLoc |
| 437 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 438 | QualType ObjectType = QualType(), |
| 439 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 440 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 441 | /// \brief Transform the given declaration name. |
| 442 | /// |
| 443 | /// By default, transforms the types of conversion function, constructor, |
| 444 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 445 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 446 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 447 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 448 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 451 | /// |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 452 | /// \param SS The nested-name-specifier that qualifies the template |
| 453 | /// name. This nested-name-specifier must already have been transformed. |
| 454 | /// |
| 455 | /// \param Name The template name to transform. |
| 456 | /// |
| 457 | /// \param NameLoc The source location of the template name. |
| 458 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 459 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 460 | /// access expression, this is the type of the object whose member template |
| 461 | /// is being referenced. |
| 462 | /// |
| 463 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 464 | /// also refers to a name within the current (lexical) scope, this is the |
| 465 | /// declaration it refers to. |
| 466 | /// |
| 467 | /// By default, transforms the template name by transforming the declarations |
| 468 | /// and nested-name-specifiers that occur within the template name. |
| 469 | /// Subclasses may override this function to provide alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 470 | TemplateName |
| 471 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 472 | SourceLocation NameLoc, |
| 473 | QualType ObjectType = QualType(), |
| 474 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 475 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 476 | /// \brief Transform the given template argument. |
| 477 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 478 | /// By default, this operation transforms the type, expression, or |
| 479 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 480 | /// new template argument from the transformed result. Subclasses may |
| 481 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 482 | /// |
| 483 | /// Returns true if there was an error. |
| 484 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 485 | TemplateArgumentLoc &Output); |
| 486 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 487 | /// \brief Transform the given set of template arguments. |
| 488 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 489 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 490 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 491 | /// the transformed arguments to the output list. |
| 492 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 493 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 494 | /// a convenience function. Subclasses that wish to override this behavior |
| 495 | /// should override the iterator-based member template version. |
| 496 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 497 | /// \param Inputs The set of template arguments to be transformed. |
| 498 | /// |
| 499 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 500 | /// |
| 501 | /// \param Outputs The set of transformed template arguments output by this |
| 502 | /// routine. |
| 503 | /// |
| 504 | /// Returns true if an error occurred. |
| 505 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 506 | unsigned NumInputs, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 507 | TemplateArgumentListInfo &Outputs) { |
| 508 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 509 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 510 | |
| 511 | /// \brief Transform the given set of template arguments. |
| 512 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 513 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 514 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 515 | /// the transformed arguments to the output list. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 516 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 517 | /// \param First An iterator to the first template argument. |
| 518 | /// |
| 519 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 520 | /// |
| 521 | /// \param Outputs The set of transformed template arguments output by this |
| 522 | /// routine. |
| 523 | /// |
| 524 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 525 | template<typename InputIterator> |
| 526 | bool TransformTemplateArguments(InputIterator First, |
| 527 | InputIterator Last, |
| 528 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 529 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 530 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 531 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 532 | TemplateArgumentLoc &ArgLoc); |
| 533 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 534 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 535 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 536 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 537 | getDerived().getBaseLocation()); |
| 538 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 540 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 541 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 542 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 543 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 544 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 545 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 546 | FunctionProtoTypeLoc TL, |
| 547 | CXXRecordDecl *ThisContext, |
| 548 | unsigned ThisTypeQuals); |
| 549 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 550 | StmtResult TransformSEHHandler(Stmt *Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 551 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 552 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 553 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 554 | TemplateSpecializationTypeLoc TL, |
| 555 | TemplateName Template); |
| 556 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 557 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 558 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 559 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 560 | TemplateName Template, |
| 561 | CXXScopeSpec &SS); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 562 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 563 | QualType |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 564 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 565 | DependentTemplateSpecializationTypeLoc TL, |
| 566 | NestedNameSpecifierLoc QualifierLoc); |
| 567 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 568 | /// \brief Transforms the parameters of a function type into the |
| 569 | /// given vectors. |
| 570 | /// |
| 571 | /// The result vectors should be kept in sync; null entries in the |
| 572 | /// variables vector are acceptable. |
| 573 | /// |
| 574 | /// Return true on error. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 575 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 576 | ParmVarDecl **Params, unsigned NumParams, |
| 577 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 578 | SmallVectorImpl<QualType> &PTypes, |
| 579 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 580 | |
| 581 | /// \brief Transforms a single function-type parameter. Return null |
| 582 | /// on error. |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 583 | /// |
| 584 | /// \param indexAdjustment - A number to add to the parameter's |
| 585 | /// scope index; can be negative |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 586 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 587 | int indexAdjustment, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 588 | Optional<unsigned> NumExpansions, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 589 | bool ExpectParameterPack); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 590 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 591 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 592 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 593 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 594 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 595 | |
| 596 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 597 | /// \brief Transform the captures and body of a lambda expression. |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 598 | ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator, |
| 599 | ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 600 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 601 | TemplateParameterList *TransformTemplateParameterList( |
| 602 | TemplateParameterList *TPL) { |
| 603 | return TPL; |
| 604 | } |
| 605 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 606 | ExprResult TransformAddressOfOperand(Expr *E); |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 607 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 608 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 609 | bool IsAddressOfOperand, |
| 610 | TypeSourceInfo **RecoveryTSI); |
| 611 | |
| 612 | ExprResult TransformParenDependentScopeDeclRefExpr( |
| 613 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 614 | TypeSourceInfo **RecoveryTSI); |
| 615 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 616 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 617 | |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 618 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 619 | // amount of stack usage with clang. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 620 | #define STMT(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 621 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 622 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 623 | #define EXPR(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 624 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 625 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 626 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 627 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 629 | #define OPENMP_CLAUSE(Name, Class) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 630 | LLVM_ATTRIBUTE_NOINLINE \ |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 631 | OMPClause *Transform ## Class(Class *S); |
| 632 | #include "clang/Basic/OpenMPKinds.def" |
| 633 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 634 | /// \brief Build a new pointer type given its pointee type. |
| 635 | /// |
| 636 | /// By default, performs semantic analysis when building the pointer type. |
| 637 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 638 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 639 | |
| 640 | /// \brief Build a new block pointer type given its pointee type. |
| 641 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 642 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 643 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 644 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 645 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 646 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 647 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 648 | /// By default, performs semantic analysis when building the |
| 649 | /// reference type. Subclasses may override this routine to provide |
| 650 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 651 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 652 | /// \param LValue whether the type was written with an lvalue sigil |
| 653 | /// or an rvalue sigil. |
| 654 | QualType RebuildReferenceType(QualType ReferentType, |
| 655 | bool LValue, |
| 656 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 658 | /// \brief Build a new member pointer type given the pointee type and the |
| 659 | /// class type it refers into. |
| 660 | /// |
| 661 | /// By default, performs semantic analysis when building the member pointer |
| 662 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 663 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 664 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 666 | /// \brief Build a new array type given the element type, size |
| 667 | /// modifier, size of the array (if known), size expression, and index type |
| 668 | /// qualifiers. |
| 669 | /// |
| 670 | /// By default, performs semantic analysis when building the array type. |
| 671 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 673 | QualType RebuildArrayType(QualType ElementType, |
| 674 | ArrayType::ArraySizeModifier SizeMod, |
| 675 | const llvm::APInt *Size, |
| 676 | Expr *SizeExpr, |
| 677 | unsigned IndexTypeQuals, |
| 678 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 680 | /// \brief Build a new constant array type given the element type, size |
| 681 | /// modifier, (known) size of the array, and index type qualifiers. |
| 682 | /// |
| 683 | /// By default, performs semantic analysis when building the array type. |
| 684 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 685 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 686 | ArrayType::ArraySizeModifier SizeMod, |
| 687 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 688 | unsigned IndexTypeQuals, |
| 689 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 691 | /// \brief Build a new incomplete array type given the element type, size |
| 692 | /// modifier, and index type qualifiers. |
| 693 | /// |
| 694 | /// By default, performs semantic analysis when building the array type. |
| 695 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 697 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 698 | unsigned IndexTypeQuals, |
| 699 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 700 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 702 | /// size modifier, size expression, and index type qualifiers. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis when building the array type. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 707 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 708 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 709 | unsigned IndexTypeQuals, |
| 710 | SourceRange BracketsRange); |
| 711 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 713 | /// size modifier, size expression, and index type qualifiers. |
| 714 | /// |
| 715 | /// By default, performs semantic analysis when building the array type. |
| 716 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 717 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 718 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 719 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 720 | unsigned IndexTypeQuals, |
| 721 | SourceRange BracketsRange); |
| 722 | |
| 723 | /// \brief Build a new vector type given the element type and |
| 724 | /// number of elements. |
| 725 | /// |
| 726 | /// By default, performs semantic analysis when building the vector type. |
| 727 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 728 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 729 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 731 | /// \brief Build a new extended vector type given the element type and |
| 732 | /// number of elements. |
| 733 | /// |
| 734 | /// By default, performs semantic analysis when building the vector type. |
| 735 | /// Subclasses may override this routine to provide different behavior. |
| 736 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 737 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | |
| 739 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 740 | /// given the element type and number of elements. |
| 741 | /// |
| 742 | /// By default, performs semantic analysis when building the vector type. |
| 743 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 744 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 745 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 746 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 747 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 748 | /// \brief Build a new function type. |
| 749 | /// |
| 750 | /// By default, performs semantic analysis when building the function type. |
| 751 | /// Subclasses may override this routine to provide different behavior. |
| 752 | QualType RebuildFunctionProtoType(QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 753 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 754 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 755 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 756 | /// \brief Build a new unprototyped function type. |
| 757 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 758 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 759 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 760 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 761 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 762 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 763 | /// \brief Build a new typedef type. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 764 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 765 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 766 | } |
| 767 | |
| 768 | /// \brief Build a new class/struct/union type. |
| 769 | QualType RebuildRecordType(RecordDecl *Record) { |
| 770 | return SemaRef.Context.getTypeDeclType(Record); |
| 771 | } |
| 772 | |
| 773 | /// \brief Build a new Enum type. |
| 774 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 775 | return SemaRef.Context.getTypeDeclType(Enum); |
| 776 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 777 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 779 | /// |
| 780 | /// By default, performs semantic analysis when building the typeof type. |
| 781 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 782 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 783 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 784 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 785 | /// |
| 786 | /// By default, builds a new TypeOfType with the given underlying type. |
| 787 | QualType RebuildTypeOfType(QualType Underlying); |
| 788 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 789 | /// \brief Build a new unary transform type. |
| 790 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 791 | UnaryTransformType::UTTKind UKind, |
| 792 | SourceLocation Loc); |
| 793 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 794 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 795 | /// |
| 796 | /// By default, performs semantic analysis when building the decltype type. |
| 797 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 798 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 800 | /// \brief Build a new C++11 auto type. |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 801 | /// |
| 802 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 803 | QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) { |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 804 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 805 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 806 | // that we'll retry deduction after the transformation. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 807 | return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto, |
| 808 | /*IsDependent*/ false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 809 | } |
| 810 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 811 | /// \brief Build a new template specialization type. |
| 812 | /// |
| 813 | /// By default, performs semantic analysis when building the template |
| 814 | /// specialization type. Subclasses may override this routine to provide |
| 815 | /// different behavior. |
| 816 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 817 | SourceLocation TemplateLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 818 | TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 819 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 820 | /// \brief Build a new parenthesized type. |
| 821 | /// |
| 822 | /// By default, builds a new ParenType type from the inner type. |
| 823 | /// Subclasses may override this routine to provide different behavior. |
| 824 | QualType RebuildParenType(QualType InnerType) { |
| 825 | return SemaRef.Context.getParenType(InnerType); |
| 826 | } |
| 827 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 828 | /// \brief Build a new qualified name type. |
| 829 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 830 | /// By default, builds a new ElaboratedType type from the keyword, |
| 831 | /// the nested-name-specifier and the named type. |
| 832 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 833 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 834 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 835 | NestedNameSpecifierLoc QualifierLoc, |
| 836 | QualType Named) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 837 | return SemaRef.Context.getElaboratedType(Keyword, |
| 838 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 839 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 840 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 841 | |
| 842 | /// \brief Build a new typename type that refers to a template-id. |
| 843 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 844 | /// By default, builds a new DependentNameType type from the |
| 845 | /// nested-name-specifier and the given type. Subclasses may override |
| 846 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 847 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 848 | ElaboratedTypeKeyword Keyword, |
| 849 | NestedNameSpecifierLoc QualifierLoc, |
| 850 | const IdentifierInfo *Name, |
| 851 | SourceLocation NameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 852 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 853 | // Rebuild the template name. |
| 854 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 855 | CXXScopeSpec SS; |
| 856 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 857 | TemplateName InstName |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 858 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), |
| 859 | nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 860 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 861 | if (InstName.isNull()) |
| 862 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 863 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 864 | // If it's still dependent, make a dependent specialization. |
| 865 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 866 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 867 | QualifierLoc.getNestedNameSpecifier(), |
| 868 | Name, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 869 | Args); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 870 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 871 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 872 | // specialization. |
| 873 | QualType T = |
| 874 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 875 | if (T.isNull()) return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 876 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 877 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 878 | return T; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 879 | |
| 880 | return SemaRef.Context.getElaboratedType(Keyword, |
| 881 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 882 | T); |
| 883 | } |
| 884 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 885 | /// \brief Build a new typename type that refers to an identifier. |
| 886 | /// |
| 887 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 888 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 889 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 890 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 891 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 892 | NestedNameSpecifierLoc QualifierLoc, |
| 893 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 894 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 895 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 896 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 897 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 898 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 899 | // If the name is still dependent, just build a new dependent name type. |
| 900 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 901 | return SemaRef.Context.getDependentNameType(Keyword, |
| 902 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 903 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 906 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 907 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 908 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 909 | |
| 910 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 911 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 912 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 913 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 914 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 915 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 916 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 917 | if (!DC) |
| 918 | return QualType(); |
| 919 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 920 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 921 | return QualType(); |
| 922 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 923 | TagDecl *Tag = nullptr; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 924 | SemaRef.LookupQualifiedName(Result, DC); |
| 925 | switch (Result.getResultKind()) { |
| 926 | case LookupResult::NotFound: |
| 927 | case LookupResult::NotFoundInCurrentInstantiation: |
| 928 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 930 | case LookupResult::Found: |
| 931 | Tag = Result.getAsSingle<TagDecl>(); |
| 932 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 933 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 934 | case LookupResult::FoundOverloaded: |
| 935 | case LookupResult::FoundUnresolvedValue: |
| 936 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 937 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 938 | case LookupResult::Ambiguous: |
| 939 | // Let the LookupResult structure handle ambiguities. |
| 940 | return QualType(); |
| 941 | } |
| 942 | |
| 943 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 944 | // Check where the name exists but isn't a tag type and use that to emit |
| 945 | // better diagnostics. |
| 946 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 947 | SemaRef.LookupQualifiedName(Result, DC); |
| 948 | switch (Result.getResultKind()) { |
| 949 | case LookupResult::Found: |
| 950 | case LookupResult::FoundOverloaded: |
| 951 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 952 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 953 | unsigned Kind = 0; |
| 954 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 955 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 956 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 957 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 958 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 959 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 960 | } |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 961 | default: |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 962 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Stephan Tolksdorf | eb7708d | 2014-03-13 20:34:03 +0000 | [diff] [blame] | 963 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 964 | break; |
| 965 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 966 | return QualType(); |
| 967 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 968 | |
Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 969 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 970 | IdLoc, *Id)) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 971 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 972 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 973 | return QualType(); |
| 974 | } |
| 975 | |
| 976 | // Build the elaborated-type-specifier type. |
| 977 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 978 | return SemaRef.Context.getElaboratedType(Keyword, |
| 979 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 980 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 981 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 982 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 983 | /// \brief Build a new pack expansion type. |
| 984 | /// |
| 985 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 986 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 987 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 988 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 989 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 990 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 991 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 992 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 995 | /// \brief Build a new atomic type given its value type. |
| 996 | /// |
| 997 | /// By default, performs semantic analysis when building the atomic type. |
| 998 | /// Subclasses may override this routine to provide different behavior. |
| 999 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1000 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1001 | /// \brief Build a new template name given a nested name specifier, a flag |
| 1002 | /// indicating whether the "template" keyword was provided, and the template |
| 1003 | /// that the template name refers to. |
| 1004 | /// |
| 1005 | /// By default, builds the new template name directly. Subclasses may override |
| 1006 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1007 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1008 | bool TemplateKW, |
| 1009 | TemplateDecl *Template); |
| 1010 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1011 | /// \brief Build a new template name given a nested name specifier and the |
| 1012 | /// name that is referred to as a template. |
| 1013 | /// |
| 1014 | /// By default, performs semantic analysis to determine whether the name can |
| 1015 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1016 | /// template name. Subclasses may override this routine to provide different |
| 1017 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1018 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1019 | const IdentifierInfo &Name, |
| 1020 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1021 | QualType ObjectType, |
| 1022 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1023 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1024 | /// \brief Build a new template name given a nested name specifier and the |
| 1025 | /// overloaded operator name that is referred to as a template. |
| 1026 | /// |
| 1027 | /// By default, performs semantic analysis to determine whether the name can |
| 1028 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1029 | /// template name. Subclasses may override this routine to provide different |
| 1030 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1031 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1032 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1033 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1034 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1035 | |
| 1036 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1037 | /// and the |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1038 | /// |
| 1039 | /// By default, performs semantic analysis to determine whether the name can |
| 1040 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1041 | /// template name. Subclasses may override this routine to provide different |
| 1042 | /// behavior. |
| 1043 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1044 | const TemplateArgument &ArgPack) { |
| 1045 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1046 | } |
| 1047 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1048 | /// \brief Build a new compound statement. |
| 1049 | /// |
| 1050 | /// By default, performs semantic analysis to build the new statement. |
| 1051 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1052 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1053 | MultiStmtArg Statements, |
| 1054 | SourceLocation RBraceLoc, |
| 1055 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1056 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1057 | IsStmtExpr); |
| 1058 | } |
| 1059 | |
| 1060 | /// \brief Build a new case statement. |
| 1061 | /// |
| 1062 | /// By default, performs semantic analysis to build the new statement. |
| 1063 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1064 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1065 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1066 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1067 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1068 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1069 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1070 | ColonLoc); |
| 1071 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1073 | /// \brief Attach the body to a new case statement. |
| 1074 | /// |
| 1075 | /// By default, performs semantic analysis to build the new statement. |
| 1076 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1077 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1078 | getSema().ActOnCaseStmtBody(S, Body); |
| 1079 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1082 | /// \brief Build a new default statement. |
| 1083 | /// |
| 1084 | /// By default, performs semantic analysis to build the new statement. |
| 1085 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1086 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1087 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1088 | Stmt *SubStmt) { |
| 1089 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1090 | /*CurScope=*/nullptr); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1091 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1093 | /// \brief Build a new label statement. |
| 1094 | /// |
| 1095 | /// By default, performs semantic analysis to build the new statement. |
| 1096 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1097 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1098 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1099 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1100 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1102 | /// \brief Build a new label statement. |
| 1103 | /// |
| 1104 | /// By default, performs semantic analysis to build the new statement. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1106 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1107 | ArrayRef<const Attr*> Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1108 | Stmt *SubStmt) { |
| 1109 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1110 | } |
| 1111 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1112 | /// \brief Build a new "if" statement. |
| 1113 | /// |
| 1114 | /// By default, performs semantic analysis to build the new statement. |
| 1115 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1116 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1117 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1118 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1119 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1120 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1122 | /// \brief Start building a new switch statement. |
| 1123 | /// |
| 1124 | /// By default, performs semantic analysis to build the new statement. |
| 1125 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1126 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1127 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1128 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1129 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1132 | /// \brief Attach the body to the switch statement. |
| 1133 | /// |
| 1134 | /// By default, performs semantic analysis to build the new statement. |
| 1135 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1136 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1137 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1138 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /// \brief Build a new while statement. |
| 1142 | /// |
| 1143 | /// By default, performs semantic analysis to build the new statement. |
| 1144 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1145 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1146 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1147 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1148 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1150 | /// \brief Build a new do-while statement. |
| 1151 | /// |
| 1152 | /// By default, performs semantic analysis to build the new statement. |
| 1153 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1154 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1155 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1156 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1157 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1158 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /// \brief Build a new for statement. |
| 1162 | /// |
| 1163 | /// By default, performs semantic analysis to build the new statement. |
| 1164 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1165 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1166 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1167 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1168 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1169 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1170 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1173 | /// \brief Build a new goto statement. |
| 1174 | /// |
| 1175 | /// By default, performs semantic analysis to build the new statement. |
| 1176 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1177 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1178 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1179 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | /// \brief Build a new indirect goto statement. |
| 1183 | /// |
| 1184 | /// By default, performs semantic analysis to build the new statement. |
| 1185 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1186 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1187 | SourceLocation StarLoc, |
| 1188 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1189 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1191 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1192 | /// \brief Build a new return statement. |
| 1193 | /// |
| 1194 | /// By default, performs semantic analysis to build the new statement. |
| 1195 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1196 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
Nick Lewycky | d78f92f | 2014-05-03 00:41:18 +0000 | [diff] [blame] | 1197 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1200 | /// \brief Build a new declaration statement. |
| 1201 | /// |
| 1202 | /// By default, performs semantic analysis to build the new statement. |
| 1203 | /// Subclasses may override this routine to provide different behavior. |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 1204 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1205 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1206 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1207 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1208 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1210 | /// \brief Build a new inline asm statement. |
| 1211 | /// |
| 1212 | /// By default, performs semantic analysis to build the new statement. |
| 1213 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1214 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1215 | bool IsVolatile, unsigned NumOutputs, |
| 1216 | unsigned NumInputs, IdentifierInfo **Names, |
| 1217 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1218 | Expr *AsmString, MultiExprArg Clobbers, |
| 1219 | SourceLocation RParenLoc) { |
| 1220 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1221 | NumInputs, Names, Constraints, Exprs, |
| 1222 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1223 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1224 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1225 | /// \brief Build a new MS style inline asm statement. |
| 1226 | /// |
| 1227 | /// By default, performs semantic analysis to build the new statement. |
| 1228 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1229 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1230 | ArrayRef<Token> AsmToks, |
| 1231 | StringRef AsmString, |
| 1232 | unsigned NumOutputs, unsigned NumInputs, |
| 1233 | ArrayRef<StringRef> Constraints, |
| 1234 | ArrayRef<StringRef> Clobbers, |
| 1235 | ArrayRef<Expr*> Exprs, |
| 1236 | SourceLocation EndLoc) { |
| 1237 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1238 | NumOutputs, NumInputs, |
| 1239 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1242 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1243 | /// |
| 1244 | /// By default, performs semantic analysis to build the new statement. |
| 1245 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1246 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1247 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1248 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1249 | Stmt *Finally) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1250 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1251 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1254 | /// \brief Rebuild an Objective-C exception declaration. |
| 1255 | /// |
| 1256 | /// By default, performs semantic analysis to build the new declaration. |
| 1257 | /// Subclasses may override this routine to provide different behavior. |
| 1258 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1259 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1260 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1261 | ExceptionDecl->getInnerLocStart(), |
| 1262 | ExceptionDecl->getLocation(), |
| 1263 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1264 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1265 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1266 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1267 | /// |
| 1268 | /// By default, performs semantic analysis to build the new statement. |
| 1269 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1270 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1271 | SourceLocation RParenLoc, |
| 1272 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1273 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1274 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1275 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1276 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1277 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1278 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1279 | /// |
| 1280 | /// By default, performs semantic analysis to build the new statement. |
| 1281 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1282 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1283 | Stmt *Body) { |
| 1284 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1285 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1286 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1287 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1288 | /// |
| 1289 | /// By default, performs semantic analysis to build the new statement. |
| 1290 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1291 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1292 | Expr *Operand) { |
| 1293 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1294 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1295 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1296 | /// \brief Build a new OpenMP executable directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1297 | /// |
| 1298 | /// By default, performs semantic analysis to build the new statement. |
| 1299 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1300 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
| 1301 | ArrayRef<OMPClause *> Clauses, |
| 1302 | Stmt *AStmt, |
| 1303 | SourceLocation StartLoc, |
| 1304 | SourceLocation EndLoc) { |
| 1305 | return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt, |
| 1306 | StartLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1309 | /// \brief Build a new OpenMP 'if' clause. |
| 1310 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1311 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1312 | /// Subclasses may override this routine to provide different behavior. |
| 1313 | OMPClause *RebuildOMPIfClause(Expr *Condition, |
| 1314 | SourceLocation StartLoc, |
| 1315 | SourceLocation LParenLoc, |
| 1316 | SourceLocation EndLoc) { |
| 1317 | return getSema().ActOnOpenMPIfClause(Condition, StartLoc, |
| 1318 | LParenLoc, EndLoc); |
| 1319 | } |
| 1320 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1321 | /// \brief Build a new OpenMP 'final' clause. |
| 1322 | /// |
| 1323 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1324 | /// Subclasses may override this routine to provide different behavior. |
| 1325 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1326 | SourceLocation LParenLoc, |
| 1327 | SourceLocation EndLoc) { |
| 1328 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
| 1329 | EndLoc); |
| 1330 | } |
| 1331 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1332 | /// \brief Build a new OpenMP 'num_threads' clause. |
| 1333 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1334 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1335 | /// Subclasses may override this routine to provide different behavior. |
| 1336 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
| 1337 | SourceLocation StartLoc, |
| 1338 | SourceLocation LParenLoc, |
| 1339 | SourceLocation EndLoc) { |
| 1340 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
| 1341 | LParenLoc, EndLoc); |
| 1342 | } |
| 1343 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1344 | /// \brief Build a new OpenMP 'safelen' clause. |
| 1345 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1346 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1347 | /// Subclasses may override this routine to provide different behavior. |
| 1348 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1349 | SourceLocation LParenLoc, |
| 1350 | SourceLocation EndLoc) { |
| 1351 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1352 | } |
| 1353 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1354 | /// \brief Build a new OpenMP 'collapse' clause. |
| 1355 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1356 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1357 | /// Subclasses may override this routine to provide different behavior. |
| 1358 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1359 | SourceLocation LParenLoc, |
| 1360 | SourceLocation EndLoc) { |
| 1361 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
| 1362 | EndLoc); |
| 1363 | } |
| 1364 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1365 | /// \brief Build a new OpenMP 'default' clause. |
| 1366 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1367 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1368 | /// Subclasses may override this routine to provide different behavior. |
| 1369 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1370 | SourceLocation KindKwLoc, |
| 1371 | SourceLocation StartLoc, |
| 1372 | SourceLocation LParenLoc, |
| 1373 | SourceLocation EndLoc) { |
| 1374 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1375 | StartLoc, LParenLoc, EndLoc); |
| 1376 | } |
| 1377 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1378 | /// \brief Build a new OpenMP 'proc_bind' clause. |
| 1379 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1380 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1381 | /// Subclasses may override this routine to provide different behavior. |
| 1382 | OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 1383 | SourceLocation KindKwLoc, |
| 1384 | SourceLocation StartLoc, |
| 1385 | SourceLocation LParenLoc, |
| 1386 | SourceLocation EndLoc) { |
| 1387 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
| 1388 | StartLoc, LParenLoc, EndLoc); |
| 1389 | } |
| 1390 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1391 | /// \brief Build a new OpenMP 'schedule' clause. |
| 1392 | /// |
| 1393 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1394 | /// Subclasses may override this routine to provide different behavior. |
| 1395 | OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind, |
| 1396 | Expr *ChunkSize, |
| 1397 | SourceLocation StartLoc, |
| 1398 | SourceLocation LParenLoc, |
| 1399 | SourceLocation KindLoc, |
| 1400 | SourceLocation CommaLoc, |
| 1401 | SourceLocation EndLoc) { |
| 1402 | return getSema().ActOnOpenMPScheduleClause( |
| 1403 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 1404 | } |
| 1405 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1406 | /// \brief Build a new OpenMP 'private' clause. |
| 1407 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1408 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1409 | /// Subclasses may override this routine to provide different behavior. |
| 1410 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1411 | SourceLocation StartLoc, |
| 1412 | SourceLocation LParenLoc, |
| 1413 | SourceLocation EndLoc) { |
| 1414 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1415 | EndLoc); |
| 1416 | } |
| 1417 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1418 | /// \brief Build a new OpenMP 'firstprivate' clause. |
| 1419 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1420 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1421 | /// Subclasses may override this routine to provide different behavior. |
| 1422 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1423 | SourceLocation StartLoc, |
| 1424 | SourceLocation LParenLoc, |
| 1425 | SourceLocation EndLoc) { |
| 1426 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1427 | EndLoc); |
| 1428 | } |
| 1429 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1430 | /// \brief Build a new OpenMP 'lastprivate' clause. |
| 1431 | /// |
| 1432 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1433 | /// Subclasses may override this routine to provide different behavior. |
| 1434 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1435 | SourceLocation StartLoc, |
| 1436 | SourceLocation LParenLoc, |
| 1437 | SourceLocation EndLoc) { |
| 1438 | return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, |
| 1439 | EndLoc); |
| 1440 | } |
| 1441 | |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1442 | /// \brief Build a new OpenMP 'shared' clause. |
| 1443 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1444 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1445 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1446 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1447 | SourceLocation StartLoc, |
| 1448 | SourceLocation LParenLoc, |
| 1449 | SourceLocation EndLoc) { |
| 1450 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1451 | EndLoc); |
| 1452 | } |
| 1453 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1454 | /// \brief Build a new OpenMP 'reduction' clause. |
| 1455 | /// |
| 1456 | /// By default, performs semantic analysis to build the new statement. |
| 1457 | /// Subclasses may override this routine to provide different behavior. |
| 1458 | OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList, |
| 1459 | SourceLocation StartLoc, |
| 1460 | SourceLocation LParenLoc, |
| 1461 | SourceLocation ColonLoc, |
| 1462 | SourceLocation EndLoc, |
| 1463 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1464 | const DeclarationNameInfo &ReductionId) { |
| 1465 | return getSema().ActOnOpenMPReductionClause( |
| 1466 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1467 | ReductionId); |
| 1468 | } |
| 1469 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1470 | /// \brief Build a new OpenMP 'linear' clause. |
| 1471 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1472 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1473 | /// Subclasses may override this routine to provide different behavior. |
| 1474 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1475 | SourceLocation StartLoc, |
| 1476 | SourceLocation LParenLoc, |
| 1477 | SourceLocation ColonLoc, |
| 1478 | SourceLocation EndLoc) { |
| 1479 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
| 1480 | ColonLoc, EndLoc); |
| 1481 | } |
| 1482 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1483 | /// \brief Build a new OpenMP 'aligned' clause. |
| 1484 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1485 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1486 | /// Subclasses may override this routine to provide different behavior. |
| 1487 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 1488 | SourceLocation StartLoc, |
| 1489 | SourceLocation LParenLoc, |
| 1490 | SourceLocation ColonLoc, |
| 1491 | SourceLocation EndLoc) { |
| 1492 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
| 1493 | LParenLoc, ColonLoc, EndLoc); |
| 1494 | } |
| 1495 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1496 | /// \brief Build a new OpenMP 'copyin' clause. |
| 1497 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1498 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1499 | /// Subclasses may override this routine to provide different behavior. |
| 1500 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1501 | SourceLocation StartLoc, |
| 1502 | SourceLocation LParenLoc, |
| 1503 | SourceLocation EndLoc) { |
| 1504 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
| 1505 | EndLoc); |
| 1506 | } |
| 1507 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1508 | /// \brief Build a new OpenMP 'copyprivate' clause. |
| 1509 | /// |
| 1510 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1511 | /// Subclasses may override this routine to provide different behavior. |
| 1512 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 1513 | SourceLocation StartLoc, |
| 1514 | SourceLocation LParenLoc, |
| 1515 | SourceLocation EndLoc) { |
| 1516 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
| 1517 | EndLoc); |
| 1518 | } |
| 1519 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1520 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1521 | /// |
| 1522 | /// By default, performs semantic analysis to build the new statement. |
| 1523 | /// Subclasses may override this routine to provide different behavior. |
| 1524 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1525 | Expr *object) { |
| 1526 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1527 | } |
| 1528 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1529 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1530 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1531 | /// By default, performs semantic analysis to build the new statement. |
| 1532 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1533 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1534 | Expr *Object, Stmt *Body) { |
| 1535 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1536 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1537 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1538 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1539 | /// |
| 1540 | /// By default, performs semantic analysis to build the new statement. |
| 1541 | /// Subclasses may override this routine to provide different behavior. |
| 1542 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1543 | Stmt *Body) { |
| 1544 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1545 | } |
John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1546 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1547 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1548 | /// |
| 1549 | /// By default, performs semantic analysis to build the new statement. |
| 1550 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1551 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1552 | Stmt *Element, |
| 1553 | Expr *Collection, |
| 1554 | SourceLocation RParenLoc, |
| 1555 | Stmt *Body) { |
Sam Panzer | 2c4ca0f | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1556 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1557 | Element, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1558 | Collection, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1559 | RParenLoc); |
| 1560 | if (ForEachStmt.isInvalid()) |
| 1561 | return StmtError(); |
| 1562 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1563 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1564 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1565 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1566 | /// \brief Build a new C++ exception declaration. |
| 1567 | /// |
| 1568 | /// By default, performs semantic analysis to build the new decaration. |
| 1569 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1570 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1571 | TypeSourceInfo *Declarator, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1572 | SourceLocation StartLoc, |
| 1573 | SourceLocation IdLoc, |
| 1574 | IdentifierInfo *Id) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1575 | VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1576 | StartLoc, IdLoc, Id); |
| 1577 | if (Var) |
| 1578 | getSema().CurContext->addDecl(Var); |
| 1579 | return Var; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | /// \brief Build a new C++ catch statement. |
| 1583 | /// |
| 1584 | /// By default, performs semantic analysis to build the new statement. |
| 1585 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1586 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1587 | VarDecl *ExceptionDecl, |
| 1588 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1589 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1590 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1591 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1593 | /// \brief Build a new C++ try statement. |
| 1594 | /// |
| 1595 | /// By default, performs semantic analysis to build the new statement. |
| 1596 | /// Subclasses may override this routine to provide different behavior. |
Robert Wilhelm | cafda82 | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 1597 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 1598 | ArrayRef<Stmt *> Handlers) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1599 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1602 | /// \brief Build a new C++0x range-based for statement. |
| 1603 | /// |
| 1604 | /// By default, performs semantic analysis to build the new statement. |
| 1605 | /// Subclasses may override this routine to provide different behavior. |
| 1606 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1607 | SourceLocation ColonLoc, |
| 1608 | Stmt *Range, Stmt *BeginEnd, |
| 1609 | Expr *Cond, Expr *Inc, |
| 1610 | Stmt *LoopVar, |
| 1611 | SourceLocation RParenLoc) { |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1612 | // If we've just learned that the range is actually an Objective-C |
| 1613 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1614 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1615 | if (RangeStmt->isSingleDecl()) { |
| 1616 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1617 | if (RangeVar->isInvalidDecl()) |
| 1618 | return StmtError(); |
| 1619 | |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1620 | Expr *RangeExpr = RangeVar->getInit(); |
| 1621 | if (!RangeExpr->isTypeDependent() && |
| 1622 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1623 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1624 | RParenLoc); |
| 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1629 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | a05b3b5 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1630 | Cond, Inc, LoopVar, RParenLoc, |
| 1631 | Sema::BFRK_Rebuild); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1632 | } |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1633 | |
| 1634 | /// \brief Build a new C++0x range-based for statement. |
| 1635 | /// |
| 1636 | /// By default, performs semantic analysis to build the new statement. |
| 1637 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1638 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1639 | bool IsIfExists, |
| 1640 | NestedNameSpecifierLoc QualifierLoc, |
| 1641 | DeclarationNameInfo NameInfo, |
| 1642 | Stmt *Nested) { |
| 1643 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1644 | QualifierLoc, NameInfo, Nested); |
| 1645 | } |
| 1646 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1647 | /// \brief Attach body to a C++0x range-based for statement. |
| 1648 | /// |
| 1649 | /// By default, performs semantic analysis to finish the new statement. |
| 1650 | /// Subclasses may override this routine to provide different behavior. |
| 1651 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1652 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1653 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1654 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1655 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
| 1656 | Stmt *TryBlock, Stmt *Handler) { |
| 1657 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1660 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1661 | Stmt *Block) { |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1662 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1665 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| 1666 | return getSema().ActOnSEHFinallyBlock(Loc, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | /// \brief Build a new expression that references a declaration. |
| 1670 | /// |
| 1671 | /// By default, performs semantic analysis to build the new expression. |
| 1672 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1673 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1674 | LookupResult &R, |
| 1675 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1676 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1677 | } |
| 1678 | |
| 1679 | |
| 1680 | /// \brief Build a new expression that references a declaration. |
| 1681 | /// |
| 1682 | /// By default, performs semantic analysis to build the new expression. |
| 1683 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1684 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1685 | ValueDecl *VD, |
| 1686 | const DeclarationNameInfo &NameInfo, |
| 1687 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1688 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1689 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1690 | |
| 1691 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1692 | |
| 1693 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1694 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1695 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1697 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | /// By default, performs semantic analysis to build the new expression. |
| 1699 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1700 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1701 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1702 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1705 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1706 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1707 | /// By default, performs semantic analysis to build the new expression. |
| 1708 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1709 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1710 | SourceLocation OperatorLoc, |
| 1711 | bool isArrow, |
| 1712 | CXXScopeSpec &SS, |
| 1713 | TypeSourceInfo *ScopeType, |
| 1714 | SourceLocation CCLoc, |
| 1715 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1716 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1717 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1719 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1720 | /// By default, performs semantic analysis to build the new expression. |
| 1721 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1722 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1723 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1724 | Expr *SubExpr) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1725 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1726 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1727 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1728 | /// \brief Build a new builtin offsetof expression. |
| 1729 | /// |
| 1730 | /// By default, performs semantic analysis to build the new expression. |
| 1731 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1732 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1733 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1734 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1735 | unsigned NumComponents, |
| 1736 | SourceLocation RParenLoc) { |
| 1737 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1738 | NumComponents, RParenLoc); |
| 1739 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1740 | |
| 1741 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1742 | /// type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1744 | /// By default, performs semantic analysis to build the new expression. |
| 1745 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1746 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1747 | SourceLocation OpLoc, |
| 1748 | UnaryExprOrTypeTrait ExprKind, |
| 1749 | SourceRange R) { |
| 1750 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1753 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1754 | /// expression argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1756 | /// By default, performs semantic analysis to build the new expression. |
| 1757 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1758 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1759 | UnaryExprOrTypeTrait ExprKind, |
| 1760 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1761 | ExprResult Result |
Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1762 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1763 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1764 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1765 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1766 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1769 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1770 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1771 | /// By default, performs semantic analysis to build the new expression. |
| 1772 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1773 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1774 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1775 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1776 | SourceLocation RBracketLoc) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1777 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1778 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1779 | RBracketLoc); |
| 1780 | } |
| 1781 | |
| 1782 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1784 | /// By default, performs semantic analysis to build the new expression. |
| 1785 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1786 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1787 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1788 | SourceLocation RParenLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1789 | Expr *ExecConfig = nullptr) { |
| 1790 | return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1791 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1795 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1796 | /// By default, performs semantic analysis to build the new expression. |
| 1797 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1798 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1799 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1800 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1801 | SourceLocation TemplateKWLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1802 | const DeclarationNameInfo &MemberNameInfo, |
| 1803 | ValueDecl *Member, |
| 1804 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1805 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1806 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1807 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1808 | isArrow); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1809 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1810 | // We have a reference to an unnamed field. This is always the |
| 1811 | // base of an anonymous struct/union member access, i.e. the |
| 1812 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1813 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1814 | assert(Member->getType()->isRecordType() && |
| 1815 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1816 | |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1817 | BaseResult = |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1818 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1819 | QualifierLoc.getNestedNameSpecifier(), |
| 1820 | FoundDecl, Member); |
| 1821 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1822 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1823 | Base = BaseResult.get(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1824 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1826 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1827 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1828 | cast<FieldDecl>(Member)->getType(), |
| 1829 | VK, OK_Ordinary); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1830 | return ME; |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1831 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1832 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1833 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1834 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1835 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1836 | Base = BaseResult.get(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1837 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1838 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1839 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1840 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1841 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1842 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1843 | R.resolveKind(); |
| 1844 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1845 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1846 | SS, TemplateKWLoc, |
| 1847 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1848 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1849 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1851 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1853 | /// By default, performs semantic analysis to build the new expression. |
| 1854 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1855 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1856 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1857 | Expr *LHS, Expr *RHS) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1858 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1862 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1863 | /// By default, performs semantic analysis to build the new expression. |
| 1864 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1865 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1866 | SourceLocation QuestionLoc, |
| 1867 | Expr *LHS, |
| 1868 | SourceLocation ColonLoc, |
| 1869 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1870 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1871 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1874 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1876 | /// By default, performs semantic analysis to build the new expression. |
| 1877 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1878 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1879 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1880 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1881 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1882 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1883 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1884 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1885 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1886 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1888 | /// By default, performs semantic analysis to build the new expression. |
| 1889 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1890 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1891 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1892 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1893 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1894 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1895 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1896 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1898 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1899 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1900 | /// By default, performs semantic analysis to build the new expression. |
| 1901 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1902 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1903 | SourceLocation OpLoc, |
| 1904 | SourceLocation AccessorLoc, |
| 1905 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1906 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1907 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1908 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1909 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1910 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1911 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1912 | /*FirstQualifierInScope*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1913 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1914 | /* TemplateArgs */ nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1915 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1917 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1918 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1919 | /// By default, performs semantic analysis to build the new expression. |
| 1920 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1921 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1922 | MultiExprArg Inits, |
| 1923 | SourceLocation RBraceLoc, |
| 1924 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1925 | ExprResult Result |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1926 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1927 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1928 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1929 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1930 | // Patch in the result type we were given, which may have been computed |
| 1931 | // when the initial InitListExpr was built. |
| 1932 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1933 | ILE->setType(ResultTy); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1934 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1935 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1936 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1937 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1938 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1939 | /// By default, performs semantic analysis to build the new expression. |
| 1940 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1941 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1942 | MultiExprArg ArrayExprs, |
| 1943 | SourceLocation EqualOrColonLoc, |
| 1944 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1945 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1946 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1947 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1948 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1950 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1951 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1952 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1953 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1954 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1955 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1956 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1957 | /// By default, builds the implicit value initialization without performing |
| 1958 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1959 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1960 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1961 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1962 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1963 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1964 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1966 | /// By default, performs semantic analysis to build the new expression. |
| 1967 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1968 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1969 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1970 | SourceLocation RParenLoc) { |
| 1971 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1972 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1973 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1977 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1978 | /// By default, performs semantic analysis to build the new expression. |
| 1979 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1980 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1981 | MultiExprArg SubExprs, |
| 1982 | SourceLocation RParenLoc) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1983 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1984 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1985 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1986 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1987 | /// |
| 1988 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1989 | /// rather than attempting to map the label statement itself. |
| 1990 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1991 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1992 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1993 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1994 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1995 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1996 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1998 | /// By default, performs semantic analysis to build the new expression. |
| 1999 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2000 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2001 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2002 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2003 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2005 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2006 | /// \brief Build a new __builtin_choose_expr expression. |
| 2007 | /// |
| 2008 | /// By default, performs semantic analysis to build the new expression. |
| 2009 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2010 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2011 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2012 | SourceLocation RParenLoc) { |
| 2013 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2014 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2015 | RParenLoc); |
| 2016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2018 | /// \brief Build a new generic selection expression. |
| 2019 | /// |
| 2020 | /// By default, performs semantic analysis to build the new expression. |
| 2021 | /// Subclasses may override this routine to provide different behavior. |
| 2022 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2023 | SourceLocation DefaultLoc, |
| 2024 | SourceLocation RParenLoc, |
| 2025 | Expr *ControllingExpr, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2026 | ArrayRef<TypeSourceInfo *> Types, |
| 2027 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2028 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2029 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2032 | /// \brief Build a new overloaded operator call expression. |
| 2033 | /// |
| 2034 | /// By default, performs semantic analysis to build the new expression. |
| 2035 | /// The semantic analysis provides the behavior of template instantiation, |
| 2036 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2037 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2038 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2039 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2040 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2041 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2042 | Expr *Callee, |
| 2043 | Expr *First, |
| 2044 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2045 | |
| 2046 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2047 | /// reinterpret_cast. |
| 2048 | /// |
| 2049 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2050 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2051 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2052 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2053 | Stmt::StmtClass Class, |
| 2054 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2055 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2056 | SourceLocation RAngleLoc, |
| 2057 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2058 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2059 | SourceLocation RParenLoc) { |
| 2060 | switch (Class) { |
| 2061 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2062 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2063 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2064 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2065 | |
| 2066 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2067 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2068 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2069 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2070 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2071 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2072 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2073 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2074 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2075 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2076 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2077 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2078 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2079 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2080 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2082 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2083 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2084 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2085 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2086 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2087 | /// \brief Build a new C++ static_cast expression. |
| 2088 | /// |
| 2089 | /// By default, performs semantic analysis to build the new expression. |
| 2090 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2091 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2092 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2093 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2094 | SourceLocation RAngleLoc, |
| 2095 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2096 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2097 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2098 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2099 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2100 | SourceRange(LAngleLoc, RAngleLoc), |
| 2101 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | /// \brief Build a new C++ dynamic_cast expression. |
| 2105 | /// |
| 2106 | /// By default, performs semantic analysis to build the new expression. |
| 2107 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2108 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2109 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2110 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2111 | SourceLocation RAngleLoc, |
| 2112 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2113 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2114 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2115 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2116 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2117 | SourceRange(LAngleLoc, RAngleLoc), |
| 2118 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | /// \brief Build a new C++ reinterpret_cast expression. |
| 2122 | /// |
| 2123 | /// By default, performs semantic analysis to build the new expression. |
| 2124 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2125 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2126 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2127 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2128 | SourceLocation RAngleLoc, |
| 2129 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2130 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2131 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2132 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2133 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2134 | SourceRange(LAngleLoc, RAngleLoc), |
| 2135 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | /// \brief Build a new C++ const_cast expression. |
| 2139 | /// |
| 2140 | /// By default, performs semantic analysis to build the new expression. |
| 2141 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2142 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2143 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2144 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2145 | SourceLocation RAngleLoc, |
| 2146 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2147 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2148 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2149 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2150 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2151 | SourceRange(LAngleLoc, RAngleLoc), |
| 2152 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2153 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2155 | /// \brief Build a new C++ functional-style cast expression. |
| 2156 | /// |
| 2157 | /// By default, performs semantic analysis to build the new expression. |
| 2158 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2159 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2160 | SourceLocation LParenLoc, |
| 2161 | Expr *Sub, |
| 2162 | SourceLocation RParenLoc) { |
| 2163 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2164 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2165 | RParenLoc); |
| 2166 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2168 | /// \brief Build a new C++ typeid(type) expression. |
| 2169 | /// |
| 2170 | /// By default, performs semantic analysis to build the new expression. |
| 2171 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2172 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2173 | SourceLocation TypeidLoc, |
| 2174 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2175 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2176 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2177 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2179 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2180 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2181 | /// \brief Build a new C++ typeid(expr) expression. |
| 2182 | /// |
| 2183 | /// By default, performs semantic analysis to build the new expression. |
| 2184 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2185 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2186 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2187 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2188 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2189 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2190 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2191 | } |
| 2192 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2193 | /// \brief Build a new C++ __uuidof(type) expression. |
| 2194 | /// |
| 2195 | /// By default, performs semantic analysis to build the new expression. |
| 2196 | /// Subclasses may override this routine to provide different behavior. |
| 2197 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2198 | SourceLocation TypeidLoc, |
| 2199 | TypeSourceInfo *Operand, |
| 2200 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2201 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2202 | RParenLoc); |
| 2203 | } |
| 2204 | |
| 2205 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2206 | /// |
| 2207 | /// By default, performs semantic analysis to build the new expression. |
| 2208 | /// Subclasses may override this routine to provide different behavior. |
| 2209 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2210 | SourceLocation TypeidLoc, |
| 2211 | Expr *Operand, |
| 2212 | SourceLocation RParenLoc) { |
| 2213 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2214 | RParenLoc); |
| 2215 | } |
| 2216 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2217 | /// \brief Build a new C++ "this" expression. |
| 2218 | /// |
| 2219 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2220 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2221 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2222 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2223 | QualType ThisType, |
| 2224 | bool isImplicit) { |
Eli Friedman | 20139d3 | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2225 | getSema().CheckCXXThisCapture(ThisLoc); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2226 | return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | /// \brief Build a new C++ throw expression. |
| 2230 | /// |
| 2231 | /// By default, performs semantic analysis to build the new expression. |
| 2232 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2233 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2234 | bool IsThrownVariableInScope) { |
| 2235 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | /// \brief Build a new C++ default-argument expression. |
| 2239 | /// |
| 2240 | /// By default, builds a new default-argument expression, which does not |
| 2241 | /// require any semantic analysis. Subclasses may override this routine to |
| 2242 | /// provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2243 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2244 | ParmVarDecl *Param) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2245 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2248 | /// \brief Build a new C++11 default-initialization expression. |
| 2249 | /// |
| 2250 | /// By default, builds a new default field initialization expression, which |
| 2251 | /// does not require any semantic analysis. Subclasses may override this |
| 2252 | /// routine to provide different behavior. |
| 2253 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2254 | FieldDecl *Field) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2255 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field); |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2256 | } |
| 2257 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2258 | /// \brief Build a new C++ zero-initialization expression. |
| 2259 | /// |
| 2260 | /// By default, performs semantic analysis to build the new expression. |
| 2261 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2262 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2263 | SourceLocation LParenLoc, |
| 2264 | SourceLocation RParenLoc) { |
| 2265 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2266 | None, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2267 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2268 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2269 | /// \brief Build a new C++ "new" expression. |
| 2270 | /// |
| 2271 | /// By default, performs semantic analysis to build the new expression. |
| 2272 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2273 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2274 | bool UseGlobal, |
| 2275 | SourceLocation PlacementLParen, |
| 2276 | MultiExprArg PlacementArgs, |
| 2277 | SourceLocation PlacementRParen, |
| 2278 | SourceRange TypeIdParens, |
| 2279 | QualType AllocatedType, |
| 2280 | TypeSourceInfo *AllocatedTypeInfo, |
| 2281 | Expr *ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2282 | SourceRange DirectInitRange, |
| 2283 | Expr *Initializer) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2284 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2285 | PlacementLParen, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2286 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2287 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2288 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2289 | AllocatedType, |
| 2290 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2291 | ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2292 | DirectInitRange, |
| 2293 | Initializer); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2294 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2295 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2296 | /// \brief Build a new C++ "delete" expression. |
| 2297 | /// |
| 2298 | /// By default, performs semantic analysis to build the new expression. |
| 2299 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2300 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2301 | bool IsGlobalDelete, |
| 2302 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2303 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2304 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2305 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2306 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2307 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2308 | /// \brief Build a new type trait expression. |
| 2309 | /// |
| 2310 | /// By default, performs semantic analysis to build the new expression. |
| 2311 | /// Subclasses may override this routine to provide different behavior. |
| 2312 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2313 | SourceLocation StartLoc, |
| 2314 | ArrayRef<TypeSourceInfo *> Args, |
| 2315 | SourceLocation RParenLoc) { |
| 2316 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2317 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2318 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2319 | /// \brief Build a new array type trait expression. |
| 2320 | /// |
| 2321 | /// By default, performs semantic analysis to build the new expression. |
| 2322 | /// Subclasses may override this routine to provide different behavior. |
| 2323 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2324 | SourceLocation StartLoc, |
| 2325 | TypeSourceInfo *TSInfo, |
| 2326 | Expr *DimExpr, |
| 2327 | SourceLocation RParenLoc) { |
| 2328 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2329 | } |
| 2330 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2331 | /// \brief Build a new expression trait expression. |
| 2332 | /// |
| 2333 | /// By default, performs semantic analysis to build the new expression. |
| 2334 | /// Subclasses may override this routine to provide different behavior. |
| 2335 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2336 | SourceLocation StartLoc, |
| 2337 | Expr *Queried, |
| 2338 | SourceLocation RParenLoc) { |
| 2339 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2340 | } |
| 2341 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2342 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2343 | /// expression. |
| 2344 | /// |
| 2345 | /// By default, performs semantic analysis to build the new expression. |
| 2346 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2347 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2348 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2349 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2350 | const DeclarationNameInfo &NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2351 | const TemplateArgumentListInfo *TemplateArgs, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2352 | bool IsAddressOfOperand, |
| 2353 | TypeSourceInfo **RecoveryTSI) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2354 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2355 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2356 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2357 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2358 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2359 | TemplateArgs); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2360 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2361 | return getSema().BuildQualifiedDeclarationNameExpr( |
| 2362 | SS, NameInfo, IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | /// \brief Build a new template-id expression. |
| 2366 | /// |
| 2367 | /// By default, performs semantic analysis to build the new expression. |
| 2368 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2369 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2370 | SourceLocation TemplateKWLoc, |
| 2371 | LookupResult &R, |
| 2372 | bool RequiresADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2373 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2374 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2375 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | /// \brief Build a new object-construction expression. |
| 2379 | /// |
| 2380 | /// By default, performs semantic analysis to build the new expression. |
| 2381 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2382 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2383 | SourceLocation Loc, |
| 2384 | CXXConstructorDecl *Constructor, |
| 2385 | bool IsElidable, |
| 2386 | MultiExprArg Args, |
| 2387 | bool HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2388 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2389 | bool StdInitListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2390 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2391 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2392 | SourceRange ParenRange) { |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2393 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2394 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2395 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2396 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2397 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2398 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2399 | ConvertedArgs, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2400 | HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2401 | ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2402 | StdInitListInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2403 | RequiresZeroInit, ConstructKind, |
| 2404 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | /// \brief Build a new object-construction expression. |
| 2408 | /// |
| 2409 | /// By default, performs semantic analysis to build the new expression. |
| 2410 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2411 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2412 | SourceLocation LParenLoc, |
| 2413 | MultiExprArg Args, |
| 2414 | SourceLocation RParenLoc) { |
| 2415 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2416 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2417 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2418 | RParenLoc); |
| 2419 | } |
| 2420 | |
| 2421 | /// \brief Build a new object-construction expression. |
| 2422 | /// |
| 2423 | /// By default, performs semantic analysis to build the new expression. |
| 2424 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2425 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2426 | SourceLocation LParenLoc, |
| 2427 | MultiExprArg Args, |
| 2428 | SourceLocation RParenLoc) { |
| 2429 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2430 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2431 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2432 | RParenLoc); |
| 2433 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2434 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2435 | /// \brief Build a new member reference expression. |
| 2436 | /// |
| 2437 | /// By default, performs semantic analysis to build the new expression. |
| 2438 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2439 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2440 | QualType BaseType, |
| 2441 | bool IsArrow, |
| 2442 | SourceLocation OperatorLoc, |
| 2443 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2444 | SourceLocation TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2445 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2446 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2447 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2448 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2449 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2450 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2451 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2452 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2453 | SS, TemplateKWLoc, |
| 2454 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2455 | MemberNameInfo, |
| 2456 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2459 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2460 | /// |
| 2461 | /// By default, performs semantic analysis to build the new expression. |
| 2462 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2463 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2464 | SourceLocation OperatorLoc, |
| 2465 | bool IsArrow, |
| 2466 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2467 | SourceLocation TemplateKWLoc, |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2468 | NamedDecl *FirstQualifierInScope, |
| 2469 | LookupResult &R, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2470 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2471 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2472 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2473 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2474 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2475 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2476 | SS, TemplateKWLoc, |
| 2477 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2478 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2480 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2481 | /// \brief Build a new noexcept expression. |
| 2482 | /// |
| 2483 | /// By default, performs semantic analysis to build the new expression. |
| 2484 | /// Subclasses may override this routine to provide different behavior. |
| 2485 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2486 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2487 | } |
| 2488 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2489 | /// \brief Build a new expression to compute the length of a parameter pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2490 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2491 | SourceLocation PackLoc, |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2492 | SourceLocation RParenLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2493 | Optional<unsigned> Length) { |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2494 | if (Length) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2495 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2496 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2497 | RParenLoc, *Length); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2498 | |
| 2499 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2500 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2501 | RParenLoc); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2502 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2503 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2504 | /// \brief Build a new Objective-C boxed expression. |
| 2505 | /// |
| 2506 | /// By default, performs semantic analysis to build the new expression. |
| 2507 | /// Subclasses may override this routine to provide different behavior. |
| 2508 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2509 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2510 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2511 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2512 | /// \brief Build a new Objective-C array literal. |
| 2513 | /// |
| 2514 | /// By default, performs semantic analysis to build the new expression. |
| 2515 | /// Subclasses may override this routine to provide different behavior. |
| 2516 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2517 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2518 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2519 | MultiExprArg(Elements, NumElements)); |
| 2520 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2521 | |
| 2522 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2523 | Expr *Base, Expr *Key, |
| 2524 | ObjCMethodDecl *getterMethod, |
| 2525 | ObjCMethodDecl *setterMethod) { |
| 2526 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2527 | getterMethod, setterMethod); |
| 2528 | } |
| 2529 | |
| 2530 | /// \brief Build a new Objective-C dictionary literal. |
| 2531 | /// |
| 2532 | /// By default, performs semantic analysis to build the new expression. |
| 2533 | /// Subclasses may override this routine to provide different behavior. |
| 2534 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2535 | ObjCDictionaryElement *Elements, |
| 2536 | unsigned NumElements) { |
| 2537 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2538 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2539 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2540 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2541 | /// |
| 2542 | /// By default, performs semantic analysis to build the new expression. |
| 2543 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2544 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2545 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2546 | SourceLocation RParenLoc) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2547 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2548 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2549 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2550 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2551 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2552 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2553 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2554 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2555 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2556 | MultiExprArg Args, |
| 2557 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2558 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2559 | ReceiverTypeInfo->getType(), |
| 2560 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2561 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2562 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2566 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2567 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2568 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2569 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2570 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2571 | MultiExprArg Args, |
| 2572 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2573 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2574 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2575 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2576 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2577 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2580 | /// \brief Build a new Objective-C ivar reference expression. |
| 2581 | /// |
| 2582 | /// By default, performs semantic analysis to build the new expression. |
| 2583 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2584 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2585 | SourceLocation IvarLoc, |
| 2586 | bool IsArrow, bool IsFreeIvar) { |
| 2587 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2588 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2589 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| 2590 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2591 | /*FIXME:*/IvarLoc, IsArrow, |
| 2592 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2593 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2594 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2595 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2596 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2597 | |
| 2598 | /// \brief Build a new Objective-C property reference expression. |
| 2599 | /// |
| 2600 | /// By default, performs semantic analysis to build the new expression. |
| 2601 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2602 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2603 | ObjCPropertyDecl *Property, |
| 2604 | SourceLocation PropertyLoc) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2605 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2606 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 2607 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 2608 | /*FIXME:*/PropertyLoc, |
| 2609 | /*IsArrow=*/false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2610 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2611 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2612 | NameInfo, |
| 2613 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2614 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2615 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2616 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2617 | /// |
| 2618 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2619 | /// Subclasses may override this routine to provide different behavior. |
| 2620 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2621 | ObjCMethodDecl *Getter, |
| 2622 | ObjCMethodDecl *Setter, |
| 2623 | SourceLocation PropertyLoc) { |
| 2624 | // Since these expressions can only be value-dependent, we do not |
| 2625 | // need to perform semantic analysis again. |
| 2626 | return Owned( |
| 2627 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2628 | VK_LValue, OK_ObjCProperty, |
| 2629 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2632 | /// \brief Build a new Objective-C "isa" expression. |
| 2633 | /// |
| 2634 | /// By default, performs semantic analysis to build the new expression. |
| 2635 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2636 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2637 | SourceLocation OpLoc, bool IsArrow) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2638 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2639 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 2640 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2641 | OpLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2642 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2643 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2644 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2645 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2646 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2647 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2648 | /// \brief Build a new shuffle vector expression. |
| 2649 | /// |
| 2650 | /// By default, performs semantic analysis to build the new expression. |
| 2651 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2652 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2653 | MultiExprArg SubExprs, |
| 2654 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2655 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2656 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2657 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2658 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2659 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2660 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2661 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2662 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2663 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2664 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2665 | SemaRef.Context.BuiltinFnTy, |
| 2666 | VK_RValue, BuiltinLoc); |
| 2667 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2668 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2669 | CK_BuiltinFnToFnPtr).get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2670 | |
| 2671 | // Build the CallExpr |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2672 | ExprResult TheCall = new (SemaRef.Context) CallExpr( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2673 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2674 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2675 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2676 | // Type-check the __builtin_shufflevector expression. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2677 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2678 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2679 | |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 2680 | /// \brief Build a new convert vector expression. |
| 2681 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 2682 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 2683 | SourceLocation RParenLoc) { |
| 2684 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 2685 | BuiltinLoc, RParenLoc); |
| 2686 | } |
| 2687 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2688 | /// \brief Build a new template argument pack expansion. |
| 2689 | /// |
| 2690 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2691 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2692 | /// different behavior. |
| 2693 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2694 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2695 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2696 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2697 | case TemplateArgument::Expression: { |
| 2698 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2699 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2700 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2701 | if (Result.isInvalid()) |
| 2702 | return TemplateArgumentLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2703 | |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2704 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2705 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2706 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2707 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2708 | return TemplateArgumentLoc(TemplateArgument( |
| 2709 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2710 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2711 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2712 | Pattern.getTemplateNameLoc(), |
| 2713 | EllipsisLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2714 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2715 | case TemplateArgument::Null: |
| 2716 | case TemplateArgument::Integral: |
| 2717 | case TemplateArgument::Declaration: |
| 2718 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2719 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2720 | case TemplateArgument::NullPtr: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2721 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2722 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2723 | case TemplateArgument::Type: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2724 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2725 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2726 | EllipsisLoc, |
| 2727 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2728 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2729 | Expansion); |
| 2730 | break; |
| 2731 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2732 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2733 | return TemplateArgumentLoc(); |
| 2734 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2735 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2736 | /// \brief Build a new expression pack expansion. |
| 2737 | /// |
| 2738 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2739 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2740 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2741 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2742 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2743 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2744 | } |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2745 | |
| 2746 | /// \brief Build a new atomic operation expression. |
| 2747 | /// |
| 2748 | /// By default, performs semantic analysis to build the new expression. |
| 2749 | /// Subclasses may override this routine to provide different behavior. |
| 2750 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2751 | MultiExprArg SubExprs, |
| 2752 | QualType RetTy, |
| 2753 | AtomicExpr::AtomicOp Op, |
| 2754 | SourceLocation RParenLoc) { |
| 2755 | // Just create the expression; there is not any interesting semantic |
| 2756 | // analysis here because we can't actually build an AtomicExpr until |
| 2757 | // we are sure it is semantically sound. |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2758 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2759 | RParenLoc); |
| 2760 | } |
| 2761 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2762 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2763 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2764 | QualType ObjectType, |
| 2765 | NamedDecl *FirstQualifierInScope, |
| 2766 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2767 | |
| 2768 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2769 | QualType ObjectType, |
| 2770 | NamedDecl *FirstQualifierInScope, |
| 2771 | CXXScopeSpec &SS); |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 2772 | |
| 2773 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 2774 | NamedDecl *FirstQualifierInScope, |
| 2775 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2776 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2777 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2778 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2779 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2780 | if (!S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2781 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2782 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2783 | switch (S->getStmtClass()) { |
| 2784 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2785 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2786 | // Transform individual statement nodes |
| 2787 | #define STMT(Node, Parent) \ |
| 2788 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2789 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2790 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2791 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2793 | // Transform expressions by calling TransformExpr. |
| 2794 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2795 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2796 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2797 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2798 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2799 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2800 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2801 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2802 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2803 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2804 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2807 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2808 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2809 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2810 | template<typename Derived> |
| 2811 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2812 | if (!S) |
| 2813 | return S; |
| 2814 | |
| 2815 | switch (S->getClauseKind()) { |
| 2816 | default: break; |
| 2817 | // Transform individual clause nodes |
| 2818 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2819 | case OMPC_ ## Name : \ |
| 2820 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2821 | #include "clang/Basic/OpenMPKinds.def" |
| 2822 | } |
| 2823 | |
| 2824 | return S; |
| 2825 | } |
| 2826 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2827 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2828 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2829 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2830 | if (!E) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2831 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2832 | |
| 2833 | switch (E->getStmtClass()) { |
| 2834 | case Stmt::NoStmtClass: break; |
| 2835 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2836 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2837 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2838 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2839 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2840 | } |
| 2841 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2842 | return E; |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | template<typename Derived> |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2846 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 2847 | bool CXXDirectInit) { |
| 2848 | // Initializers are instantiated like expressions, except that various outer |
| 2849 | // layers are stripped. |
| 2850 | if (!Init) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2851 | return Init; |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2852 | |
| 2853 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2854 | Init = ExprTemp->getSubExpr(); |
| 2855 | |
Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 2856 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 2857 | Init = MTE->GetTemporaryExpr(); |
| 2858 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2859 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 2860 | Init = Binder->getSubExpr(); |
| 2861 | |
| 2862 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 2863 | Init = ICE->getSubExprAsWritten(); |
| 2864 | |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 2865 | if (CXXStdInitializerListExpr *ILE = |
| 2866 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| 2867 | return TransformInitializer(ILE->getSubExpr(), CXXDirectInit); |
| 2868 | |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2869 | // If this is not a direct-initializer, we only need to reconstruct |
| 2870 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 2871 | // the initializer is already the right type. |
| 2872 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 2873 | if (!CXXDirectInit && !(Construct && Construct->isListInitialization())) |
| 2874 | return getDerived().TransformExpr(Init); |
| 2875 | |
| 2876 | // Revert value-initialization back to empty parens. |
| 2877 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 2878 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2879 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2880 | Parens.getEnd()); |
| 2881 | } |
| 2882 | |
| 2883 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 2884 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2885 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2886 | SourceLocation()); |
| 2887 | |
| 2888 | // Revert initialization by constructor back to a parenthesized or braced list |
| 2889 | // of expressions. Any other form of initializer can just be reused directly. |
| 2890 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2891 | return getDerived().TransformExpr(Init); |
| 2892 | |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2893 | // If the initialization implicitly converted an initializer list to a |
| 2894 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 2895 | if (Construct && Construct->isStdInitListInitialization()) |
| 2896 | return TransformInitializer(Construct->getArg(0), CXXDirectInit); |
| 2897 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2898 | SmallVector<Expr*, 8> NewArgs; |
| 2899 | bool ArgChanged = false; |
| 2900 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 2901 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| 2902 | return ExprError(); |
| 2903 | |
| 2904 | // If this was list initialization, revert to list form. |
| 2905 | if (Construct->isListInitialization()) |
| 2906 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 2907 | Construct->getLocEnd(), |
| 2908 | Construct->getType()); |
| 2909 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2910 | // Build a ParenListExpr to represent anything else. |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 2911 | SourceRange Parens = Construct->getParenOrBraceRange(); |
Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 2912 | if (Parens.isInvalid()) { |
| 2913 | // This was a variable declaration's initialization for which no initializer |
| 2914 | // was specified. |
| 2915 | assert(NewArgs.empty() && |
| 2916 | "no parens or braces but have direct init with arguments?"); |
| 2917 | return ExprEmpty(); |
| 2918 | } |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2919 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 2920 | Parens.getEnd()); |
| 2921 | } |
| 2922 | |
| 2923 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2924 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2925 | unsigned NumInputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2926 | bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2927 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2928 | bool *ArgChanged) { |
| 2929 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2930 | // If requested, drop call arguments that need to be dropped. |
| 2931 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2932 | if (ArgChanged) |
| 2933 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2934 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2935 | break; |
| 2936 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2937 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2938 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2939 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2940 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2941 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2942 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2943 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2944 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2945 | // Determine whether the set of unexpanded parameter packs can and should |
| 2946 | // be expanded. |
| 2947 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2948 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2949 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 2950 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2951 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2952 | Pattern->getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2953 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2954 | Expand, RetainExpansion, |
| 2955 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2956 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2957 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2958 | if (!Expand) { |
| 2959 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2960 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2961 | // expansion. |
| 2962 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2963 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2964 | if (OutPattern.isInvalid()) |
| 2965 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2966 | |
| 2967 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2968 | Expansion->getEllipsisLoc(), |
| 2969 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2970 | if (Out.isInvalid()) |
| 2971 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2972 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2973 | if (ArgChanged) |
| 2974 | *ArgChanged = true; |
| 2975 | Outputs.push_back(Out.get()); |
| 2976 | continue; |
| 2977 | } |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2978 | |
| 2979 | // Record right away that the argument was changed. This needs |
| 2980 | // to happen even if the array expands to nothing. |
| 2981 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2982 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2983 | // The transform has determined that we should perform an elementwise |
| 2984 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2985 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2986 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2987 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2988 | if (Out.isInvalid()) |
| 2989 | return true; |
| 2990 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 2991 | // FIXME: Can this happen? We should not try to expand the pack |
| 2992 | // in this case. |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2993 | if (Out.get()->containsUnexpandedParameterPack()) { |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 2994 | Out = getDerived().RebuildPackExpansion( |
| 2995 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2996 | if (Out.isInvalid()) |
| 2997 | return true; |
| 2998 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2999 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3000 | Outputs.push_back(Out.get()); |
| 3001 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3002 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3003 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3004 | // forgetting the partially-substituted parameter pack. |
| 3005 | if (RetainExpansion) { |
| 3006 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3007 | |
| 3008 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3009 | if (Out.isInvalid()) |
| 3010 | return true; |
| 3011 | |
| 3012 | Out = getDerived().RebuildPackExpansion( |
| 3013 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3014 | if (Out.isInvalid()) |
| 3015 | return true; |
| 3016 | |
| 3017 | Outputs.push_back(Out.get()); |
| 3018 | } |
| 3019 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3020 | continue; |
| 3021 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3022 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3023 | ExprResult Result = |
| 3024 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3025 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3026 | if (Result.isInvalid()) |
| 3027 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3028 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3029 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3030 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3031 | |
| 3032 | Outputs.push_back(Result.get()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3033 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3034 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3035 | return false; |
| 3036 | } |
| 3037 | |
| 3038 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3039 | NestedNameSpecifierLoc |
| 3040 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3041 | NestedNameSpecifierLoc NNS, |
| 3042 | QualType ObjectType, |
| 3043 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3044 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3045 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3046 | Qualifier = Qualifier.getPrefix()) |
| 3047 | Qualifiers.push_back(Qualifier); |
| 3048 | |
| 3049 | CXXScopeSpec SS; |
| 3050 | while (!Qualifiers.empty()) { |
| 3051 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3052 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3053 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3054 | switch (QNNS->getKind()) { |
| 3055 | case NestedNameSpecifier::Identifier: |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3056 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3057 | *QNNS->getAsIdentifier(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3058 | Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3059 | Q.getLocalEndLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3060 | ObjectType, false, SS, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3061 | FirstQualifierInScope, false)) |
| 3062 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3063 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3064 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3065 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3066 | case NestedNameSpecifier::Namespace: { |
| 3067 | NamespaceDecl *NS |
| 3068 | = cast_or_null<NamespaceDecl>( |
| 3069 | getDerived().TransformDecl( |
| 3070 | Q.getLocalBeginLoc(), |
| 3071 | QNNS->getAsNamespace())); |
| 3072 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3073 | break; |
| 3074 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3075 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3076 | case NestedNameSpecifier::NamespaceAlias: { |
| 3077 | NamespaceAliasDecl *Alias |
| 3078 | = cast_or_null<NamespaceAliasDecl>( |
| 3079 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3080 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3081 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3082 | Q.getLocalEndLoc()); |
| 3083 | break; |
| 3084 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3085 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3086 | case NestedNameSpecifier::Global: |
| 3087 | // There is no meaningful transformation that one could perform on the |
| 3088 | // global scope. |
| 3089 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3090 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3091 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3092 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3093 | case NestedNameSpecifier::TypeSpec: { |
| 3094 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3095 | FirstQualifierInScope, SS); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3096 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3097 | if (!TL) |
| 3098 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3099 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3100 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3101 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3102 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3103 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3104 | "Can't get cv-qualifiers here"); |
Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3105 | if (TL.getType()->isEnumeralType()) |
| 3106 | SemaRef.Diag(TL.getBeginLoc(), |
| 3107 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3108 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3109 | Q.getLocalEndLoc()); |
| 3110 | break; |
| 3111 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3112 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3113 | // error because a previous error should have already been emitted. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3114 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3115 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3116 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3117 | << TL.getType() << SS.getRange(); |
| 3118 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3119 | return NestedNameSpecifierLoc(); |
| 3120 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3121 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3122 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3123 | // The qualifier-in-scope and object type only apply to the leftmost entity. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3124 | FirstQualifierInScope = nullptr; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3125 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3126 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3127 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3128 | // Don't rebuild the nested-name-specifier if we don't have to. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3129 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3130 | !getDerived().AlwaysRebuild()) |
| 3131 | return NNS; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3132 | |
| 3133 | // If we can re-use the source-location data from the original |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3134 | // nested-name-specifier, do so. |
| 3135 | if (SS.location_size() == NNS.getDataLength() && |
| 3136 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3137 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3138 | |
| 3139 | // Allocate new nested-name-specifier location information. |
| 3140 | return SS.getWithLocInContext(SemaRef.Context); |
| 3141 | } |
| 3142 | |
| 3143 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3144 | DeclarationNameInfo |
| 3145 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3146 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3147 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3148 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3149 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3150 | |
| 3151 | switch (Name.getNameKind()) { |
| 3152 | case DeclarationName::Identifier: |
| 3153 | case DeclarationName::ObjCZeroArgSelector: |
| 3154 | case DeclarationName::ObjCOneArgSelector: |
| 3155 | case DeclarationName::ObjCMultiArgSelector: |
| 3156 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3157 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3158 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3159 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3160 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3161 | case DeclarationName::CXXConstructorName: |
| 3162 | case DeclarationName::CXXDestructorName: |
| 3163 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3164 | TypeSourceInfo *NewTInfo; |
| 3165 | CanQualType NewCanTy; |
| 3166 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3167 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3168 | if (!NewTInfo) |
| 3169 | return DeclarationNameInfo(); |
| 3170 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3171 | } |
| 3172 | else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3173 | NewTInfo = nullptr; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3174 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3175 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3176 | if (NewT.isNull()) |
| 3177 | return DeclarationNameInfo(); |
| 3178 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3179 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3180 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3181 | DeclarationName NewName |
| 3182 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3183 | NewCanTy); |
| 3184 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3185 | NewNameInfo.setName(NewName); |
| 3186 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3187 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3191 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3195 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3196 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3197 | TemplateName Name, |
| 3198 | SourceLocation NameLoc, |
| 3199 | QualType ObjectType, |
| 3200 | NamedDecl *FirstQualifierInScope) { |
| 3201 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3202 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3203 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3205 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3206 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3207 | Template)); |
| 3208 | if (!TransTemplate) |
| 3209 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3210 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3211 | if (!getDerived().AlwaysRebuild() && |
| 3212 | SS.getScopeRep() == QTN->getQualifier() && |
| 3213 | TransTemplate == Template) |
| 3214 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3215 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3216 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3217 | TransTemplate); |
| 3218 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3219 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3220 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3221 | if (SS.getScopeRep()) { |
| 3222 | // These apply to the scope specifier, not the template. |
| 3223 | ObjectType = QualType(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3224 | FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3227 | if (!getDerived().AlwaysRebuild() && |
| 3228 | SS.getScopeRep() == DTN->getQualifier() && |
| 3229 | ObjectType.isNull()) |
| 3230 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3231 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3232 | if (DTN->isIdentifier()) { |
| 3233 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3234 | *DTN->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3235 | NameLoc, |
| 3236 | ObjectType, |
| 3237 | FirstQualifierInScope); |
| 3238 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3239 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3240 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3241 | ObjectType); |
| 3242 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3243 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3244 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3245 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3246 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3247 | Template)); |
| 3248 | if (!TransTemplate) |
| 3249 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3251 | if (!getDerived().AlwaysRebuild() && |
| 3252 | TransTemplate == Template) |
| 3253 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3255 | return TemplateName(TransTemplate); |
| 3256 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3257 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3258 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3259 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3260 | TemplateTemplateParmDecl *TransParam |
| 3261 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3262 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3263 | if (!TransParam) |
| 3264 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3265 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3266 | if (!getDerived().AlwaysRebuild() && |
| 3267 | TransParam == SubstPack->getParameterPack()) |
| 3268 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3269 | |
| 3270 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3271 | SubstPack->getArgumentPack()); |
| 3272 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3273 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3274 | // These should be getting filtered out before they reach the AST. |
| 3275 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3279 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3280 | const TemplateArgument &Arg, |
| 3281 | TemplateArgumentLoc &Output) { |
| 3282 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3283 | switch (Arg.getKind()) { |
| 3284 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3285 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3286 | break; |
| 3287 | |
| 3288 | case TemplateArgument::Type: |
| 3289 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3290 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3291 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3292 | break; |
| 3293 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3294 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3295 | case TemplateArgument::TemplateExpansion: { |
| 3296 | NestedNameSpecifierLocBuilder Builder; |
| 3297 | TemplateName Template = Arg.getAsTemplate(); |
| 3298 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3299 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3300 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3301 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3302 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3303 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3304 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3305 | Builder.getWithLocInContext(SemaRef.Context), |
| 3306 | Loc); |
| 3307 | else |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3308 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3309 | Builder.getWithLocInContext(SemaRef.Context), |
| 3310 | Loc, Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3311 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3312 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3313 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3314 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3315 | case TemplateArgument::Expression: |
| 3316 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3317 | break; |
| 3318 | |
| 3319 | case TemplateArgument::Declaration: |
| 3320 | case TemplateArgument::Integral: |
| 3321 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3322 | case TemplateArgument::NullPtr: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3323 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3324 | break; |
| 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | template<typename Derived> |
| 3329 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3330 | const TemplateArgumentLoc &Input, |
| 3331 | TemplateArgumentLoc &Output) { |
| 3332 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3333 | switch (Arg.getKind()) { |
| 3334 | case TemplateArgument::Null: |
| 3335 | case TemplateArgument::Integral: |
Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3336 | case TemplateArgument::Pack: |
| 3337 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3338 | case TemplateArgument::NullPtr: |
| 3339 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3340 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3341 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3342 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3343 | if (!DI) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3344 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3345 | |
| 3346 | DI = getDerived().TransformType(DI); |
| 3347 | if (!DI) return true; |
| 3348 | |
| 3349 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3350 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3351 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3353 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3354 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3355 | if (QualifierLoc) { |
| 3356 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3357 | if (!QualifierLoc) |
| 3358 | return true; |
| 3359 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3360 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3361 | CXXScopeSpec SS; |
| 3362 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3363 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3364 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3365 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3366 | if (Template.isNull()) |
| 3367 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3368 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3369 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3370 | Input.getTemplateNameLoc()); |
| 3371 | return false; |
| 3372 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3373 | |
| 3374 | case TemplateArgument::TemplateExpansion: |
| 3375 | llvm_unreachable("Caller should expand pack expansions"); |
| 3376 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3377 | case TemplateArgument::Expression: { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3378 | // Template argument expressions are constant expressions. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3379 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3380 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3381 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3382 | Expr *InputExpr = Input.getSourceExpression(); |
| 3383 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3384 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3385 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3386 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3387 | if (E.isInvalid()) return true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3388 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3389 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3390 | } |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3392 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3393 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3394 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3397 | /// \brief Iterator adaptor that invents template argument location information |
| 3398 | /// for each of the template arguments in its underlying iterator. |
| 3399 | template<typename Derived, typename InputIterator> |
| 3400 | class TemplateArgumentLocInventIterator { |
| 3401 | TreeTransform<Derived> &Self; |
| 3402 | InputIterator Iter; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3403 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3404 | public: |
| 3405 | typedef TemplateArgumentLoc value_type; |
| 3406 | typedef TemplateArgumentLoc reference; |
| 3407 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3408 | difference_type; |
| 3409 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3410 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3411 | class pointer { |
| 3412 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3413 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3414 | public: |
| 3415 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3416 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3417 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3418 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3419 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3420 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3421 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3422 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3423 | InputIterator Iter) |
| 3424 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3425 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3426 | TemplateArgumentLocInventIterator &operator++() { |
| 3427 | ++Iter; |
| 3428 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3429 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3430 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3431 | TemplateArgumentLocInventIterator operator++(int) { |
| 3432 | TemplateArgumentLocInventIterator Old(*this); |
| 3433 | ++(*this); |
| 3434 | return Old; |
| 3435 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3436 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3437 | reference operator*() const { |
| 3438 | TemplateArgumentLoc Result; |
| 3439 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3440 | return Result; |
| 3441 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3442 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3443 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3444 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3445 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3446 | const TemplateArgumentLocInventIterator &Y) { |
| 3447 | return X.Iter == Y.Iter; |
| 3448 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3449 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3450 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3451 | const TemplateArgumentLocInventIterator &Y) { |
| 3452 | return X.Iter != Y.Iter; |
| 3453 | } |
| 3454 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3455 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3456 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3457 | template<typename InputIterator> |
| 3458 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3459 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3460 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3461 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3462 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3463 | TemplateArgumentLoc In = *First; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3464 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3465 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3466 | // Unpack argument packs, which we translate them into separate |
| 3467 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3468 | // FIXME: We could do much better if we could guarantee that the |
| 3469 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3470 | // all of the template arguments in the argument pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3471 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3472 | TemplateArgument::pack_iterator> |
| 3473 | PackLocIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3474 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3475 | In.getArgument().pack_begin()), |
| 3476 | PackLocIterator(*this, |
| 3477 | In.getArgument().pack_end()), |
| 3478 | Outputs)) |
| 3479 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3480 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3481 | continue; |
| 3482 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3483 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3484 | if (In.getArgument().isPackExpansion()) { |
| 3485 | // We have a pack expansion, for which we will be substituting into |
| 3486 | // the pattern. |
| 3487 | SourceLocation Ellipsis; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3488 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3489 | TemplateArgumentLoc Pattern |
Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3490 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3491 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3492 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3493 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3494 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3495 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3496 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3497 | // Determine whether the set of unexpanded parameter packs can and should |
| 3498 | // be expanded. |
| 3499 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3500 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3501 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3502 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3503 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3504 | Unexpanded, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3505 | Expand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3506 | RetainExpansion, |
| 3507 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3508 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3509 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3510 | if (!Expand) { |
| 3511 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3512 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3513 | // expansion. |
| 3514 | TemplateArgumentLoc OutPattern; |
| 3515 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3516 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3517 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3518 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3519 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3520 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3521 | if (Out.getArgument().isNull()) |
| 3522 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3524 | Outputs.addArgument(Out); |
| 3525 | continue; |
| 3526 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3527 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3528 | // The transform has determined that we should perform an elementwise |
| 3529 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3530 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3531 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3532 | |
| 3533 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3534 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3535 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3536 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3537 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3538 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3539 | if (Out.getArgument().isNull()) |
| 3540 | return true; |
| 3541 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3542 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3543 | Outputs.addArgument(Out); |
| 3544 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3545 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3546 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3547 | // forgetting the partially-substituted parameter pack. |
| 3548 | if (RetainExpansion) { |
| 3549 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3550 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3551 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3552 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3553 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3554 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3555 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3556 | if (Out.getArgument().isNull()) |
| 3557 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3558 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3559 | Outputs.addArgument(Out); |
| 3560 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3561 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3562 | continue; |
| 3563 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3564 | |
| 3565 | // The simple case: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3566 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3567 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3568 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3569 | Outputs.addArgument(Out); |
| 3570 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3571 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3572 | return false; |
| 3573 | |
| 3574 | } |
| 3575 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3576 | //===----------------------------------------------------------------------===// |
| 3577 | // Type transformation |
| 3578 | //===----------------------------------------------------------------------===// |
| 3579 | |
| 3580 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3581 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3582 | if (getDerived().AlreadyTransformed(T)) |
| 3583 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3584 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3585 | // Temporary workaround. All of these transformations should |
| 3586 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3587 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3588 | getDerived().getBaseLocation()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3589 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3590 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3591 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3592 | if (!NewDI) |
| 3593 | return QualType(); |
| 3594 | |
| 3595 | return NewDI->getType(); |
| 3596 | } |
| 3597 | |
| 3598 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3599 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3600 | // Refine the base location to the type's location. |
| 3601 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3602 | getDerived().getBaseEntity()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3603 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3604 | return DI; |
| 3605 | |
| 3606 | TypeLocBuilder TLB; |
| 3607 | |
| 3608 | TypeLoc TL = DI->getTypeLoc(); |
| 3609 | TLB.reserve(TL.getFullDataSize()); |
| 3610 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3611 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3612 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3613 | return nullptr; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3614 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3615 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | template<typename Derived> |
| 3619 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3620 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3621 | switch (T.getTypeLocClass()) { |
| 3622 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3623 | #define TYPELOC(CLASS, PARENT) \ |
| 3624 | case TypeLoc::CLASS: \ |
| 3625 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3626 | T.castAs<CLASS##TypeLoc>()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3627 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3628 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3629 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3630 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3634 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3635 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3636 | /// types). This is the right thing for template instantiation, but |
| 3637 | /// probably not for other clients. |
| 3638 | template<typename Derived> |
| 3639 | QualType |
| 3640 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3641 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3642 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3643 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3644 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3645 | if (Result.isNull()) |
| 3646 | return QualType(); |
| 3647 | |
| 3648 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3649 | // FIXME: this is the right thing for template instantiation, but |
| 3650 | // probably not for other clients. |
| 3651 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3652 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3654 | // Suppress Objective-C lifetime qualifiers if they don't make sense for the |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3655 | // resulting type. |
| 3656 | if (Quals.hasObjCLifetime()) { |
| 3657 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3658 | Quals.removeObjCLifetime(); |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3659 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3660 | // Objective-C ARC: |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3661 | // A lifetime qualifier applied to a substituted template parameter |
| 3662 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3663 | const AutoType *AutoTy; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3664 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3665 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3666 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3667 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3668 | Qs.removeObjCLifetime(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3669 | Replacement |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3670 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3671 | Qs); |
| 3672 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3673 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3674 | Replacement); |
| 3675 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3676 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3677 | // 'auto' types behave the same way as template parameters. |
| 3678 | QualType Deduced = AutoTy->getDeducedType(); |
| 3679 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3680 | Qs.removeObjCLifetime(); |
| 3681 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3682 | Qs); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 3683 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(), |
| 3684 | AutoTy->isDependentType()); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3685 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3686 | } else { |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3687 | // Otherwise, complain about the addition of a qualifier to an |
| 3688 | // already-qualified type. |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3689 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3690 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3691 | << Result << R; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3692 | |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3693 | Quals.removeObjCLifetime(); |
| 3694 | } |
| 3695 | } |
| 3696 | } |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3697 | if (!Quals.empty()) { |
| 3698 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3699 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3700 | if (Result.hasLocalQualifiers()) |
| 3701 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3702 | // No location information to preserve. |
| 3703 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3704 | |
| 3705 | return Result; |
| 3706 | } |
| 3707 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3708 | template<typename Derived> |
| 3709 | TypeLoc |
| 3710 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3711 | QualType ObjectType, |
| 3712 | NamedDecl *UnqualLookup, |
| 3713 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3714 | if (getDerived().AlreadyTransformed(TL.getType())) |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3715 | return TL; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3716 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3717 | TypeSourceInfo *TSI = |
| 3718 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 3719 | if (TSI) |
| 3720 | return TSI->getTypeLoc(); |
| 3721 | return TypeLoc(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3724 | template<typename Derived> |
| 3725 | TypeSourceInfo * |
| 3726 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3727 | QualType ObjectType, |
| 3728 | NamedDecl *UnqualLookup, |
| 3729 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3730 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3731 | return TSInfo; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3732 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3733 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 3734 | UnqualLookup, SS); |
| 3735 | } |
| 3736 | |
| 3737 | template <typename Derived> |
| 3738 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 3739 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 3740 | CXXScopeSpec &SS) { |
| 3741 | QualType T = TL.getType(); |
| 3742 | assert(!getDerived().AlreadyTransformed(T)); |
| 3743 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3744 | TypeLocBuilder TLB; |
| 3745 | QualType Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3746 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3747 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3748 | TemplateSpecializationTypeLoc SpecTL = |
| 3749 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3750 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3751 | TemplateName Template |
| 3752 | = getDerived().TransformTemplateName(SS, |
| 3753 | SpecTL.getTypePtr()->getTemplateName(), |
| 3754 | SpecTL.getTemplateNameLoc(), |
| 3755 | ObjectType, UnqualLookup); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3756 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3757 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3758 | |
| 3759 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3760 | Template); |
| 3761 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3762 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3763 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3764 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3765 | TemplateName Template |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3766 | = getDerived().RebuildTemplateName(SS, |
| 3767 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3768 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3769 | ObjectType, UnqualLookup); |
| 3770 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3771 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3772 | |
| 3773 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3774 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3775 | Template, |
| 3776 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3777 | } else { |
| 3778 | // Nothing special needs to be done for these. |
| 3779 | Result = getDerived().TransformType(TLB, TL); |
| 3780 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3781 | |
| 3782 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3783 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3784 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3785 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3786 | } |
| 3787 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3788 | template <class TyLoc> static inline |
| 3789 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3790 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3791 | NewT.setNameLoc(T.getNameLoc()); |
| 3792 | return T.getType(); |
| 3793 | } |
| 3794 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3795 | template<typename Derived> |
| 3796 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3797 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3798 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3799 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3800 | if (T.needsExtraLocalData()) |
| 3801 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3802 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3804 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3805 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3806 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3807 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3808 | // FIXME: recurse? |
| 3809 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3812 | template <typename Derived> |
| 3813 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 3814 | AdjustedTypeLoc TL) { |
| 3815 | // Adjustments applied during transformation are handled elsewhere. |
| 3816 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3817 | } |
| 3818 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3819 | template<typename Derived> |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 3820 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 3821 | DecayedTypeLoc TL) { |
| 3822 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3823 | if (OriginalType.isNull()) |
| 3824 | return QualType(); |
| 3825 | |
| 3826 | QualType Result = TL.getType(); |
| 3827 | if (getDerived().AlwaysRebuild() || |
| 3828 | OriginalType != TL.getOriginalLoc().getType()) |
| 3829 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 3830 | TLB.push<DecayedTypeLoc>(Result); |
| 3831 | // Nothing to set for DecayedTypeLoc. |
| 3832 | return Result; |
| 3833 | } |
| 3834 | |
| 3835 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3836 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3837 | PointerTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3838 | QualType PointeeType |
| 3839 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3840 | if (PointeeType.isNull()) |
| 3841 | return QualType(); |
| 3842 | |
| 3843 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3844 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3845 | // A dependent pointer type 'T *' has is being transformed such |
| 3846 | // that an Objective-C class type is being replaced for 'T'. The |
| 3847 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3848 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3849 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3850 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3851 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3852 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3853 | return Result; |
| 3854 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3855 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3856 | if (getDerived().AlwaysRebuild() || |
| 3857 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3858 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3859 | if (Result.isNull()) |
| 3860 | return QualType(); |
| 3861 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3862 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3863 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3864 | // pointing to. |
| 3865 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3866 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3867 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3868 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3869 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | |
| 3872 | template<typename Derived> |
| 3873 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3874 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3875 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3876 | QualType PointeeType |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3877 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3878 | if (PointeeType.isNull()) |
| 3879 | return QualType(); |
| 3880 | |
| 3881 | QualType Result = TL.getType(); |
| 3882 | if (getDerived().AlwaysRebuild() || |
| 3883 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3884 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3885 | TL.getSigilLoc()); |
| 3886 | if (Result.isNull()) |
| 3887 | return QualType(); |
| 3888 | } |
| 3889 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3890 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3891 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3892 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3893 | } |
| 3894 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3895 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3896 | /// don't care whether the type itself is an l-value type or an r-value |
| 3897 | /// type; we only care if the type was *written* as an l-value type |
| 3898 | /// or an r-value type. |
| 3899 | template<typename Derived> |
| 3900 | QualType |
| 3901 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3902 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3903 | const ReferenceType *T = TL.getTypePtr(); |
| 3904 | |
| 3905 | // Note that this works with the pointee-as-written. |
| 3906 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3907 | if (PointeeType.isNull()) |
| 3908 | return QualType(); |
| 3909 | |
| 3910 | QualType Result = TL.getType(); |
| 3911 | if (getDerived().AlwaysRebuild() || |
| 3912 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3913 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3914 | T->isSpelledAsLValue(), |
| 3915 | TL.getSigilLoc()); |
| 3916 | if (Result.isNull()) |
| 3917 | return QualType(); |
| 3918 | } |
| 3919 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3920 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3921 | // referring to. |
| 3922 | TLB.TypeWasModifiedSafely( |
| 3923 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3924 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3925 | // r-value references can be rebuilt as l-value references. |
| 3926 | ReferenceTypeLoc NewTL; |
| 3927 | if (isa<LValueReferenceType>(Result)) |
| 3928 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3929 | else |
| 3930 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3931 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3932 | |
| 3933 | return Result; |
| 3934 | } |
| 3935 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3936 | template<typename Derived> |
| 3937 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3938 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3939 | LValueReferenceTypeLoc TL) { |
| 3940 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3941 | } |
| 3942 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3943 | template<typename Derived> |
| 3944 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3945 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3946 | RValueReferenceTypeLoc TL) { |
| 3947 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3949 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3950 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3951 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3952 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3953 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3954 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3955 | if (PointeeType.isNull()) |
| 3956 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3957 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3958 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3959 | TypeSourceInfo *NewClsTInfo = nullptr; |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3960 | if (OldClsTInfo) { |
| 3961 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3962 | if (!NewClsTInfo) |
| 3963 | return QualType(); |
| 3964 | } |
| 3965 | |
| 3966 | const MemberPointerType *T = TL.getTypePtr(); |
| 3967 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3968 | QualType NewClsType; |
| 3969 | if (NewClsTInfo) |
| 3970 | NewClsType = NewClsTInfo->getType(); |
| 3971 | else { |
| 3972 | NewClsType = getDerived().TransformType(OldClsType); |
| 3973 | if (NewClsType.isNull()) |
| 3974 | return QualType(); |
| 3975 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3977 | QualType Result = TL.getType(); |
| 3978 | if (getDerived().AlwaysRebuild() || |
| 3979 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3980 | NewClsType != OldClsType) { |
| 3981 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3982 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3983 | if (Result.isNull()) |
| 3984 | return QualType(); |
| 3985 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3986 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3987 | // If we had to adjust the pointee type when building a member pointer, make |
| 3988 | // sure to push TypeLoc info for it. |
| 3989 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 3990 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 3991 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 3992 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 3993 | } |
| 3994 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3995 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3996 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3997 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3998 | |
| 3999 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4000 | } |
| 4001 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4002 | template<typename Derived> |
| 4003 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4004 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4005 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4006 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4007 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4008 | if (ElementType.isNull()) |
| 4009 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4010 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4011 | QualType Result = TL.getType(); |
| 4012 | if (getDerived().AlwaysRebuild() || |
| 4013 | ElementType != T->getElementType()) { |
| 4014 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4015 | T->getSizeModifier(), |
| 4016 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4017 | T->getIndexTypeCVRQualifiers(), |
| 4018 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4019 | if (Result.isNull()) |
| 4020 | return QualType(); |
| 4021 | } |
Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4022 | |
| 4023 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4024 | // a ConstantArrayType is allowed to have an element type which is a |
| 4025 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4026 | // types have the same location layout. |
| 4027 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4028 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4029 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4030 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4031 | Expr *Size = TL.getSizeExpr(); |
| 4032 | if (Size) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4033 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4034 | Sema::ConstantEvaluated); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4035 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4036 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4037 | } |
| 4038 | NewTL.setSizeExpr(Size); |
| 4039 | |
| 4040 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4041 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4042 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4043 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4044 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4045 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4046 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4047 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4048 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4049 | if (ElementType.isNull()) |
| 4050 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4051 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4052 | QualType Result = TL.getType(); |
| 4053 | if (getDerived().AlwaysRebuild() || |
| 4054 | ElementType != T->getElementType()) { |
| 4055 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4056 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4057 | T->getIndexTypeCVRQualifiers(), |
| 4058 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4059 | if (Result.isNull()) |
| 4060 | return QualType(); |
| 4061 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4062 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4063 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4064 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4065 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4066 | NewTL.setSizeExpr(nullptr); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4067 | |
| 4068 | return Result; |
| 4069 | } |
| 4070 | |
| 4071 | template<typename Derived> |
| 4072 | QualType |
| 4073 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4074 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4075 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4076 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4077 | if (ElementType.isNull()) |
| 4078 | return QualType(); |
| 4079 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4080 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4081 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 4082 | if (SizeResult.isInvalid()) |
| 4083 | return QualType(); |
| 4084 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4085 | Expr *Size = SizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4086 | |
| 4087 | QualType Result = TL.getType(); |
| 4088 | if (getDerived().AlwaysRebuild() || |
| 4089 | ElementType != T->getElementType() || |
| 4090 | Size != T->getSizeExpr()) { |
| 4091 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4092 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4093 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4094 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4095 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4096 | if (Result.isNull()) |
| 4097 | return QualType(); |
| 4098 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4099 | |
Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4100 | // We might have constant size array now, but fortunately it has the same |
| 4101 | // location layout. |
| 4102 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4103 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4104 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4105 | NewTL.setSizeExpr(Size); |
| 4106 | |
| 4107 | return Result; |
| 4108 | } |
| 4109 | |
| 4110 | template<typename Derived> |
| 4111 | QualType |
| 4112 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4113 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4114 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4115 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4116 | if (ElementType.isNull()) |
| 4117 | return QualType(); |
| 4118 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4119 | // Array bounds are constant expressions. |
| 4120 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4121 | Sema::ConstantEvaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4122 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4123 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4124 | Expr *origSize = TL.getSizeExpr(); |
| 4125 | if (!origSize) origSize = T->getSizeExpr(); |
| 4126 | |
| 4127 | ExprResult sizeResult |
| 4128 | = getDerived().TransformExpr(origSize); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4129 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4130 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4131 | return QualType(); |
| 4132 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4133 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4134 | |
| 4135 | QualType Result = TL.getType(); |
| 4136 | if (getDerived().AlwaysRebuild() || |
| 4137 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4138 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4139 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4140 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4141 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4142 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4143 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4144 | if (Result.isNull()) |
| 4145 | return QualType(); |
| 4146 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4147 | |
| 4148 | // We might have any sort of array type now, but fortunately they |
| 4149 | // all have the same location layout. |
| 4150 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4151 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4152 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4153 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4154 | |
| 4155 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4156 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4157 | |
| 4158 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4159 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4160 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4161 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4162 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4163 | |
| 4164 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4165 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4166 | if (ElementType.isNull()) |
| 4167 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4169 | // Vector sizes are constant expressions. |
| 4170 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4171 | Sema::ConstantEvaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4172 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4173 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4174 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4175 | if (Size.isInvalid()) |
| 4176 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4178 | QualType Result = TL.getType(); |
| 4179 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4180 | ElementType != T->getElementType() || |
| 4181 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4182 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4183 | Size.get(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4184 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4185 | if (Result.isNull()) |
| 4186 | return QualType(); |
| 4187 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4188 | |
| 4189 | // Result might be dependent or not. |
| 4190 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4191 | DependentSizedExtVectorTypeLoc NewTL |
| 4192 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4193 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4194 | } else { |
| 4195 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4196 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4197 | } |
| 4198 | |
| 4199 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4200 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | |
| 4202 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4203 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4204 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4205 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4206 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4207 | if (ElementType.isNull()) |
| 4208 | return QualType(); |
| 4209 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4210 | QualType Result = TL.getType(); |
| 4211 | if (getDerived().AlwaysRebuild() || |
| 4212 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4213 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4214 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4215 | if (Result.isNull()) |
| 4216 | return QualType(); |
| 4217 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4218 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4219 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4220 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4221 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4222 | return Result; |
| 4223 | } |
| 4224 | |
| 4225 | template<typename Derived> |
| 4226 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4227 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4228 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4229 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4230 | if (ElementType.isNull()) |
| 4231 | return QualType(); |
| 4232 | |
| 4233 | QualType Result = TL.getType(); |
| 4234 | if (getDerived().AlwaysRebuild() || |
| 4235 | ElementType != T->getElementType()) { |
| 4236 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4237 | T->getNumElements(), |
| 4238 | /*FIXME*/ SourceLocation()); |
| 4239 | if (Result.isNull()) |
| 4240 | return QualType(); |
| 4241 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4242 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4243 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4244 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4245 | |
| 4246 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4247 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4248 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4249 | template <typename Derived> |
| 4250 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4251 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4252 | bool ExpectParameterPack) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4253 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4254 | TypeSourceInfo *NewDI = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4255 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4256 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4257 | // If we're substituting into a pack expansion type and we know the |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4258 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4259 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4260 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4261 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4262 | TypeLocBuilder TLB; |
| 4263 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4264 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4265 | |
| 4266 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4267 | OldExpansionTL.getPatternLoc()); |
| 4268 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4269 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4270 | |
| 4271 | Result = RebuildPackExpansionType(Result, |
| 4272 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4273 | OldExpansionTL.getEllipsisLoc(), |
| 4274 | NumExpansions); |
| 4275 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4276 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4277 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4278 | PackExpansionTypeLoc NewExpansionTL |
| 4279 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4280 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4281 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4282 | } else |
| 4283 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4284 | if (!NewDI) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4285 | return nullptr; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4286 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4287 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4288 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4289 | |
| 4290 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4291 | OldParm->getDeclContext(), |
| 4292 | OldParm->getInnerLocStart(), |
| 4293 | OldParm->getLocation(), |
| 4294 | OldParm->getIdentifier(), |
| 4295 | NewDI->getType(), |
| 4296 | NewDI, |
| 4297 | OldParm->getStorageClass(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4298 | /* DefArg */ nullptr); |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4299 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4300 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4301 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | template<typename Derived> |
| 4305 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4306 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4307 | ParmVarDecl **Params, unsigned NumParams, |
| 4308 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4309 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4310 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4311 | int indexAdjustment = 0; |
| 4312 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4313 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4314 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4315 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4316 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4317 | Optional<unsigned> NumExpansions; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4318 | ParmVarDecl *NewParm = nullptr; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4319 | if (OldParm->isParameterPack()) { |
| 4320 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4321 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4322 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4323 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4324 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4325 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4326 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4327 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4328 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4329 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4330 | // Determine whether we should expand the parameter packs. |
| 4331 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4332 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4333 | Optional<unsigned> OrigNumExpansions = |
| 4334 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4335 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4336 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4337 | Pattern.getSourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4338 | Unexpanded, |
| 4339 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4340 | RetainExpansion, |
| 4341 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4342 | return true; |
| 4343 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4344 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4345 | if (ShouldExpand) { |
| 4346 | // Expand the function parameter pack into multiple, separate |
| 4347 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4348 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4349 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4350 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4351 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4352 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4353 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4354 | OrigNumExpansions, |
| 4355 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4356 | if (!NewParm) |
| 4357 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4358 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4359 | OutParamTypes.push_back(NewParm->getType()); |
| 4360 | if (PVars) |
| 4361 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4362 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4363 | |
| 4364 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4365 | // forgetting the partially-substituted parameter pack. |
| 4366 | if (RetainExpansion) { |
| 4367 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4368 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4369 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4370 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4371 | OrigNumExpansions, |
| 4372 | /*ExpectParameterPack=*/false); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4373 | if (!NewParm) |
| 4374 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4375 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4376 | OutParamTypes.push_back(NewParm->getType()); |
| 4377 | if (PVars) |
| 4378 | PVars->push_back(NewParm); |
| 4379 | } |
| 4380 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4381 | // The next parameter should have the same adjustment as the |
| 4382 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4383 | // on every push. Also, if we push nothing, the adjustment should |
| 4384 | // go down by one. |
| 4385 | indexAdjustment--; |
| 4386 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4387 | // We're done with the pack expansion. |
| 4388 | continue; |
| 4389 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4390 | |
| 4391 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4392 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4393 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4394 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4395 | indexAdjustment, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4396 | NumExpansions, |
| 4397 | /*ExpectParameterPack=*/true); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4398 | } else { |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4399 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4400 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4401 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4402 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4403 | if (!NewParm) |
| 4404 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4406 | OutParamTypes.push_back(NewParm->getType()); |
| 4407 | if (PVars) |
| 4408 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4409 | continue; |
| 4410 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4411 | |
| 4412 | // Deal with the possibility that we don't have a parameter |
| 4413 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4414 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4415 | bool IsPackExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4416 | Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4417 | QualType NewType; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4418 | if (const PackExpansionType *Expansion |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4419 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4420 | // We have a function parameter pack that may need to be expanded. |
| 4421 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4422 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4423 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4424 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4425 | // Determine whether we should expand the parameter packs. |
| 4426 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4427 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4428 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4429 | Unexpanded, |
| 4430 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4431 | RetainExpansion, |
| 4432 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4433 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4434 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4435 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4436 | if (ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4437 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4438 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4439 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4440 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4441 | QualType NewType = getDerived().TransformType(Pattern); |
| 4442 | if (NewType.isNull()) |
| 4443 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4444 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4445 | OutParamTypes.push_back(NewType); |
| 4446 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4447 | PVars->push_back(nullptr); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4448 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4449 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4450 | // We're done with the pack expansion. |
| 4451 | continue; |
| 4452 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4453 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4454 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4455 | // forgetting the partially-substituted parameter pack. |
| 4456 | if (RetainExpansion) { |
| 4457 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4458 | QualType NewType = getDerived().TransformType(Pattern); |
| 4459 | if (NewType.isNull()) |
| 4460 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4461 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4462 | OutParamTypes.push_back(NewType); |
| 4463 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4464 | PVars->push_back(nullptr); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4465 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4466 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4467 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4468 | // expansion. |
| 4469 | OldType = Expansion->getPattern(); |
| 4470 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4471 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4472 | NewType = getDerived().TransformType(OldType); |
| 4473 | } else { |
| 4474 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4475 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4476 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4477 | if (NewType.isNull()) |
| 4478 | return true; |
| 4479 | |
| 4480 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4481 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4482 | NumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4483 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4484 | OutParamTypes.push_back(NewType); |
| 4485 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4486 | PVars->push_back(nullptr); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4489 | #ifndef NDEBUG |
| 4490 | if (PVars) { |
| 4491 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4492 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4493 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4494 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4495 | #endif |
| 4496 | |
| 4497 | return false; |
| 4498 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4499 | |
| 4500 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4501 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4502 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4503 | FunctionProtoTypeLoc TL) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4504 | return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | template<typename Derived> |
| 4508 | QualType |
| 4509 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4510 | FunctionProtoTypeLoc TL, |
| 4511 | CXXRecordDecl *ThisContext, |
| 4512 | unsigned ThisTypeQuals) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4513 | // Transform the parameters and return type. |
| 4514 | // |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4515 | // We are required to instantiate the params and return type in source order. |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4516 | // When the function has a trailing return type, we instantiate the |
| 4517 | // parameters before the return type, since the return type can then refer |
| 4518 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4519 | // |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4520 | SmallVector<QualType, 4> ParamTypes; |
| 4521 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4522 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4523 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4524 | QualType ResultType; |
| 4525 | |
Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4526 | if (T->hasTrailingReturn()) { |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4527 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4528 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4529 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4530 | return QualType(); |
| 4531 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4532 | { |
| 4533 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4534 | // If a declaration declares a member function or member function |
| 4535 | // template of a class X, the expression this is a prvalue of type |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4536 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4537 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4538 | // declarator. |
| 4539 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4540 | |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4541 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4542 | if (ResultType.isNull()) |
| 4543 | return QualType(); |
| 4544 | } |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4545 | } |
| 4546 | else { |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4547 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4548 | if (ResultType.isNull()) |
| 4549 | return QualType(); |
| 4550 | |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4551 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4552 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4553 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4554 | return QualType(); |
| 4555 | } |
| 4556 | |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4557 | // FIXME: Need to transform the exception-specification too. |
| 4558 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4559 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4560 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4561 | T->getNumParams() != ParamTypes.size() || |
| 4562 | !std::equal(T->param_type_begin(), T->param_type_end(), |
| 4563 | ParamTypes.begin())) { |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 4564 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 4565 | T->getExtProtoInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4566 | if (Result.isNull()) |
| 4567 | return QualType(); |
| 4568 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4569 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4570 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4571 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4572 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4573 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4574 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4575 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 4576 | NewTL.setParam(i, ParamDecls[i]); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4577 | |
| 4578 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4579 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4581 | template<typename Derived> |
| 4582 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4583 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4584 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4585 | const FunctionNoProtoType *T = TL.getTypePtr(); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4586 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4587 | if (ResultType.isNull()) |
| 4588 | return QualType(); |
| 4589 | |
| 4590 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4591 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4592 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4593 | |
| 4594 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4595 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4596 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4597 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4598 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4599 | |
| 4600 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4601 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4602 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4603 | template<typename Derived> QualType |
| 4604 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4605 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4606 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4607 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4608 | if (!D) |
| 4609 | return QualType(); |
| 4610 | |
| 4611 | QualType Result = TL.getType(); |
| 4612 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4613 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4614 | if (Result.isNull()) |
| 4615 | return QualType(); |
| 4616 | } |
| 4617 | |
| 4618 | // We might get an arbitrary type spec type back. We should at |
| 4619 | // least always get a type spec type, though. |
| 4620 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4621 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4622 | |
| 4623 | return Result; |
| 4624 | } |
| 4625 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4626 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4627 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4628 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4629 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4630 | TypedefNameDecl *Typedef |
| 4631 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4632 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4633 | if (!Typedef) |
| 4634 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4635 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4636 | QualType Result = TL.getType(); |
| 4637 | if (getDerived().AlwaysRebuild() || |
| 4638 | Typedef != T->getDecl()) { |
| 4639 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4640 | if (Result.isNull()) |
| 4641 | return QualType(); |
| 4642 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4643 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4644 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4645 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4646 | |
| 4647 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4649 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4650 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4651 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4652 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4653 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4654 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4655 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4657 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4658 | if (E.isInvalid()) |
| 4659 | return QualType(); |
| 4660 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4661 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4662 | if (E.isInvalid()) |
| 4663 | return QualType(); |
| 4664 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4665 | QualType Result = TL.getType(); |
| 4666 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4667 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4668 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4669 | if (Result.isNull()) |
| 4670 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4671 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4672 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4673 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4674 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4675 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4676 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4677 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4678 | |
| 4679 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4680 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4681 | |
| 4682 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4683 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4684 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4685 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4686 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4687 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4688 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4689 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4690 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4691 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4692 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4693 | if (Result.isNull()) |
| 4694 | return QualType(); |
| 4695 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4697 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4698 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4699 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4700 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4701 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4702 | |
| 4703 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4704 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4705 | |
| 4706 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4707 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4708 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4709 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4710 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4711 | // decltype expressions are not potentially evaluated contexts |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4712 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4713 | nullptr, /*IsDecltype=*/ true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4714 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4715 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4716 | if (E.isInvalid()) |
| 4717 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4718 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4719 | E = getSema().ActOnDecltypeExpression(E.get()); |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4720 | if (E.isInvalid()) |
| 4721 | return QualType(); |
| 4722 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4723 | QualType Result = TL.getType(); |
| 4724 | if (getDerived().AlwaysRebuild() || |
| 4725 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4726 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4727 | if (Result.isNull()) |
| 4728 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4729 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4730 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4731 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4732 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4733 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4734 | |
| 4735 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4739 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4740 | TypeLocBuilder &TLB, |
| 4741 | UnaryTransformTypeLoc TL) { |
| 4742 | QualType Result = TL.getType(); |
| 4743 | if (Result->isDependentType()) { |
| 4744 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4745 | QualType NewBase = |
| 4746 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4747 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4748 | T->getUTTKind(), |
| 4749 | TL.getKWLoc()); |
| 4750 | if (Result.isNull()) |
| 4751 | return QualType(); |
| 4752 | } |
| 4753 | |
| 4754 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4755 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4756 | NewTL.setParensRange(TL.getParensRange()); |
| 4757 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4758 | return Result; |
| 4759 | } |
| 4760 | |
| 4761 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4762 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4763 | AutoTypeLoc TL) { |
| 4764 | const AutoType *T = TL.getTypePtr(); |
| 4765 | QualType OldDeduced = T->getDeducedType(); |
| 4766 | QualType NewDeduced; |
| 4767 | if (!OldDeduced.isNull()) { |
| 4768 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4769 | if (NewDeduced.isNull()) |
| 4770 | return QualType(); |
| 4771 | } |
| 4772 | |
| 4773 | QualType Result = TL.getType(); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 4774 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 4775 | T->isDependentType()) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 4776 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4777 | if (Result.isNull()) |
| 4778 | return QualType(); |
| 4779 | } |
| 4780 | |
| 4781 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4782 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4783 | |
| 4784 | return Result; |
| 4785 | } |
| 4786 | |
| 4787 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4788 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4789 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4790 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4791 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4792 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4793 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4794 | if (!Record) |
| 4795 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4796 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4797 | QualType Result = TL.getType(); |
| 4798 | if (getDerived().AlwaysRebuild() || |
| 4799 | Record != T->getDecl()) { |
| 4800 | Result = getDerived().RebuildRecordType(Record); |
| 4801 | if (Result.isNull()) |
| 4802 | return QualType(); |
| 4803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4805 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4806 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4807 | |
| 4808 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4809 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4810 | |
| 4811 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4812 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4813 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4814 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4815 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4816 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4817 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4818 | if (!Enum) |
| 4819 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4820 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4821 | QualType Result = TL.getType(); |
| 4822 | if (getDerived().AlwaysRebuild() || |
| 4823 | Enum != T->getDecl()) { |
| 4824 | Result = getDerived().RebuildEnumType(Enum); |
| 4825 | if (Result.isNull()) |
| 4826 | return QualType(); |
| 4827 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4828 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4829 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4830 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4831 | |
| 4832 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4833 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4834 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4835 | template<typename Derived> |
| 4836 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4837 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4838 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4839 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4840 | TL.getTypePtr()->getDecl()); |
| 4841 | if (!D) return QualType(); |
| 4842 | |
| 4843 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4844 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4845 | return T; |
| 4846 | } |
| 4847 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4848 | template<typename Derived> |
| 4849 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4850 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4851 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4852 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4853 | } |
| 4854 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4855 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4856 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4857 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4858 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4859 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4860 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4861 | // Substitute into the replacement type, which itself might involve something |
| 4862 | // that needs to be transformed. This only tends to occur with default |
| 4863 | // template arguments of template template parameters. |
| 4864 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4865 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4866 | if (Replacement.isNull()) |
| 4867 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4868 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4869 | // Always canonicalize the replacement type. |
| 4870 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4871 | QualType Result |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4872 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4873 | Replacement); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4874 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4875 | // Propagate type-source information. |
| 4876 | SubstTemplateTypeParmTypeLoc NewTL |
| 4877 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4878 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4879 | return Result; |
| 4880 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4881 | } |
| 4882 | |
| 4883 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4884 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4885 | TypeLocBuilder &TLB, |
| 4886 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4887 | return TransformTypeSpecType(TLB, TL); |
| 4888 | } |
| 4889 | |
| 4890 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4891 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4892 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4893 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4894 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4895 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4896 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4897 | // because we can't have a dependent nested-name-specifier anyway. |
| 4898 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4899 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4900 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4901 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4902 | if (Template.isNull()) |
| 4903 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4905 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4906 | } |
| 4907 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4908 | template<typename Derived> |
| 4909 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4910 | AtomicTypeLoc TL) { |
| 4911 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4912 | if (ValueType.isNull()) |
| 4913 | return QualType(); |
| 4914 | |
| 4915 | QualType Result = TL.getType(); |
| 4916 | if (getDerived().AlwaysRebuild() || |
| 4917 | ValueType != TL.getValueLoc().getType()) { |
| 4918 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4919 | if (Result.isNull()) |
| 4920 | return QualType(); |
| 4921 | } |
| 4922 | |
| 4923 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4924 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4925 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4926 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4927 | |
| 4928 | return Result; |
| 4929 | } |
| 4930 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4931 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4932 | /// container that provides a \c getArgLoc() member function. |
| 4933 | /// |
| 4934 | /// This iterator is intended to be used with the iterator form of |
| 4935 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4936 | template<typename ArgLocContainer> |
| 4937 | class TemplateArgumentLocContainerIterator { |
| 4938 | ArgLocContainer *Container; |
| 4939 | unsigned Index; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4940 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4941 | public: |
| 4942 | typedef TemplateArgumentLoc value_type; |
| 4943 | typedef TemplateArgumentLoc reference; |
| 4944 | typedef int difference_type; |
| 4945 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4946 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4947 | class pointer { |
| 4948 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4949 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4950 | public: |
| 4951 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4952 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4953 | const TemplateArgumentLoc *operator->() const { |
| 4954 | return &Arg; |
| 4955 | } |
| 4956 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4957 | |
| 4958 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4959 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4960 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4961 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4962 | unsigned Index) |
| 4963 | : Container(&Container), Index(Index) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4964 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4965 | TemplateArgumentLocContainerIterator &operator++() { |
| 4966 | ++Index; |
| 4967 | return *this; |
| 4968 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4969 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4970 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4971 | TemplateArgumentLocContainerIterator Old(*this); |
| 4972 | ++(*this); |
| 4973 | return Old; |
| 4974 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4975 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4976 | TemplateArgumentLoc operator*() const { |
| 4977 | return Container->getArgLoc(Index); |
| 4978 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4979 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4980 | pointer operator->() const { |
| 4981 | return pointer(Container->getArgLoc(Index)); |
| 4982 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4983 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4984 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4985 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4986 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4987 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4988 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4989 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4990 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4991 | return !(X == Y); |
| 4992 | } |
| 4993 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4994 | |
| 4995 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4996 | template <typename Derived> |
| 4997 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4998 | TypeLocBuilder &TLB, |
| 4999 | TemplateSpecializationTypeLoc TL, |
| 5000 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5001 | TemplateArgumentListInfo NewTemplateArgs; |
| 5002 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5003 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5004 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 5005 | ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5006 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5007 | ArgIterator(TL, TL.getNumArgs()), |
| 5008 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 5009 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5011 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 5012 | |
| 5013 | QualType Result = |
| 5014 | getDerived().RebuildTemplateSpecializationType(Template, |
| 5015 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5016 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5017 | |
| 5018 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5019 | // Specializations of template template parameters are represented as |
| 5020 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 5021 | // within a dependent context can transform them into |
| 5022 | // DependentTemplateSpecializationTypes. |
| 5023 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5024 | DependentTemplateSpecializationTypeLoc NewTL |
| 5025 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5026 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5027 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5028 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5029 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5030 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5031 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5032 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5033 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5034 | return Result; |
| 5035 | } |
| 5036 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5037 | TemplateSpecializationTypeLoc NewTL |
| 5038 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5039 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5040 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5041 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5042 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5043 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5044 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5045 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5046 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5047 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5049 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5050 | template <typename Derived> |
| 5051 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 5052 | TypeLocBuilder &TLB, |
| 5053 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 5054 | TemplateName Template, |
| 5055 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5056 | TemplateArgumentListInfo NewTemplateArgs; |
| 5057 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5058 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 5059 | typedef TemplateArgumentLocContainerIterator< |
| 5060 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5061 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5062 | ArgIterator(TL, TL.getNumArgs()), |
| 5063 | NewTemplateArgs)) |
| 5064 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5065 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5066 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5067 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5068 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 5069 | QualType Result |
| 5070 | = getSema().Context.getDependentTemplateSpecializationType( |
| 5071 | TL.getTypePtr()->getKeyword(), |
| 5072 | DTN->getQualifier(), |
| 5073 | DTN->getIdentifier(), |
| 5074 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5075 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5076 | DependentTemplateSpecializationTypeLoc NewTL |
| 5077 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5078 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5079 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5080 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5081 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5082 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5083 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5084 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5085 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5086 | return Result; |
| 5087 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5088 | |
| 5089 | QualType Result |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5090 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5091 | TL.getTemplateNameLoc(), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5092 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5093 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5094 | if (!Result.isNull()) { |
| 5095 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 5096 | TemplateSpecializationTypeLoc NewTL |
| 5097 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5098 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5099 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5100 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5101 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5102 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5103 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5104 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5105 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5106 | return Result; |
| 5107 | } |
| 5108 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5110 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5111 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5112 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5113 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5115 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5116 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5117 | if (TL.getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5118 | QualifierLoc |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5119 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5120 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5121 | return QualType(); |
| 5122 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5123 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5124 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 5125 | if (NamedT.isNull()) |
| 5126 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 5127 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5128 | // C++0x [dcl.type.elab]p2: |
| 5129 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 5130 | // resolves to an alias template specialization, the |
| 5131 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5132 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 5133 | if (const TemplateSpecializationType *TST = |
| 5134 | NamedT->getAs<TemplateSpecializationType>()) { |
| 5135 | TemplateName Template = TST->getTemplateName(); |
| 5136 | if (TypeAliasTemplateDecl *TAT = |
| 5137 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 5138 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 5139 | diag::err_tag_reference_non_tag) << 4; |
| 5140 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 5141 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5142 | } |
| 5143 | } |
| 5144 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5145 | QualType Result = TL.getType(); |
| 5146 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5147 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5148 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5149 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5150 | T->getKeyword(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5151 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5152 | if (Result.isNull()) |
| 5153 | return QualType(); |
| 5154 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5155 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5156 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5157 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5158 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5159 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5160 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5161 | |
| 5162 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5163 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5164 | TypeLocBuilder &TLB, |
| 5165 | AttributedTypeLoc TL) { |
| 5166 | const AttributedType *oldType = TL.getTypePtr(); |
| 5167 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5168 | if (modifiedType.isNull()) |
| 5169 | return QualType(); |
| 5170 | |
| 5171 | QualType result = TL.getType(); |
| 5172 | |
| 5173 | // FIXME: dependent operand expressions? |
| 5174 | if (getDerived().AlwaysRebuild() || |
| 5175 | modifiedType != oldType->getModifiedType()) { |
| 5176 | // TODO: this is really lame; we should really be rebuilding the |
| 5177 | // equivalent type from first principles. |
| 5178 | QualType equivalentType |
| 5179 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5180 | if (equivalentType.isNull()) |
| 5181 | return QualType(); |
| 5182 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5183 | modifiedType, |
| 5184 | equivalentType); |
| 5185 | } |
| 5186 | |
| 5187 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5188 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5189 | if (TL.hasAttrOperand()) |
| 5190 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5191 | if (TL.hasAttrExprOperand()) |
| 5192 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5193 | else if (TL.hasAttrEnumOperand()) |
| 5194 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5195 | |
| 5196 | return result; |
| 5197 | } |
| 5198 | |
| 5199 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5200 | QualType |
| 5201 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5202 | ParenTypeLoc TL) { |
| 5203 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5204 | if (Inner.isNull()) |
| 5205 | return QualType(); |
| 5206 | |
| 5207 | QualType Result = TL.getType(); |
| 5208 | if (getDerived().AlwaysRebuild() || |
| 5209 | Inner != TL.getInnerLoc().getType()) { |
| 5210 | Result = getDerived().RebuildParenType(Inner); |
| 5211 | if (Result.isNull()) |
| 5212 | return QualType(); |
| 5213 | } |
| 5214 | |
| 5215 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5216 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5217 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5218 | return Result; |
| 5219 | } |
| 5220 | |
| 5221 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5222 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5223 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5224 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5225 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5226 | NestedNameSpecifierLoc QualifierLoc |
| 5227 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5228 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5229 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5231 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5232 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5233 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5234 | QualifierLoc, |
| 5235 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5236 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5237 | if (Result.isNull()) |
| 5238 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5239 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5240 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5241 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5242 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5243 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5244 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5245 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5246 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5247 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5248 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5249 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5250 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5251 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5252 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5253 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5254 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5255 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5256 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5257 | QualType TreeTransform<Derived>:: |
| 5258 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5259 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5260 | NestedNameSpecifierLoc QualifierLoc; |
| 5261 | if (TL.getQualifierLoc()) { |
| 5262 | QualifierLoc |
| 5263 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5264 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5265 | return QualType(); |
| 5266 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5267 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5268 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5269 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5270 | } |
| 5271 | |
| 5272 | template<typename Derived> |
| 5273 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5274 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5275 | DependentTemplateSpecializationTypeLoc TL, |
| 5276 | NestedNameSpecifierLoc QualifierLoc) { |
| 5277 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5278 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5279 | TemplateArgumentListInfo NewTemplateArgs; |
| 5280 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5281 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5282 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5283 | typedef TemplateArgumentLocContainerIterator< |
| 5284 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5285 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5286 | ArgIterator(TL, TL.getNumArgs()), |
| 5287 | NewTemplateArgs)) |
| 5288 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5289 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5290 | QualType Result |
| 5291 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5292 | QualifierLoc, |
| 5293 | T->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5294 | TL.getTemplateNameLoc(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5295 | NewTemplateArgs); |
| 5296 | if (Result.isNull()) |
| 5297 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5298 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5299 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5300 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5301 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5302 | // Copy information relevant to the template specialization. |
| 5303 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5304 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5305 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5306 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5307 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5308 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5309 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5310 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5311 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5312 | // Copy information relevant to the elaborated type. |
| 5313 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5314 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5315 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5316 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5317 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5318 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5319 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5320 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5321 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5322 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5323 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5324 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5325 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5326 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5327 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5328 | TemplateSpecializationTypeLoc SpecTL |
| 5329 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5330 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5331 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5332 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5333 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5334 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5335 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5336 | } |
| 5337 | return Result; |
| 5338 | } |
| 5339 | |
| 5340 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5341 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5342 | PackExpansionTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5343 | QualType Pattern |
| 5344 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5345 | if (Pattern.isNull()) |
| 5346 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5347 | |
| 5348 | QualType Result = TL.getType(); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5349 | if (getDerived().AlwaysRebuild() || |
| 5350 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5351 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5352 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5353 | TL.getEllipsisLoc(), |
| 5354 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5355 | if (Result.isNull()) |
| 5356 | return QualType(); |
| 5357 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5358 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5359 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5360 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5361 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5365 | QualType |
| 5366 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5367 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5368 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5369 | TLB.pushFullCopy(TL); |
| 5370 | return TL.getType(); |
| 5371 | } |
| 5372 | |
| 5373 | template<typename Derived> |
| 5374 | QualType |
| 5375 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5376 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5377 | // ObjCObjectType is never dependent. |
| 5378 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5379 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
| 5382 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5383 | QualType |
| 5384 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5385 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5386 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5387 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5388 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5389 | } |
| 5390 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5391 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5392 | // Statement transformation |
| 5393 | //===----------------------------------------------------------------------===// |
| 5394 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5395 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5396 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5397 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5398 | } |
| 5399 | |
| 5400 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5401 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5402 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5403 | return getDerived().TransformCompoundStmt(S, false); |
| 5404 | } |
| 5405 | |
| 5406 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5407 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5408 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5409 | bool IsStmtExpr) { |
Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5410 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5411 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5412 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5413 | bool SubStmtChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5414 | SmallVector<Stmt*, 8> Statements; |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5415 | for (auto *B : S->body()) { |
| 5416 | StmtResult Result = getDerived().TransformStmt(B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5417 | if (Result.isInvalid()) { |
| 5418 | // Immediately fail if this was a DeclStmt, since it's very |
| 5419 | // likely that this will cause problems for future statements. |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5420 | if (isa<DeclStmt>(B)) |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5421 | return StmtError(); |
| 5422 | |
| 5423 | // Otherwise, just keep processing substatements and fail later. |
| 5424 | SubStmtInvalid = true; |
| 5425 | continue; |
| 5426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5427 | |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5428 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5429 | Statements.push_back(Result.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5430 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5431 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5432 | if (SubStmtInvalid) |
| 5433 | return StmtError(); |
| 5434 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5435 | if (!getDerived().AlwaysRebuild() && |
| 5436 | !SubStmtChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5437 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5438 | |
| 5439 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5440 | Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5441 | S->getRBracLoc(), |
| 5442 | IsStmtExpr); |
| 5443 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5444 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5445 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5446 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5447 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5448 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5449 | { |
Eli Friedman | 1f4f9dd | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5450 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5451 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5452 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5453 | // Transform the left-hand case value. |
| 5454 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5455 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5456 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5457 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5458 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5459 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5460 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5461 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5462 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5463 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5466 | // Build the case statement. |
| 5467 | // Case statements are always rebuilt so that they will attached to their |
| 5468 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5469 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5470 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5471 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5472 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5473 | S->getColonLoc()); |
| 5474 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5475 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5477 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5478 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5479 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5480 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5481 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5482 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5483 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5487 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5488 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5489 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5490 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5491 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5492 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5494 | // Default statements are always rebuilt |
| 5495 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5496 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5498 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5499 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5500 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5501 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5502 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5503 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5504 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5505 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5506 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5507 | S->getDecl()); |
| 5508 | if (!LD) |
| 5509 | return StmtError(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5510 | |
| 5511 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5512 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5513 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5514 | cast<LabelDecl>(LD), SourceLocation(), |
| 5515 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5516 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5517 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5518 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5519 | StmtResult |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5520 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5521 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5522 | if (SubStmt.isInvalid()) |
| 5523 | return StmtError(); |
| 5524 | |
| 5525 | // TODO: transform attributes |
| 5526 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5527 | return S; |
| 5528 | |
| 5529 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5530 | S->getAttrs(), |
| 5531 | SubStmt.get()); |
| 5532 | } |
| 5533 | |
| 5534 | template<typename Derived> |
| 5535 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5536 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5537 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5538 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5539 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5540 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5541 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5542 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5543 | getDerived().TransformDefinition( |
| 5544 | S->getConditionVariable()->getLocation(), |
| 5545 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5546 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5547 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5548 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5549 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5550 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5551 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5552 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5553 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5554 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5555 | if (S->getCond()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5556 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5557 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5558 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5559 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5560 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5561 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5562 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5563 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5564 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5565 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5566 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5567 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5568 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5569 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5570 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5571 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5572 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5573 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5574 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5575 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5576 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5577 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5578 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5579 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5580 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5581 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5582 | Then.get() == S->getThen() && |
| 5583 | Else.get() == S->getElse()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5584 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5585 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5586 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5587 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5588 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5592 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5594 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5595 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5596 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5597 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5598 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5599 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5600 | getDerived().TransformDefinition( |
| 5601 | S->getConditionVariable()->getLocation(), |
| 5602 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5603 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5604 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5605 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5606 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5607 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5608 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5609 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5610 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5611 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5612 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5613 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5614 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5615 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5616 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5617 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5618 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5619 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5620 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5621 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5622 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5623 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5624 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5625 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5626 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5627 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5628 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5629 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5630 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5631 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5632 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5633 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5634 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5635 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5636 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5637 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5638 | getDerived().TransformDefinition( |
| 5639 | S->getConditionVariable()->getLocation(), |
| 5640 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5641 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5642 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5643 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5644 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5645 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5646 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5647 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5648 | |
| 5649 | if (S->getCond()) { |
| 5650 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5651 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 5652 | S->getWhileLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5653 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5654 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5655 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5656 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5657 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5658 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5659 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5660 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5661 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5662 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5663 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5664 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5665 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5666 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5667 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5668 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5669 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5670 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5671 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5672 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5673 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5674 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5675 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5676 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5677 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5679 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5680 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5681 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5682 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5683 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5684 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5685 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5686 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5687 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5688 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5689 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5690 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5691 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5692 | if (!getDerived().AlwaysRebuild() && |
| 5693 | Cond.get() == S->getCond() && |
| 5694 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5695 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5696 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5697 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5698 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5699 | S->getRParenLoc()); |
| 5700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5701 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5702 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5703 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5704 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5705 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5706 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5707 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5708 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5709 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5710 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5711 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5712 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5713 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5714 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5715 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5716 | getDerived().TransformDefinition( |
| 5717 | S->getConditionVariable()->getLocation(), |
| 5718 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5719 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5720 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5721 | } else { |
| 5722 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5723 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5724 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5725 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5726 | |
| 5727 | if (S->getCond()) { |
| 5728 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5729 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 5730 | S->getForLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5731 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5732 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5733 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5734 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5735 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5736 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5737 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5738 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5739 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5740 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5741 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5742 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5743 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5744 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5745 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5746 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5747 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 5748 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5749 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5750 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5751 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5752 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5753 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5754 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5755 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5756 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5757 | if (!getDerived().AlwaysRebuild() && |
| 5758 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5759 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5760 | Inc.get() == S->getInc() && |
| 5761 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5762 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5763 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5764 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5765 | Init.get(), FullCond, ConditionVar, |
| 5766 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5767 | } |
| 5768 | |
| 5769 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5770 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5771 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5772 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5773 | S->getLabel()); |
| 5774 | if (!LD) |
| 5775 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5776 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5777 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5778 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5779 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5780 | } |
| 5781 | |
| 5782 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5783 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5784 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5785 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5786 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5787 | return StmtError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5788 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5789 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5790 | if (!getDerived().AlwaysRebuild() && |
| 5791 | Target.get() == S->getTarget()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5792 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5793 | |
| 5794 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5795 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5799 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5800 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5801 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5802 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5803 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5804 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5805 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5806 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5807 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5808 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5809 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5810 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5811 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5812 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5813 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5814 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5815 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5816 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5817 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5818 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5819 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5820 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5821 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5822 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5823 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5824 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5825 | bool DeclChanged = false; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5826 | SmallVector<Decl *, 4> Decls; |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 5827 | for (auto *D : S->decls()) { |
| 5828 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5829 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5830 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5831 | |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 5832 | if (Transformed != D) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5833 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5834 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5835 | Decls.push_back(Transformed); |
| 5836 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5837 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5838 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5839 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5840 | |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 5841 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5843 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5844 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5845 | StmtResult |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5846 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5847 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5848 | SmallVector<Expr*, 8> Constraints; |
| 5849 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5850 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5851 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5852 | ExprResult AsmString; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5853 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5854 | |
| 5855 | bool ExprsChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5856 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5857 | // Go through the outputs. |
| 5858 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5859 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5860 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5861 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5862 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5863 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5864 | // Transform the output expr. |
| 5865 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5866 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5867 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5868 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5869 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5870 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5871 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5872 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5873 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5874 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5875 | // Go through the inputs. |
| 5876 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5877 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5878 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5879 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5880 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5881 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5882 | // Transform the input expr. |
| 5883 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5884 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5885 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5886 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5887 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5888 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5889 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5890 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5891 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5892 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5893 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5894 | return S; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5895 | |
| 5896 | // Go through the clobbers. |
| 5897 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5898 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5899 | |
| 5900 | // No need to transform the asm string literal. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5901 | AsmString = S->getAsmString(); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5902 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5903 | S->isVolatile(), S->getNumOutputs(), |
| 5904 | S->getNumInputs(), Names.data(), |
| 5905 | Constraints, Exprs, AsmString.get(), |
| 5906 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5907 | } |
| 5908 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5909 | template<typename Derived> |
| 5910 | StmtResult |
| 5911 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5912 | ArrayRef<Token> AsmToks = |
| 5913 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5914 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5915 | bool HadError = false, HadChange = false; |
| 5916 | |
| 5917 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 5918 | SmallVector<Expr*, 8> TransformedExprs; |
| 5919 | TransformedExprs.reserve(SrcExprs.size()); |
| 5920 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 5921 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 5922 | if (!Result.isUsable()) { |
| 5923 | HadError = true; |
| 5924 | } else { |
| 5925 | HadChange |= (Result.get() != SrcExprs[i]); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5926 | TransformedExprs.push_back(Result.get()); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5927 | } |
| 5928 | } |
| 5929 | |
| 5930 | if (HadError) return StmtError(); |
| 5931 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 5932 | return Owned(S); |
| 5933 | |
Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 5934 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5935 | AsmToks, S->getAsmString(), |
| 5936 | S->getNumOutputs(), S->getNumInputs(), |
| 5937 | S->getAllConstraints(), S->getClobbers(), |
| 5938 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5939 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5940 | |
| 5941 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5942 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5943 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5944 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5945 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5946 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5947 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5948 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5949 | // Transform the @catch statements (if present). |
| 5950 | bool AnyCatchChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5951 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5952 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5953 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5954 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5955 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5956 | if (Catch.get() != S->getCatchStmt(I)) |
| 5957 | AnyCatchChanged = true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5958 | CatchStmts.push_back(Catch.get()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5959 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5960 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5961 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5962 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5963 | if (S->getFinallyStmt()) { |
| 5964 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5965 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5966 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5967 | } |
| 5968 | |
| 5969 | // If nothing changed, just retain this statement. |
| 5970 | if (!getDerived().AlwaysRebuild() && |
| 5971 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5972 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5973 | Finally.get() == S->getFinallyStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5974 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5975 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5976 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5977 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5978 | CatchStmts, Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5979 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5980 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5981 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5982 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5983 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5984 | // Transform the @catch parameter, if there is one. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5985 | VarDecl *Var = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5986 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5987 | TypeSourceInfo *TSInfo = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5988 | if (FromVar->getTypeSourceInfo()) { |
| 5989 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5990 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5991 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5992 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5993 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5994 | QualType T; |
| 5995 | if (TSInfo) |
| 5996 | T = TSInfo->getType(); |
| 5997 | else { |
| 5998 | T = getDerived().TransformType(FromVar->getType()); |
| 5999 | if (T.isNull()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6000 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6001 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6002 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6003 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 6004 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6005 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6006 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6007 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6008 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6009 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6010 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6011 | |
| 6012 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6013 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6014 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6015 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6016 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6017 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6018 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6019 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6020 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6021 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6022 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6023 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6024 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6025 | // If nothing changed, just retain this statement. |
| 6026 | if (!getDerived().AlwaysRebuild() && |
| 6027 | Body.get() == S->getFinallyBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6028 | return S; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6029 | |
| 6030 | // Build a new statement. |
| 6031 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6032 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6033 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6034 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6035 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6036 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6037 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6038 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6039 | if (S->getThrowExpr()) { |
| 6040 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 6041 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6042 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6043 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6044 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6045 | if (!getDerived().AlwaysRebuild() && |
| 6046 | Operand.get() == S->getThrowExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6047 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6048 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6049 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6051 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6052 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6053 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6054 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6055 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6056 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6057 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6058 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6059 | return StmtError(); |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 6060 | Object = |
| 6061 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 6062 | Object.get()); |
| 6063 | if (Object.isInvalid()) |
| 6064 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6065 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6066 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6067 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6068 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6069 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6070 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6071 | // If nothing change, just retain the current statement. |
| 6072 | if (!getDerived().AlwaysRebuild() && |
| 6073 | Object.get() == S->getSynchExpr() && |
| 6074 | Body.get() == S->getSynchBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6075 | return S; |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6076 | |
| 6077 | // Build a new statement. |
| 6078 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6079 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6083 | StmtResult |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6084 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 6085 | ObjCAutoreleasePoolStmt *S) { |
| 6086 | // Transform the body. |
| 6087 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 6088 | if (Body.isInvalid()) |
| 6089 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6090 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6091 | // If nothing changed, just retain this statement. |
| 6092 | if (!getDerived().AlwaysRebuild() && |
| 6093 | Body.get() == S->getSubStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6094 | return S; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6095 | |
| 6096 | // Build a new statement. |
| 6097 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 6098 | S->getAtLoc(), Body.get()); |
| 6099 | } |
| 6100 | |
| 6101 | template<typename Derived> |
| 6102 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6103 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6104 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6105 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6106 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6107 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6108 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6109 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6110 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6111 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6112 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6113 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6114 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6115 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6116 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6117 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6118 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6119 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6120 | // If nothing changed, just retain this statement. |
| 6121 | if (!getDerived().AlwaysRebuild() && |
| 6122 | Element.get() == S->getElement() && |
| 6123 | Collection.get() == S->getCollection() && |
| 6124 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6125 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6126 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6127 | // Build a new statement. |
| 6128 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6129 | Element.get(), |
| 6130 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6131 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6132 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6133 | } |
| 6134 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6135 | template <typename Derived> |
| 6136 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6137 | // Transform the exception declaration, if any. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6138 | VarDecl *Var = nullptr; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6139 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 6140 | TypeSourceInfo *T = |
| 6141 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 6142 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6143 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6144 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6145 | Var = getDerived().RebuildExceptionDecl( |
| 6146 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 6147 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6148 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6149 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6151 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6152 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6153 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6154 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6155 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6156 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6157 | if (!getDerived().AlwaysRebuild() && !Var && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6158 | Handler.get() == S->getHandlerBlock()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6159 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6160 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6161 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6162 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6163 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6164 | template <typename Derived> |
| 6165 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6166 | // Transform the try block itself. |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6167 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6168 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6169 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6170 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6171 | // Transform the handlers. |
| 6172 | bool HandlerChanged = false; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6173 | SmallVector<Stmt *, 8> Handlers; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6174 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6175 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6176 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6177 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6178 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6179 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6180 | Handlers.push_back(Handler.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6181 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6182 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6183 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6184 | !HandlerChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6185 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6186 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6187 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6188 | Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6189 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6190 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6191 | template<typename Derived> |
| 6192 | StmtResult |
| 6193 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6194 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6195 | if (Range.isInvalid()) |
| 6196 | return StmtError(); |
| 6197 | |
| 6198 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6199 | if (BeginEnd.isInvalid()) |
| 6200 | return StmtError(); |
| 6201 | |
| 6202 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6203 | if (Cond.isInvalid()) |
| 6204 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6205 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6206 | Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc()); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6207 | if (Cond.isInvalid()) |
| 6208 | return StmtError(); |
| 6209 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6210 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6211 | |
| 6212 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6213 | if (Inc.isInvalid()) |
| 6214 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6215 | if (Inc.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6216 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6217 | |
| 6218 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6219 | if (LoopVar.isInvalid()) |
| 6220 | return StmtError(); |
| 6221 | |
| 6222 | StmtResult NewStmt = S; |
| 6223 | if (getDerived().AlwaysRebuild() || |
| 6224 | Range.get() != S->getRangeStmt() || |
| 6225 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6226 | Cond.get() != S->getCond() || |
| 6227 | Inc.get() != S->getInc() || |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6228 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6229 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6230 | S->getColonLoc(), Range.get(), |
| 6231 | BeginEnd.get(), Cond.get(), |
| 6232 | Inc.get(), LoopVar.get(), |
| 6233 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6234 | if (NewStmt.isInvalid()) |
| 6235 | return StmtError(); |
| 6236 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6237 | |
| 6238 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6239 | if (Body.isInvalid()) |
| 6240 | return StmtError(); |
| 6241 | |
| 6242 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6243 | // it now so we have a new statement to attach the body to. |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6244 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6245 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6246 | S->getColonLoc(), Range.get(), |
| 6247 | BeginEnd.get(), Cond.get(), |
| 6248 | Inc.get(), LoopVar.get(), |
| 6249 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6250 | if (NewStmt.isInvalid()) |
| 6251 | return StmtError(); |
| 6252 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6253 | |
| 6254 | if (NewStmt.get() == S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6255 | return S; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6256 | |
| 6257 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6258 | } |
| 6259 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6260 | template<typename Derived> |
| 6261 | StmtResult |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6262 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6263 | MSDependentExistsStmt *S) { |
| 6264 | // Transform the nested-name-specifier, if any. |
| 6265 | NestedNameSpecifierLoc QualifierLoc; |
| 6266 | if (S->getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6267 | QualifierLoc |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6268 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6269 | if (!QualifierLoc) |
| 6270 | return StmtError(); |
| 6271 | } |
| 6272 | |
| 6273 | // Transform the declaration name. |
| 6274 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6275 | if (NameInfo.getName()) { |
| 6276 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6277 | if (!NameInfo.getName()) |
| 6278 | return StmtError(); |
| 6279 | } |
| 6280 | |
| 6281 | // Check whether anything changed. |
| 6282 | if (!getDerived().AlwaysRebuild() && |
| 6283 | QualifierLoc == S->getQualifierLoc() && |
| 6284 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6285 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6286 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6287 | // Determine whether this name exists, if we can. |
| 6288 | CXXScopeSpec SS; |
| 6289 | SS.Adopt(QualifierLoc); |
| 6290 | bool Dependent = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6291 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6292 | case Sema::IER_Exists: |
| 6293 | if (S->isIfExists()) |
| 6294 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6295 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6296 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6297 | |
| 6298 | case Sema::IER_DoesNotExist: |
| 6299 | if (S->isIfNotExists()) |
| 6300 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6301 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6302 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6303 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6304 | case Sema::IER_Dependent: |
| 6305 | Dependent = true; |
| 6306 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6307 | |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6308 | case Sema::IER_Error: |
| 6309 | return StmtError(); |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6310 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6311 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6312 | // We need to continue with the instantiation, so do so now. |
| 6313 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6314 | if (SubStmt.isInvalid()) |
| 6315 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6316 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6317 | // If we have resolved the name, just transform to the substatement. |
| 6318 | if (!Dependent) |
| 6319 | return SubStmt; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6320 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6321 | // The name is still dependent, so build a dependent expression again. |
| 6322 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6323 | S->isIfExists(), |
| 6324 | QualifierLoc, |
| 6325 | NameInfo, |
| 6326 | SubStmt.get()); |
| 6327 | } |
| 6328 | |
| 6329 | template<typename Derived> |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6330 | ExprResult |
| 6331 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6332 | NestedNameSpecifierLoc QualifierLoc; |
| 6333 | if (E->getQualifierLoc()) { |
| 6334 | QualifierLoc |
| 6335 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6336 | if (!QualifierLoc) |
| 6337 | return ExprError(); |
| 6338 | } |
| 6339 | |
| 6340 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6341 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6342 | if (!PD) |
| 6343 | return ExprError(); |
| 6344 | |
| 6345 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6346 | if (Base.isInvalid()) |
| 6347 | return ExprError(); |
| 6348 | |
| 6349 | return new (SemaRef.getASTContext()) |
| 6350 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6351 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6352 | QualifierLoc, E->getMemberLoc()); |
| 6353 | } |
| 6354 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6355 | template <typename Derived> |
| 6356 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6357 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6358 | if (TryBlock.isInvalid()) |
| 6359 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6360 | |
| 6361 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6362 | if (Handler.isInvalid()) |
| 6363 | return StmtError(); |
| 6364 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6365 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 6366 | Handler.get() == S->getHandler()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6367 | return S; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6368 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6369 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6370 | TryBlock.get(), Handler.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6371 | } |
| 6372 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6373 | template <typename Derived> |
| 6374 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6375 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6376 | if (Block.isInvalid()) |
| 6377 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6378 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6379 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6382 | template <typename Derived> |
| 6383 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6384 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6385 | if (FilterExpr.isInvalid()) |
| 6386 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6387 | |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6388 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6389 | if (Block.isInvalid()) |
| 6390 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6391 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6392 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 6393 | Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6394 | } |
| 6395 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6396 | template <typename Derived> |
| 6397 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6398 | if (isa<SEHFinallyStmt>(Handler)) |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6399 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6400 | else |
| 6401 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6402 | } |
| 6403 | |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 6404 | template<typename Derived> |
| 6405 | StmtResult |
| 6406 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 6407 | return S; |
| 6408 | } |
| 6409 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6410 | //===----------------------------------------------------------------------===// |
| 6411 | // OpenMP directive transformation |
| 6412 | //===----------------------------------------------------------------------===// |
| 6413 | template <typename Derived> |
| 6414 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 6415 | OMPExecutableDirective *D) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6416 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6417 | // Transform the clauses |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6418 | llvm::SmallVector<OMPClause *, 16> TClauses; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6419 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6420 | TClauses.reserve(Clauses.size()); |
| 6421 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6422 | I != E; ++I) { |
| 6423 | if (*I) { |
| 6424 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6425 | if (Clause) |
| 6426 | TClauses.push_back(Clause); |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6427 | } else { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 6428 | TClauses.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6429 | } |
| 6430 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6431 | StmtResult AssociatedStmt; |
| 6432 | if (D->hasAssociatedStmt()) { |
| 6433 | if (!D->getAssociatedStmt()) { |
| 6434 | return StmtError(); |
| 6435 | } |
| 6436 | AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt()); |
| 6437 | if (AssociatedStmt.isInvalid()) { |
| 6438 | return StmtError(); |
| 6439 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6440 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6441 | if (TClauses.size() != Clauses.size()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6442 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6443 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6444 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6445 | return getDerived().RebuildOMPExecutableDirective( |
| 6446 | D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(), |
| 6447 | D->getLocEnd()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6448 | } |
| 6449 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6450 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6451 | StmtResult |
| 6452 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 6453 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6454 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| 6455 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6456 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6457 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6458 | return Res; |
| 6459 | } |
| 6460 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6461 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6462 | StmtResult |
| 6463 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 6464 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6465 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| 6466 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6467 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6468 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6469 | return Res; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6470 | } |
| 6471 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6472 | template <typename Derived> |
| 6473 | StmtResult |
| 6474 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 6475 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6476 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| 6477 | D->getLocStart()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6478 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6479 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6480 | return Res; |
| 6481 | } |
| 6482 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6483 | template <typename Derived> |
| 6484 | StmtResult |
| 6485 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 6486 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6487 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| 6488 | D->getLocStart()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6489 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6490 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6491 | return Res; |
| 6492 | } |
| 6493 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6494 | template <typename Derived> |
| 6495 | StmtResult |
| 6496 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 6497 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6498 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| 6499 | D->getLocStart()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6500 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6501 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6502 | return Res; |
| 6503 | } |
| 6504 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6505 | template <typename Derived> |
| 6506 | StmtResult |
| 6507 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 6508 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6509 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| 6510 | D->getLocStart()); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6511 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6512 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6513 | return Res; |
| 6514 | } |
| 6515 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6516 | template <typename Derived> |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 6517 | StmtResult |
| 6518 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 6519 | DeclarationNameInfo DirName; |
| 6520 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| 6521 | D->getLocStart()); |
| 6522 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6523 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6524 | return Res; |
| 6525 | } |
| 6526 | |
| 6527 | template <typename Derived> |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6528 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 6529 | OMPParallelForDirective *D) { |
| 6530 | DeclarationNameInfo DirName; |
| 6531 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| 6532 | nullptr, D->getLocStart()); |
| 6533 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6534 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6535 | return Res; |
| 6536 | } |
| 6537 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6538 | template <typename Derived> |
| 6539 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 6540 | OMPParallelSectionsDirective *D) { |
| 6541 | DeclarationNameInfo DirName; |
| 6542 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| 6543 | nullptr, D->getLocStart()); |
| 6544 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6545 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6546 | return Res; |
| 6547 | } |
| 6548 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6549 | template <typename Derived> |
| 6550 | StmtResult |
| 6551 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 6552 | DeclarationNameInfo DirName; |
| 6553 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| 6554 | D->getLocStart()); |
| 6555 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6556 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6557 | return Res; |
| 6558 | } |
| 6559 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6560 | template <typename Derived> |
| 6561 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 6562 | OMPTaskyieldDirective *D) { |
| 6563 | DeclarationNameInfo DirName; |
| 6564 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| 6565 | D->getLocStart()); |
| 6566 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6567 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6568 | return Res; |
| 6569 | } |
| 6570 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame^] | 6571 | template <typename Derived> |
| 6572 | StmtResult |
| 6573 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 6574 | DeclarationNameInfo DirName; |
| 6575 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| 6576 | D->getLocStart()); |
| 6577 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6578 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6579 | return Res; |
| 6580 | } |
| 6581 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6582 | //===----------------------------------------------------------------------===// |
| 6583 | // OpenMP clause transformation |
| 6584 | //===----------------------------------------------------------------------===// |
| 6585 | template <typename Derived> |
| 6586 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 6587 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 6588 | if (Cond.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6589 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6590 | return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(), |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6591 | C->getLParenLoc(), C->getLocEnd()); |
| 6592 | } |
| 6593 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6594 | template <typename Derived> |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6595 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 6596 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 6597 | if (Cond.isInvalid()) |
| 6598 | return nullptr; |
| 6599 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(), |
| 6600 | C->getLParenLoc(), C->getLocEnd()); |
| 6601 | } |
| 6602 | |
| 6603 | template <typename Derived> |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6604 | OMPClause * |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6605 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 6606 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 6607 | if (NumThreads.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6608 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6609 | return getDerived().RebuildOMPNumThreadsClause( |
| 6610 | NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6613 | template <typename Derived> |
| 6614 | OMPClause * |
| 6615 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 6616 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 6617 | if (E.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6618 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6619 | return getDerived().RebuildOMPSafelenClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6620 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6621 | } |
| 6622 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6623 | template <typename Derived> |
| 6624 | OMPClause * |
| 6625 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 6626 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 6627 | if (E.isInvalid()) |
| 6628 | return 0; |
| 6629 | return getDerived().RebuildOMPCollapseClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6630 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6631 | } |
| 6632 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6633 | template <typename Derived> |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6634 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6635 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6636 | return getDerived().RebuildOMPDefaultClause( |
| 6637 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(), |
| 6638 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6639 | } |
| 6640 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6641 | template <typename Derived> |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6642 | OMPClause * |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6643 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6644 | return getDerived().RebuildOMPProcBindClause( |
| 6645 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(), |
| 6646 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6647 | } |
| 6648 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6649 | template <typename Derived> |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6650 | OMPClause * |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6651 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 6652 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 6653 | if (E.isInvalid()) |
| 6654 | return nullptr; |
| 6655 | return getDerived().RebuildOMPScheduleClause( |
| 6656 | C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(), |
| 6657 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd()); |
| 6658 | } |
| 6659 | |
| 6660 | template <typename Derived> |
| 6661 | OMPClause * |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6662 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
| 6663 | // No need to rebuild this clause, no template-dependent parameters. |
| 6664 | return C; |
| 6665 | } |
| 6666 | |
| 6667 | template <typename Derived> |
| 6668 | OMPClause * |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6669 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 6670 | // No need to rebuild this clause, no template-dependent parameters. |
| 6671 | return C; |
| 6672 | } |
| 6673 | |
| 6674 | template <typename Derived> |
| 6675 | OMPClause * |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6676 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 6677 | // No need to rebuild this clause, no template-dependent parameters. |
| 6678 | return C; |
| 6679 | } |
| 6680 | |
| 6681 | template <typename Derived> |
| 6682 | OMPClause * |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6683 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 6684 | // No need to rebuild this clause, no template-dependent parameters. |
| 6685 | return C; |
| 6686 | } |
| 6687 | |
| 6688 | template <typename Derived> |
| 6689 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6690 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6691 | llvm::SmallVector<Expr *, 16> Vars; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6692 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6693 | for (auto *VE : C->varlists()) { |
| 6694 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6695 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6696 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6697 | Vars.push_back(EVar.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6698 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6699 | return getDerived().RebuildOMPPrivateClause( |
| 6700 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6701 | } |
| 6702 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6703 | template <typename Derived> |
| 6704 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 6705 | OMPFirstprivateClause *C) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6706 | llvm::SmallVector<Expr *, 16> Vars; |
| 6707 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6708 | for (auto *VE : C->varlists()) { |
| 6709 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6710 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6711 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6712 | Vars.push_back(EVar.get()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6713 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6714 | return getDerived().RebuildOMPFirstprivateClause( |
| 6715 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6716 | } |
| 6717 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6718 | template <typename Derived> |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6719 | OMPClause * |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6720 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 6721 | llvm::SmallVector<Expr *, 16> Vars; |
| 6722 | Vars.reserve(C->varlist_size()); |
| 6723 | for (auto *VE : C->varlists()) { |
| 6724 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6725 | if (EVar.isInvalid()) |
| 6726 | return nullptr; |
| 6727 | Vars.push_back(EVar.get()); |
| 6728 | } |
| 6729 | return getDerived().RebuildOMPLastprivateClause( |
| 6730 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 6731 | } |
| 6732 | |
| 6733 | template <typename Derived> |
| 6734 | OMPClause * |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6735 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 6736 | llvm::SmallVector<Expr *, 16> Vars; |
| 6737 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6738 | for (auto *VE : C->varlists()) { |
| 6739 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6740 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6741 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6742 | Vars.push_back(EVar.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6743 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6744 | return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(), |
| 6745 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6746 | } |
| 6747 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6748 | template <typename Derived> |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6749 | OMPClause * |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6750 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 6751 | llvm::SmallVector<Expr *, 16> Vars; |
| 6752 | Vars.reserve(C->varlist_size()); |
| 6753 | for (auto *VE : C->varlists()) { |
| 6754 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6755 | if (EVar.isInvalid()) |
| 6756 | return nullptr; |
| 6757 | Vars.push_back(EVar.get()); |
| 6758 | } |
| 6759 | CXXScopeSpec ReductionIdScopeSpec; |
| 6760 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 6761 | |
| 6762 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 6763 | if (NameInfo.getName()) { |
| 6764 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6765 | if (!NameInfo.getName()) |
| 6766 | return nullptr; |
| 6767 | } |
| 6768 | return getDerived().RebuildOMPReductionClause( |
| 6769 | Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(), |
| 6770 | C->getLocEnd(), ReductionIdScopeSpec, NameInfo); |
| 6771 | } |
| 6772 | |
| 6773 | template <typename Derived> |
| 6774 | OMPClause * |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6775 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 6776 | llvm::SmallVector<Expr *, 16> Vars; |
| 6777 | Vars.reserve(C->varlist_size()); |
| 6778 | for (auto *VE : C->varlists()) { |
| 6779 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6780 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6781 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6782 | Vars.push_back(EVar.get()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6783 | } |
| 6784 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 6785 | if (Step.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6786 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6787 | return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(), |
| 6788 | C->getLParenLoc(), |
| 6789 | C->getColonLoc(), C->getLocEnd()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6790 | } |
| 6791 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6792 | template <typename Derived> |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6793 | OMPClause * |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6794 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 6795 | llvm::SmallVector<Expr *, 16> Vars; |
| 6796 | Vars.reserve(C->varlist_size()); |
| 6797 | for (auto *VE : C->varlists()) { |
| 6798 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6799 | if (EVar.isInvalid()) |
| 6800 | return nullptr; |
| 6801 | Vars.push_back(EVar.get()); |
| 6802 | } |
| 6803 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 6804 | if (Alignment.isInvalid()) |
| 6805 | return nullptr; |
| 6806 | return getDerived().RebuildOMPAlignedClause( |
| 6807 | Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(), |
| 6808 | C->getColonLoc(), C->getLocEnd()); |
| 6809 | } |
| 6810 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6811 | template <typename Derived> |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6812 | OMPClause * |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6813 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 6814 | llvm::SmallVector<Expr *, 16> Vars; |
| 6815 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6816 | for (auto *VE : C->varlists()) { |
| 6817 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6818 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6819 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6820 | Vars.push_back(EVar.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6821 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6822 | return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(), |
| 6823 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6824 | } |
| 6825 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6826 | template <typename Derived> |
| 6827 | OMPClause * |
| 6828 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 6829 | llvm::SmallVector<Expr *, 16> Vars; |
| 6830 | Vars.reserve(C->varlist_size()); |
| 6831 | for (auto *VE : C->varlists()) { |
| 6832 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6833 | if (EVar.isInvalid()) |
| 6834 | return nullptr; |
| 6835 | Vars.push_back(EVar.get()); |
| 6836 | } |
| 6837 | return getDerived().RebuildOMPCopyprivateClause( |
| 6838 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 6839 | } |
| 6840 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6841 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6842 | // Expression transformation |
| 6843 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6844 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6845 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6846 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6847 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6848 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6849 | |
| 6850 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6851 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6852 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6853 | NestedNameSpecifierLoc QualifierLoc; |
| 6854 | if (E->getQualifierLoc()) { |
| 6855 | QualifierLoc |
| 6856 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6857 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6858 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6859 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6860 | |
| 6861 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6862 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6863 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6864 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6865 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6866 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6867 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6868 | if (NameInfo.getName()) { |
| 6869 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6870 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6871 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6872 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6873 | |
| 6874 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6875 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6876 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6877 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6878 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6879 | |
| 6880 | // Mark it referenced in the new context regardless. |
| 6881 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6882 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6883 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6884 | return E; |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6885 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6886 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6887 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6888 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6889 | TemplateArgs = &TransArgs; |
| 6890 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6891 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6892 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6893 | E->getNumTemplateArgs(), |
| 6894 | TransArgs)) |
| 6895 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6896 | } |
| 6897 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6898 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6899 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6901 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6902 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6903 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6904 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6905 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6906 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6907 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6908 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6909 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6910 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6911 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6912 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6913 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6914 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6915 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6916 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6917 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6918 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6920 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6921 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6922 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6923 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6924 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6925 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6926 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6927 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6928 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6929 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6930 | } |
| 6931 | |
| 6932 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6933 | ExprResult |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6934 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 6935 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 6936 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6937 | return SemaRef.MaybeBindToTemporary(E); |
| 6938 | } |
| 6939 | |
| 6940 | template<typename Derived> |
| 6941 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6942 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6943 | ExprResult ControllingExpr = |
| 6944 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6945 | if (ControllingExpr.isInvalid()) |
| 6946 | return ExprError(); |
| 6947 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6948 | SmallVector<Expr *, 4> AssocExprs; |
| 6949 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6950 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6951 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6952 | if (TS) { |
| 6953 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6954 | if (!AssocType) |
| 6955 | return ExprError(); |
| 6956 | AssocTypes.push_back(AssocType); |
| 6957 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6958 | AssocTypes.push_back(nullptr); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6962 | if (AssocExpr.isInvalid()) |
| 6963 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6964 | AssocExprs.push_back(AssocExpr.get()); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6965 | } |
| 6966 | |
| 6967 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6968 | E->getDefaultLoc(), |
| 6969 | E->getRParenLoc(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6970 | ControllingExpr.get(), |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 6971 | AssocTypes, |
| 6972 | AssocExprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6973 | } |
| 6974 | |
| 6975 | template<typename Derived> |
| 6976 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6977 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6978 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6979 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6980 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6981 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6982 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6983 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6984 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6985 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6986 | E->getRParen()); |
| 6987 | } |
| 6988 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6989 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 6990 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 6991 | /// object available. |
| 6992 | template<typename Derived> |
| 6993 | ExprResult |
| 6994 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 6995 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 6996 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6997 | else |
| 6998 | return getDerived().TransformExpr(E); |
| 6999 | } |
| 7000 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7001 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7002 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7003 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 7004 | ExprResult SubExpr; |
| 7005 | if (E->getOpcode() == UO_AddrOf) |
| 7006 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 7007 | else |
| 7008 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7009 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7010 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7011 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7012 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7013 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7014 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7015 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 7016 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7017 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7018 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7019 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7020 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7021 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7022 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 7023 | // Transform the type. |
| 7024 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7025 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7026 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7027 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7028 | // Transform all of the components into components similar to what the |
| 7029 | // parser uses. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7030 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 7031 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 7032 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7033 | // template code that we don't care. |
| 7034 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7035 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7036 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7037 | SmallVector<Component, 4> Components; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7038 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 7039 | const Node &ON = E->getComponent(I); |
| 7040 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 7041 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 7042 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 7043 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7044 | switch (ON.getKind()) { |
| 7045 | case Node::Array: { |
| 7046 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7047 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7048 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7049 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7050 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7051 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 7052 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7053 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7054 | break; |
| 7055 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7056 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7057 | case Node::Field: |
| 7058 | case Node::Identifier: |
| 7059 | Comp.isBrackets = false; |
| 7060 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 7061 | if (!Comp.U.IdentInfo) |
| 7062 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7063 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7064 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7065 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 7066 | case Node::Base: |
| 7067 | // Will be recomputed during the rebuild. |
| 7068 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7069 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7070 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7071 | Components.push_back(Comp); |
| 7072 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7073 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7074 | // If nothing changed, retain the existing expression. |
| 7075 | if (!getDerived().AlwaysRebuild() && |
| 7076 | Type == E->getTypeSourceInfo() && |
| 7077 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7078 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7079 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7080 | // Build a new offsetof expression. |
| 7081 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 7082 | Components.data(), Components.size(), |
| 7083 | E->getRParenLoc()); |
| 7084 | } |
| 7085 | |
| 7086 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7087 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7088 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 7089 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 7090 | "opaque value expression requires transformation"); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7091 | return E; |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7092 | } |
| 7093 | |
| 7094 | template<typename Derived> |
| 7095 | ExprResult |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7096 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 7097 | // Rebuild the syntactic form. The original syntactic form has |
| 7098 | // opaque-value expressions in it, so strip those away and rebuild |
| 7099 | // the result. This is a really awful way of doing this, but the |
| 7100 | // better solution (rebuilding the semantic expressions and |
| 7101 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 7102 | // TreeTransform to not strip away implicit conversions. |
| 7103 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 7104 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7105 | if (result.isInvalid()) return ExprError(); |
| 7106 | |
| 7107 | // If that gives us a pseudo-object result back, the pseudo-object |
| 7108 | // expression must have been an lvalue-to-rvalue conversion which we |
| 7109 | // should reapply. |
| 7110 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7111 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7112 | |
| 7113 | return result; |
| 7114 | } |
| 7115 | |
| 7116 | template<typename Derived> |
| 7117 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7118 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 7119 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7120 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7121 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7122 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7123 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7124 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7125 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7126 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7127 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7128 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7129 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7130 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 7131 | E->getKind(), |
| 7132 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7133 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7134 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7135 | // C++0x [expr.sizeof]p1: |
| 7136 | // The operand is either an expression, which is an unevaluated operand |
| 7137 | // [...] |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7138 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7139 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7140 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7141 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 7142 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 7143 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 7144 | ExprResult SubExpr; |
| 7145 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 7146 | if (auto *DRE = |
| 7147 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 7148 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 7149 | PE, DRE, false, &RecoveryTSI); |
| 7150 | else |
| 7151 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 7152 | |
| 7153 | if (RecoveryTSI) { |
| 7154 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 7155 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 7156 | } else if (SubExpr.isInvalid()) |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7157 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7158 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7159 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7160 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7161 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7162 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 7163 | E->getOperatorLoc(), |
| 7164 | E->getKind(), |
| 7165 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7166 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7168 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7169 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7170 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7171 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7172 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7173 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7174 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7175 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7176 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7177 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7178 | |
| 7179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7180 | if (!getDerived().AlwaysRebuild() && |
| 7181 | LHS.get() == E->getLHS() && |
| 7182 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7183 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7184 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7185 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7186 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7187 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7188 | E->getRBracketLoc()); |
| 7189 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7190 | |
| 7191 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7192 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7193 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7194 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7195 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7196 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7197 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7198 | |
| 7199 | // Transform arguments. |
| 7200 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7201 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7202 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7203 | &ArgChanged)) |
| 7204 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7206 | if (!getDerived().AlwaysRebuild() && |
| 7207 | Callee.get() == E->getCallee() && |
| 7208 | !ArgChanged) |
Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 7209 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7210 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7211 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7212 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7213 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7214 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7215 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7216 | E->getRParenLoc()); |
| 7217 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7218 | |
| 7219 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7220 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7221 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7222 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7223 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7224 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7225 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7226 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7227 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7228 | QualifierLoc |
| 7229 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7230 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7231 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7232 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7233 | } |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7234 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7235 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 7236 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7237 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 7238 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7239 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7240 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7241 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7242 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 7243 | if (FoundDecl == E->getMemberDecl()) { |
| 7244 | FoundDecl = Member; |
| 7245 | } else { |
| 7246 | FoundDecl = cast_or_null<NamedDecl>( |
| 7247 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 7248 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7249 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7250 | } |
| 7251 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7252 | if (!getDerived().AlwaysRebuild() && |
| 7253 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7254 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7255 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7256 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7257 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7258 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 7259 | // Mark it referenced in the new context regardless. |
| 7260 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7261 | SemaRef.MarkMemberReferenced(E); |
| 7262 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7263 | return E; |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 7264 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7265 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7266 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7267 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7268 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 7269 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7270 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7271 | E->getNumTemplateArgs(), |
| 7272 | TransArgs)) |
| 7273 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7274 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7275 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7276 | // FIXME: Bogus source location for the operator |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7277 | SourceLocation FakeOperatorLoc = |
| 7278 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7279 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7280 | // FIXME: to do this check properly, we will need to preserve the |
| 7281 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7282 | // base (and therefore couldn't do the check) and a |
| 7283 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7284 | NamedDecl *FirstQualifierInScope = nullptr; |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7285 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7286 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7287 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7288 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7289 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7290 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7291 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7292 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7293 | (E->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7294 | ? &TransArgs : nullptr), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7295 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7297 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7298 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7299 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7300 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7301 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7302 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7303 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7304 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7305 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7306 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7307 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7308 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7309 | if (!getDerived().AlwaysRebuild() && |
| 7310 | LHS.get() == E->getLHS() && |
| 7311 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7312 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7313 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7314 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7315 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7316 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7317 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7318 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7319 | } |
| 7320 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7321 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7322 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7323 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7324 | CompoundAssignOperator *E) { |
| 7325 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7328 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7329 | ExprResult TreeTransform<Derived>:: |
| 7330 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 7331 | // Just rebuild the common and RHS expressions and see whether we |
| 7332 | // get any changes. |
| 7333 | |
| 7334 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 7335 | if (commonExpr.isInvalid()) |
| 7336 | return ExprError(); |
| 7337 | |
| 7338 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 7339 | if (rhs.isInvalid()) |
| 7340 | return ExprError(); |
| 7341 | |
| 7342 | if (!getDerived().AlwaysRebuild() && |
| 7343 | commonExpr.get() == e->getCommon() && |
| 7344 | rhs.get() == e->getFalseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7345 | return e; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7346 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7347 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7348 | e->getQuestionLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7349 | nullptr, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7350 | e->getColonLoc(), |
| 7351 | rhs.get()); |
| 7352 | } |
| 7353 | |
| 7354 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7355 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7356 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7357 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7358 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7359 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7360 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7361 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7362 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7363 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7364 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7365 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7366 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7367 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7368 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7369 | if (!getDerived().AlwaysRebuild() && |
| 7370 | Cond.get() == E->getCond() && |
| 7371 | LHS.get() == E->getLHS() && |
| 7372 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7373 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7374 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7375 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 7376 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7377 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 7378 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7379 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7381 | |
| 7382 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7383 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7384 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 7385 | // Implicit casts are eliminated during transformation, since they |
| 7386 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7387 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7388 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7389 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7390 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7391 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7392 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7393 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7394 | if (!Type) |
| 7395 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7396 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7397 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7398 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7399 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7400 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7401 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7402 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7403 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7404 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7405 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7406 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 7407 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7408 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7409 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7410 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7412 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7413 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7414 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7415 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7416 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 7417 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 7418 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7419 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7420 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7421 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7422 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7423 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7425 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7426 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7427 | Init.get() == E->getInitializer()) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7428 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7429 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 7430 | // Note: the expression type doesn't necessarily match the |
| 7431 | // type-as-written, but that's okay, because it should always be |
| 7432 | // derivable from the initializer. |
| 7433 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7434 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7435 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7436 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7438 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7439 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7440 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7441 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7442 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7443 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7444 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7445 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7446 | if (!getDerived().AlwaysRebuild() && |
| 7447 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7448 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7449 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7450 | // FIXME: Bad source location |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7451 | SourceLocation FakeOperatorLoc = |
| 7452 | SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7453 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7454 | E->getAccessorLoc(), |
| 7455 | E->getAccessor()); |
| 7456 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7457 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7458 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7459 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7460 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7461 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7462 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7463 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7464 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7465 | Inits, &InitChanged)) |
| 7466 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7467 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7468 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7469 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7470 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7471 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 7472 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7473 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7474 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7475 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7476 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7477 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7478 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7479 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7480 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7481 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7482 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7483 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7484 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7485 | // transform the designators. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7486 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7487 | bool ExprChanged = false; |
| 7488 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 7489 | DEnd = E->designators_end(); |
| 7490 | D != DEnd; ++D) { |
| 7491 | if (D->isFieldDesignator()) { |
| 7492 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 7493 | D->getDotLoc(), |
| 7494 | D->getFieldLoc())); |
| 7495 | continue; |
| 7496 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7497 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7498 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7499 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7500 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7501 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7502 | |
| 7503 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7504 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7505 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7506 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7507 | ArrayExprs.push_back(Index.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7508 | continue; |
| 7509 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7510 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7511 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7512 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7513 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 7514 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7515 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7516 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7517 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7518 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7519 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7520 | |
| 7521 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7522 | End.get(), |
| 7523 | D->getLBracketLoc(), |
| 7524 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7525 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7526 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 7527 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7528 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7529 | ArrayExprs.push_back(Start.get()); |
| 7530 | ArrayExprs.push_back(End.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7532 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7533 | if (!getDerived().AlwaysRebuild() && |
| 7534 | Init.get() == E->getInit() && |
| 7535 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7536 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7537 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7538 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7539 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7540 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7541 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7542 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7543 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7544 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7545 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7546 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7547 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7548 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7549 | // FIXME: Will we ever have proper type location here? Will we actually |
| 7550 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7551 | QualType T = getDerived().TransformType(E->getType()); |
| 7552 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7553 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7554 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7555 | if (!getDerived().AlwaysRebuild() && |
| 7556 | T == E->getType()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7557 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7558 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7559 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 7560 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7561 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7562 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7563 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7564 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 7565 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 7566 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7567 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7568 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7569 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7570 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7571 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7572 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7573 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7574 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7575 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7576 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7577 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7578 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7579 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7580 | } |
| 7581 | |
| 7582 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7583 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7584 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7585 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7586 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7587 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 7588 | &ArgumentChanged)) |
| 7589 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7590 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7591 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7592 | Inits, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7593 | E->getRParenLoc()); |
| 7594 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7595 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7596 | /// \brief Transform an address-of-label expression. |
| 7597 | /// |
| 7598 | /// By default, the transformation of an address-of-label expression always |
| 7599 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 7600 | /// the corresponding label statement by semantic analysis. |
| 7601 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7602 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7603 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7604 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 7605 | E->getLabel()); |
| 7606 | if (!LD) |
| 7607 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7608 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7609 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7610 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7611 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7612 | |
| 7613 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7614 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7615 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7616 | SemaRef.ActOnStartStmtExpr(); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7617 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7618 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7619 | if (SubStmt.isInvalid()) { |
| 7620 | SemaRef.ActOnStmtExprError(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7621 | return ExprError(); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7622 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7623 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7624 | if (!getDerived().AlwaysRebuild() && |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7625 | SubStmt.get() == E->getSubStmt()) { |
| 7626 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 7627 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7628 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7629 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7630 | |
| 7631 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7632 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7633 | E->getRParenLoc()); |
| 7634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7635 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7636 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7637 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7638 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7639 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7640 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7641 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7642 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7643 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7644 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7645 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7646 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7647 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7648 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7649 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7650 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7651 | if (!getDerived().AlwaysRebuild() && |
| 7652 | Cond.get() == E->getCond() && |
| 7653 | LHS.get() == E->getLHS() && |
| 7654 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7655 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7656 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7657 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7658 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7659 | E->getRParenLoc()); |
| 7660 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7661 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7662 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7663 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7664 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7665 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7666 | } |
| 7667 | |
| 7668 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7669 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7670 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7671 | switch (E->getOperator()) { |
| 7672 | case OO_New: |
| 7673 | case OO_Delete: |
| 7674 | case OO_Array_New: |
| 7675 | case OO_Array_Delete: |
| 7676 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7677 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7678 | case OO_Call: { |
| 7679 | // This is a call to an object's operator(). |
| 7680 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 7681 | |
| 7682 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7683 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7684 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7685 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7686 | |
| 7687 | // FIXME: Poor location information |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7688 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| 7689 | static_cast<Expr *>(Object.get())->getLocEnd()); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7690 | |
| 7691 | // Transform the call arguments. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7692 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7693 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7694 | Args)) |
| 7695 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7696 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7697 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7698 | Args, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7699 | E->getLocEnd()); |
| 7700 | } |
| 7701 | |
| 7702 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 7703 | case OO_##Name: |
| 7704 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 7705 | #include "clang/Basic/OperatorKinds.def" |
| 7706 | case OO_Subscript: |
| 7707 | // Handled below. |
| 7708 | break; |
| 7709 | |
| 7710 | case OO_Conditional: |
| 7711 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7712 | |
| 7713 | case OO_None: |
| 7714 | case NUM_OVERLOADED_OPERATORS: |
| 7715 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7716 | } |
| 7717 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7718 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7719 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7720 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7721 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7722 | ExprResult First; |
| 7723 | if (E->getOperator() == OO_Amp) |
| 7724 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 7725 | else |
| 7726 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7727 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7728 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7729 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7730 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7731 | if (E->getNumArgs() == 2) { |
| 7732 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 7733 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7734 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7735 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7736 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7737 | if (!getDerived().AlwaysRebuild() && |
| 7738 | Callee.get() == E->getCallee() && |
| 7739 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7740 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7741 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7742 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7743 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7744 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7745 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7746 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 7747 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7748 | Callee.get(), |
| 7749 | First.get(), |
| 7750 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7751 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7752 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7753 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7754 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7755 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7756 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7757 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7758 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7759 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7760 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7761 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 7762 | // Transform the callee. |
| 7763 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 7764 | if (Callee.isInvalid()) |
| 7765 | return ExprError(); |
| 7766 | |
| 7767 | // Transform exec config. |
| 7768 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 7769 | if (EC.isInvalid()) |
| 7770 | return ExprError(); |
| 7771 | |
| 7772 | // Transform arguments. |
| 7773 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7774 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7775 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7776 | &ArgChanged)) |
| 7777 | return ExprError(); |
| 7778 | |
| 7779 | if (!getDerived().AlwaysRebuild() && |
| 7780 | Callee.get() == E->getCallee() && |
| 7781 | !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7782 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7783 | |
| 7784 | // FIXME: Wrong source location information for the '('. |
| 7785 | SourceLocation FakeLParenLoc |
| 7786 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 7787 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7788 | Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7789 | E->getRParenLoc(), EC.get()); |
| 7790 | } |
| 7791 | |
| 7792 | template<typename Derived> |
| 7793 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7794 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7795 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7796 | if (!Type) |
| 7797 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7798 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7799 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7800 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7801 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7802 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7803 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7804 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7805 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7806 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7807 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7808 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7809 | E->getStmtClass(), |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7810 | E->getAngleBrackets().getBegin(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7811 | Type, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7812 | E->getAngleBrackets().getEnd(), |
| 7813 | // FIXME. this should be '(' location |
| 7814 | E->getAngleBrackets().getEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7815 | SubExpr.get(), |
Abramo Bagnara | 9fb4386 | 2012-10-15 21:08:58 +0000 | [diff] [blame] | 7816 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7817 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7818 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7819 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7820 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7821 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 7822 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7823 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7824 | |
| 7825 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7826 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7827 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 7828 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7829 | } |
| 7830 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7831 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7832 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7833 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7834 | CXXReinterpretCastExpr *E) { |
| 7835 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7836 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7837 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7838 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7839 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7840 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 7841 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7843 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7844 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7845 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7846 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7847 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7848 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7849 | if (!Type) |
| 7850 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7851 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7852 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7853 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7854 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7855 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7856 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7857 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7858 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7859 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7860 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7861 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7862 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 7863 | E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7864 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7865 | E->getRParenLoc()); |
| 7866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7867 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7868 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7869 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7870 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7871 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7872 | TypeSourceInfo *TInfo |
| 7873 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7874 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7875 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7876 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7877 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7878 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7879 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7880 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7881 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7882 | E->getLocStart(), |
| 7883 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7884 | E->getLocEnd()); |
| 7885 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7886 | |
Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7887 | // We don't know whether the subexpression is potentially evaluated until |
| 7888 | // after we perform semantic analysis. We speculatively assume it is |
| 7889 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7890 | // potentially evaluated. |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7891 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7892 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7893 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7894 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7895 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7896 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7898 | if (!getDerived().AlwaysRebuild() && |
| 7899 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7900 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7901 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7902 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7903 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7904 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7905 | E->getLocEnd()); |
| 7906 | } |
| 7907 | |
| 7908 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7909 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7910 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7911 | if (E->isTypeOperand()) { |
| 7912 | TypeSourceInfo *TInfo |
| 7913 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7914 | if (!TInfo) |
| 7915 | return ExprError(); |
| 7916 | |
| 7917 | if (!getDerived().AlwaysRebuild() && |
| 7918 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7919 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7920 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7921 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7922 | E->getLocStart(), |
| 7923 | TInfo, |
| 7924 | E->getLocEnd()); |
| 7925 | } |
| 7926 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7927 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7928 | |
| 7929 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7930 | if (SubExpr.isInvalid()) |
| 7931 | return ExprError(); |
| 7932 | |
| 7933 | if (!getDerived().AlwaysRebuild() && |
| 7934 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7935 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7936 | |
| 7937 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7938 | E->getLocStart(), |
| 7939 | SubExpr.get(), |
| 7940 | E->getLocEnd()); |
| 7941 | } |
| 7942 | |
| 7943 | template<typename Derived> |
| 7944 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7945 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7946 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7947 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7948 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7949 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7950 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7951 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7952 | CXXNullPtrLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7953 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7954 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7956 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7957 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7958 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 7959 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7960 | |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7961 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7962 | // Make sure that we capture 'this'. |
| 7963 | getSema().CheckCXXThisCapture(E->getLocStart()); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7964 | return E; |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7965 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7966 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7967 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7968 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7969 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7970 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7971 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7972 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7973 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7974 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7975 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7976 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7977 | if (!getDerived().AlwaysRebuild() && |
| 7978 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7979 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7980 | |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7981 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7982 | E->isThrownVariableInScope()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7983 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7984 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7985 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7986 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7987 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7988 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7989 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7990 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7991 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7992 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7993 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7994 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7995 | Param == E->getParam()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7996 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7997 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7998 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7999 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8000 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8001 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8002 | ExprResult |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8003 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 8004 | FieldDecl *Field |
| 8005 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8006 | E->getField())); |
| 8007 | if (!Field) |
| 8008 | return ExprError(); |
| 8009 | |
| 8010 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8011 | return E; |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8012 | |
| 8013 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 8014 | } |
| 8015 | |
| 8016 | template<typename Derived> |
| 8017 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8018 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 8019 | CXXScalarValueInitExpr *E) { |
| 8020 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8021 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8022 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8024 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8025 | T == E->getTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8026 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8027 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8028 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8029 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 8030 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8031 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8032 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8033 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8034 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8035 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8036 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8037 | TypeSourceInfo *AllocTypeInfo |
| 8038 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 8039 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8040 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8041 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8042 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8043 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8044 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8045 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8047 | // Transform the placement arguments (if any). |
| 8048 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8049 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8050 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8051 | E->getNumPlacementArgs(), true, |
| 8052 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8053 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8054 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8055 | // Transform the initializer (if any). |
| 8056 | Expr *OldInit = E->getInitializer(); |
| 8057 | ExprResult NewInit; |
| 8058 | if (OldInit) |
| 8059 | NewInit = getDerived().TransformExpr(OldInit); |
| 8060 | if (NewInit.isInvalid()) |
| 8061 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8062 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8063 | // Transform new operator and delete operator. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8064 | FunctionDecl *OperatorNew = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8065 | if (E->getOperatorNew()) { |
| 8066 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8067 | getDerived().TransformDecl(E->getLocStart(), |
| 8068 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8069 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8070 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8071 | } |
| 8072 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8073 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8074 | if (E->getOperatorDelete()) { |
| 8075 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8076 | getDerived().TransformDecl(E->getLocStart(), |
| 8077 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8078 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8079 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8080 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8082 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8083 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8084 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8085 | NewInit.get() == OldInit && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8086 | OperatorNew == E->getOperatorNew() && |
| 8087 | OperatorDelete == E->getOperatorDelete() && |
| 8088 | !ArgumentChanged) { |
| 8089 | // Mark any declarations we need as referenced. |
| 8090 | // FIXME: instantiation-specific. |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8091 | if (OperatorNew) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8092 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8093 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8094 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8095 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8096 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8097 | QualType ElementType |
| 8098 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 8099 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 8100 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 8101 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8102 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8103 | } |
| 8104 | } |
| 8105 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8106 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8107 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8109 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8110 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8111 | if (!ArraySize.get()) { |
| 8112 | // If no array size was specified, but the new expression was |
| 8113 | // instantiated with an array type (e.g., "new T" where T is |
| 8114 | // instantiated with "int[4]"), extract the outer bound from the |
| 8115 | // array type as our array size. We do this with constant and |
| 8116 | // dependently-sized array types. |
| 8117 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 8118 | if (!ArrayT) { |
| 8119 | // Do nothing |
| 8120 | } else if (const ConstantArrayType *ConsArrayT |
| 8121 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8122 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 8123 | SemaRef.Context.getSizeType(), |
| 8124 | /*FIXME:*/ E->getLocStart()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8125 | AllocType = ConsArrayT->getElementType(); |
| 8126 | } else if (const DependentSizedArrayType *DepArrayT |
| 8127 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 8128 | if (DepArrayT->getSizeExpr()) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8129 | ArraySize = DepArrayT->getSizeExpr(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8130 | AllocType = DepArrayT->getElementType(); |
| 8131 | } |
| 8132 | } |
| 8133 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8134 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8135 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 8136 | E->isGlobalNew(), |
| 8137 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8138 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8139 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 8140 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8141 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8142 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8143 | ArraySize.get(), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8144 | E->getDirectInitRange(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8145 | NewInit.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8147 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8148 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8149 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8150 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8151 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8152 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8153 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8154 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8155 | // Transform the delete operator, if known. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8156 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8157 | if (E->getOperatorDelete()) { |
| 8158 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8159 | getDerived().TransformDecl(E->getLocStart(), |
| 8160 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8161 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8162 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8163 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8164 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8165 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8166 | Operand.get() == E->getArgument() && |
| 8167 | OperatorDelete == E->getOperatorDelete()) { |
| 8168 | // Mark any declarations we need as referenced. |
| 8169 | // FIXME: instantiation-specific. |
| 8170 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8171 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8172 | |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8173 | if (!E->getArgument()->isTypeDependent()) { |
| 8174 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 8175 | E->getDestroyedType()); |
| 8176 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 8177 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8178 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8179 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8180 | } |
| 8181 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8182 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8183 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8184 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8185 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8186 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 8187 | E->isGlobalDelete(), |
| 8188 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8189 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8191 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8192 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8193 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8194 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8195 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8196 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8197 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8198 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8199 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8200 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8201 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8202 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8203 | E->getOperatorLoc(), |
| 8204 | E->isArrow()? tok::arrow : tok::period, |
| 8205 | ObjectTypePtr, |
| 8206 | MayBePseudoDestructor); |
| 8207 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8208 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8209 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8210 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8211 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 8212 | if (QualifierLoc) { |
| 8213 | QualifierLoc |
| 8214 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 8215 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8216 | return ExprError(); |
| 8217 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8218 | CXXScopeSpec SS; |
| 8219 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8220 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8221 | PseudoDestructorTypeStorage Destroyed; |
| 8222 | if (E->getDestroyedTypeInfo()) { |
| 8223 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8224 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8225 | ObjectType, nullptr, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8226 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8227 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8228 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 8229 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8230 | // We aren't likely to be able to resolve the identifier down to a type |
| 8231 | // now anyway, so just retain the identifier. |
| 8232 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 8233 | E->getDestroyedTypeLoc()); |
| 8234 | } else { |
| 8235 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8236 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8237 | *E->getDestroyedTypeIdentifier(), |
| 8238 | E->getDestroyedTypeLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8239 | /*Scope=*/nullptr, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8240 | SS, ObjectTypePtr, |
| 8241 | false); |
| 8242 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8243 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8244 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8245 | Destroyed |
| 8246 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 8247 | E->getDestroyedTypeLoc()); |
| 8248 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8249 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8250 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8251 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 8252 | CXXScopeSpec EmptySS; |
| 8253 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8254 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8255 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8256 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8257 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8258 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8259 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8260 | E->getOperatorLoc(), |
| 8261 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8262 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8263 | ScopeTypeInfo, |
| 8264 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8265 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8266 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8267 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8268 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8269 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8270 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8271 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8272 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8273 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 8274 | Sema::LookupOrdinaryName); |
| 8275 | |
| 8276 | // Transform all the decls. |
| 8277 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 8278 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8279 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8280 | getDerived().TransformDecl(Old->getNameLoc(), |
| 8281 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8282 | if (!InstD) { |
| 8283 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8284 | // This can happen because of dependent hiding. |
| 8285 | if (isa<UsingShadowDecl>(*I)) |
| 8286 | continue; |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8287 | else { |
| 8288 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8289 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8290 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8291 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8292 | |
| 8293 | // Expand using declarations. |
| 8294 | if (isa<UsingDecl>(InstD)) { |
| 8295 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 8296 | for (auto *I : UD->shadows()) |
| 8297 | R.addDecl(I); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8298 | continue; |
| 8299 | } |
| 8300 | |
| 8301 | R.addDecl(InstD); |
| 8302 | } |
| 8303 | |
| 8304 | // Resolve a kind, but don't do any further analysis. If it's |
| 8305 | // ambiguous, the callee needs to deal with it. |
| 8306 | R.resolveKind(); |
| 8307 | |
| 8308 | // Rebuild the nested-name qualifier, if present. |
| 8309 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8310 | if (Old->getQualifierLoc()) { |
| 8311 | NestedNameSpecifierLoc QualifierLoc |
| 8312 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8313 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8314 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8315 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8316 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8317 | } |
| 8318 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8319 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8320 | CXXRecordDecl *NamingClass |
| 8321 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 8322 | Old->getNameLoc(), |
| 8323 | Old->getNamingClass())); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8324 | if (!NamingClass) { |
| 8325 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8326 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8327 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8328 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8329 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8330 | } |
| 8331 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8332 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8333 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 8334 | // If we have neither explicit template arguments, nor the template keyword, |
| 8335 | // it's a normal declaration name. |
| 8336 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8337 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 8338 | |
| 8339 | // If we have template arguments, rebuild them, then rebuild the |
| 8340 | // templateid expression. |
| 8341 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 8342 | if (Old->hasExplicitTemplateArgs() && |
| 8343 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8344 | Old->getNumTemplateArgs(), |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8345 | TransArgs)) { |
| 8346 | R.clear(); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8347 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8348 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8349 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8350 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 8351 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8352 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8353 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8354 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8355 | ExprResult |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8356 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 8357 | bool ArgChanged = false; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8358 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8359 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 8360 | TypeSourceInfo *From = E->getArg(I); |
| 8361 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 8362 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8363 | TypeLocBuilder TLB; |
| 8364 | TLB.reserve(FromTL.getFullDataSize()); |
| 8365 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 8366 | if (To.isNull()) |
| 8367 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8368 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8369 | if (To == From->getType()) |
| 8370 | Args.push_back(From); |
| 8371 | else { |
| 8372 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8373 | ArgChanged = true; |
| 8374 | } |
| 8375 | continue; |
| 8376 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8377 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8378 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8379 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8380 | // We have a pack expansion. Instantiate it. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 8381 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8382 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 8383 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8384 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8385 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8386 | // Determine whether the set of unexpanded parameter packs can and should |
| 8387 | // be expanded. |
| 8388 | bool Expand = true; |
| 8389 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8390 | Optional<unsigned> OrigNumExpansions = |
| 8391 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 8392 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8393 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 8394 | PatternTL.getSourceRange(), |
| 8395 | Unexpanded, |
| 8396 | Expand, RetainExpansion, |
| 8397 | NumExpansions)) |
| 8398 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8399 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8400 | if (!Expand) { |
| 8401 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8402 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8403 | // expansion. |
| 8404 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8405 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8406 | TypeLocBuilder TLB; |
| 8407 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 8408 | |
| 8409 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8410 | if (To.isNull()) |
| 8411 | return ExprError(); |
| 8412 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8413 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8414 | PatternTL.getSourceRange(), |
| 8415 | ExpansionTL.getEllipsisLoc(), |
| 8416 | NumExpansions); |
| 8417 | if (To.isNull()) |
| 8418 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8419 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8420 | PackExpansionTypeLoc ToExpansionTL |
| 8421 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8422 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8423 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8424 | continue; |
| 8425 | } |
| 8426 | |
| 8427 | // Expand the pack expansion by substituting for each argument in the |
| 8428 | // pack(s). |
| 8429 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8430 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 8431 | TypeLocBuilder TLB; |
| 8432 | TLB.reserve(PatternTL.getFullDataSize()); |
| 8433 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8434 | if (To.isNull()) |
| 8435 | return ExprError(); |
| 8436 | |
Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 8437 | if (To->containsUnexpandedParameterPack()) { |
| 8438 | To = getDerived().RebuildPackExpansionType(To, |
| 8439 | PatternTL.getSourceRange(), |
| 8440 | ExpansionTL.getEllipsisLoc(), |
| 8441 | NumExpansions); |
| 8442 | if (To.isNull()) |
| 8443 | return ExprError(); |
| 8444 | |
| 8445 | PackExpansionTypeLoc ToExpansionTL |
| 8446 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8447 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8448 | } |
| 8449 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8450 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8451 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8452 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8453 | if (!RetainExpansion) |
| 8454 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8455 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8456 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 8457 | // forgetting the partially-substituted parameter pack. |
| 8458 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 8459 | |
| 8460 | TypeLocBuilder TLB; |
| 8461 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8462 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8463 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8464 | if (To.isNull()) |
| 8465 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8466 | |
| 8467 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8468 | PatternTL.getSourceRange(), |
| 8469 | ExpansionTL.getEllipsisLoc(), |
| 8470 | NumExpansions); |
| 8471 | if (To.isNull()) |
| 8472 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8473 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8474 | PackExpansionTypeLoc ToExpansionTL |
| 8475 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8476 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8477 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8478 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8479 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8480 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8481 | return E; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8482 | |
| 8483 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 8484 | E->getLocStart(), |
| 8485 | Args, |
| 8486 | E->getLocEnd()); |
| 8487 | } |
| 8488 | |
| 8489 | template<typename Derived> |
| 8490 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8491 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 8492 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 8493 | if (!T) |
| 8494 | return ExprError(); |
| 8495 | |
| 8496 | if (!getDerived().AlwaysRebuild() && |
| 8497 | T == E->getQueriedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8498 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8499 | |
| 8500 | ExprResult SubExpr; |
| 8501 | { |
| 8502 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8503 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 8504 | if (SubExpr.isInvalid()) |
| 8505 | return ExprError(); |
| 8506 | |
| 8507 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8508 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8509 | } |
| 8510 | |
| 8511 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 8512 | E->getLocStart(), |
| 8513 | T, |
| 8514 | SubExpr.get(), |
| 8515 | E->getLocEnd()); |
| 8516 | } |
| 8517 | |
| 8518 | template<typename Derived> |
| 8519 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8520 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 8521 | ExprResult SubExpr; |
| 8522 | { |
| 8523 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8524 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 8525 | if (SubExpr.isInvalid()) |
| 8526 | return ExprError(); |
| 8527 | |
| 8528 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8529 | return E; |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8530 | } |
| 8531 | |
| 8532 | return getDerived().RebuildExpressionTrait( |
| 8533 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 8534 | } |
| 8535 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8536 | template <typename Derived> |
| 8537 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 8538 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 8539 | TypeSourceInfo **RecoveryTSI) { |
| 8540 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 8541 | DRE, AddrTaken, RecoveryTSI); |
| 8542 | |
| 8543 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 8544 | if (!NewDRE.isUsable()) |
| 8545 | return NewDRE; |
| 8546 | |
| 8547 | // We got an expr, wrap it up in parens. |
| 8548 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 8549 | return PE; |
| 8550 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 8551 | PE->getRParen()); |
| 8552 | } |
| 8553 | |
| 8554 | template <typename Derived> |
| 8555 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8556 | DependentScopeDeclRefExpr *E) { |
| 8557 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 8558 | nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8559 | } |
| 8560 | |
| 8561 | template<typename Derived> |
| 8562 | ExprResult |
| 8563 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8564 | DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8565 | bool IsAddressOfOperand, |
| 8566 | TypeSourceInfo **RecoveryTSI) { |
Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 8567 | assert(E->getQualifierLoc()); |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8568 | NestedNameSpecifierLoc QualifierLoc |
| 8569 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8570 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8571 | return ExprError(); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8572 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8573 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8574 | // TODO: If this is a conversion-function-id, verify that the |
| 8575 | // destination type name (if present) resolves the same way after |
| 8576 | // instantiation as it did in the local scope. |
| 8577 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8578 | DeclarationNameInfo NameInfo |
| 8579 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 8580 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8581 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8582 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8583 | if (!E->hasExplicitTemplateArgs()) { |
| 8584 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8585 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8586 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 8587 | // if name has not changed, DNLoc has not changed either. |
| 8588 | NameInfo.getName() == E->getDeclName()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8589 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8590 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8591 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 8592 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 8593 | IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 8594 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8595 | |
| 8596 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8597 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8598 | E->getNumTemplateArgs(), |
| 8599 | TransArgs)) |
| 8600 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8601 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8602 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 8603 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 8604 | RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8605 | } |
| 8606 | |
| 8607 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8608 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8609 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8610 | // CXXConstructExprs other than for list-initialization and |
| 8611 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 8612 | // a 1-argument construction we just transform that argument. |
Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 8613 | if ((E->getNumArgs() == 1 || |
| 8614 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8615 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 8616 | !E->isListInitialization()) |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 8617 | return getDerived().TransformExpr(E->getArg(0)); |
| 8618 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8619 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 8620 | |
| 8621 | QualType T = getDerived().TransformType(E->getType()); |
| 8622 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8623 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8624 | |
| 8625 | CXXConstructorDecl *Constructor |
| 8626 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8627 | getDerived().TransformDecl(E->getLocStart(), |
| 8628 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8629 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8630 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8631 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8632 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8633 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8634 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8635 | &ArgumentChanged)) |
| 8636 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8638 | if (!getDerived().AlwaysRebuild() && |
| 8639 | T == E->getType() && |
| 8640 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8641 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8642 | // Mark the constructor as referenced. |
| 8643 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8644 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8645 | return E; |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8646 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8647 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 8648 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 8649 | Constructor, E->isElidable(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8650 | Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 8651 | E->hadMultipleCandidates(), |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8652 | E->isListInitialization(), |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 8653 | E->isStdInitListInitialization(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 8654 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 8655 | E->getConstructionKind(), |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 8656 | E->getParenOrBraceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8657 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8658 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8659 | /// \brief Transform a C++ temporary-binding expression. |
| 8660 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8661 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 8662 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8663 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8664 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8665 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8666 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8667 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8668 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8669 | /// \brief Transform a C++ expression that contains cleanups that should |
| 8670 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8671 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8672 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8673 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8674 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8675 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8676 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8677 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8680 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8681 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8682 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8683 | CXXTemporaryObjectExpr *E) { |
| 8684 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8685 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8686 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8687 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8688 | CXXConstructorDecl *Constructor |
| 8689 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8690 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8691 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8692 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8693 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8694 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8695 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8696 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8697 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8698 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8699 | &ArgumentChanged)) |
| 8700 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8701 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8702 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8703 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8704 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8705 | !ArgumentChanged) { |
| 8706 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8707 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8708 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8709 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8710 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8711 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8712 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 8713 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8714 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8715 | E->getLocEnd()); |
| 8716 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8717 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8718 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8719 | ExprResult |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8720 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8721 | |
| 8722 | // Transform any init-capture expressions before entering the scope of the |
| 8723 | // lambda body, because they are not semantically within that scope. |
| 8724 | SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes; |
| 8725 | InitCaptureExprsAndTypes.resize(E->explicit_capture_end() - |
| 8726 | E->explicit_capture_begin()); |
| 8727 | |
| 8728 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 8729 | CEnd = E->capture_end(); |
| 8730 | C != CEnd; ++C) { |
| 8731 | if (!C->isInitCapture()) |
| 8732 | continue; |
| 8733 | EnterExpressionEvaluationContext EEEC(getSema(), |
| 8734 | Sema::PotentiallyEvaluated); |
| 8735 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 8736 | C->getCapturedVar()->getInit(), |
| 8737 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
| 8738 | |
| 8739 | if (NewExprInitResult.isInvalid()) |
| 8740 | return ExprError(); |
| 8741 | Expr *NewExprInit = NewExprInitResult.get(); |
| 8742 | |
| 8743 | VarDecl *OldVD = C->getCapturedVar(); |
| 8744 | QualType NewInitCaptureType = |
| 8745 | getSema().performLambdaInitCaptureInitialization(C->getLocation(), |
| 8746 | OldVD->getType()->isReferenceType(), OldVD->getIdentifier(), |
| 8747 | NewExprInit); |
| 8748 | NewExprInitResult = NewExprInit; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8749 | InitCaptureExprsAndTypes[C - E->capture_begin()] = |
| 8750 | std::make_pair(NewExprInitResult, NewInitCaptureType); |
| 8751 | |
| 8752 | } |
| 8753 | |
Faisal Vali | 524ca28 | 2013-11-12 01:40:44 +0000 | [diff] [blame] | 8754 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8755 | // Transform the template parameters, and add them to the current |
| 8756 | // instantiation scope. The null case is handled correctly. |
| 8757 | LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList( |
| 8758 | E->getTemplateParameterList()); |
| 8759 | |
| 8760 | // Check to see if the TypeSourceInfo of the call operator needs to |
| 8761 | // be transformed, and if so do the transformation in the |
| 8762 | // CurrentInstantiationScope. |
| 8763 | |
| 8764 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 8765 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 8766 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8767 | TypeSourceInfo *NewCallOpTSI = nullptr; |
| 8768 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8769 | const bool CallOpWasAlreadyTransformed = |
| 8770 | getDerived().AlreadyTransformed(OldCallOpTSI->getType()); |
| 8771 | |
| 8772 | // Use the Old Call Operator's TypeSourceInfo if it is already transformed. |
| 8773 | if (CallOpWasAlreadyTransformed) |
| 8774 | NewCallOpTSI = OldCallOpTSI; |
| 8775 | else { |
| 8776 | // Transform the TypeSourceInfo of the Original Lambda's Call Operator. |
| 8777 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 8778 | // it introduces a mapping of the original to the newly created |
| 8779 | // transformed parameters. |
| 8780 | |
| 8781 | TypeLocBuilder NewCallOpTLBuilder; |
| 8782 | QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder, |
| 8783 | OldCallOpFPTL, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8784 | nullptr, 0); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8785 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 8786 | NewCallOpType); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8787 | } |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8788 | // Extract the ParmVarDecls from the NewCallOpTSI and add them to |
| 8789 | // the vector below - this will be used to synthesize the |
| 8790 | // NewCallOperator. Additionally, add the parameters of the untransformed |
| 8791 | // lambda call operator to the CurrentInstantiationScope. |
| 8792 | SmallVector<ParmVarDecl *, 4> Params; |
| 8793 | { |
| 8794 | FunctionProtoTypeLoc NewCallOpFPTL = |
| 8795 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>(); |
| 8796 | ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray(); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 8797 | const unsigned NewNumArgs = NewCallOpFPTL.getNumParams(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8798 | |
| 8799 | for (unsigned I = 0; I < NewNumArgs; ++I) { |
| 8800 | // If this call operator's type does not require transformation, |
| 8801 | // the parameters do not get added to the current instantiation scope, |
| 8802 | // - so ADD them! This allows the following to compile when the enclosing |
| 8803 | // template is specialized and the entire lambda expression has to be |
| 8804 | // transformed. |
| 8805 | // template<class T> void foo(T t) { |
| 8806 | // auto L = [](auto a) { |
| 8807 | // auto M = [](char b) { <-- note: non-generic lambda |
| 8808 | // auto N = [](auto c) { |
| 8809 | // int x = sizeof(a); |
| 8810 | // x = sizeof(b); <-- specifically this line |
| 8811 | // x = sizeof(c); |
| 8812 | // }; |
| 8813 | // }; |
| 8814 | // }; |
| 8815 | // } |
| 8816 | // foo('a') |
| 8817 | if (CallOpWasAlreadyTransformed) |
| 8818 | getDerived().transformedLocalDecl(NewParamDeclArray[I], |
| 8819 | NewParamDeclArray[I]); |
| 8820 | // Add to Params array, so these parameters can be used to create |
| 8821 | // the newly transformed call operator. |
| 8822 | Params.push_back(NewParamDeclArray[I]); |
| 8823 | } |
| 8824 | } |
| 8825 | |
| 8826 | if (!NewCallOpTSI) |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8827 | return ExprError(); |
| 8828 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8829 | // Create the local class that will describe the lambda. |
| 8830 | CXXRecordDecl *Class |
| 8831 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8832 | NewCallOpTSI, |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 8833 | /*KnownDependent=*/false, |
| 8834 | E->getCaptureDefault()); |
| 8835 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8836 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 8837 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8838 | // Build the call operator. |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8839 | CXXMethodDecl *NewCallOperator |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8840 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8841 | NewCallOpTSI, |
Douglas Gregor | adb376e | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8842 | E->getCallOperator()->getLocEnd(), |
Richard Smith | 505df23 | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8843 | Params); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8844 | LSI->CallOperator = NewCallOperator; |
Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 8845 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8846 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| 8847 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8848 | return getDerived().TransformLambdaScope(E, NewCallOperator, |
| 8849 | InitCaptureExprsAndTypes); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8850 | } |
| 8851 | |
| 8852 | template<typename Derived> |
| 8853 | ExprResult |
| 8854 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8855 | CXXMethodDecl *CallOperator, |
| 8856 | ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8857 | bool Invalid = false; |
| 8858 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8859 | // Introduce the context of the call operator. |
Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 8860 | Sema::ContextRAII SavedContext(getSema(), CallOperator, |
| 8861 | /*NewThisContext*/false); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8862 | |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8863 | LambdaScopeInfo *const LSI = getSema().getCurLambda(); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8864 | // Enter the scope of the lambda. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8865 | getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8866 | E->getCaptureDefault(), |
James Dennett | ddd36ff | 2013-08-09 23:08:25 +0000 | [diff] [blame] | 8867 | E->getCaptureDefaultLoc(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8868 | E->hasExplicitParameters(), |
| 8869 | E->hasExplicitResultType(), |
| 8870 | E->isMutable()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8871 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8872 | // Transform captures. |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8873 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8874 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8875 | CEnd = E->capture_end(); |
| 8876 | C != CEnd; ++C) { |
| 8877 | // When we hit the first implicit capture, tell Sema that we've finished |
| 8878 | // the list of explicit captures. |
| 8879 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 8880 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8881 | FinishedExplicitCaptures = true; |
| 8882 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8883 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8884 | // Capturing 'this' is trivial. |
| 8885 | if (C->capturesThis()) { |
| 8886 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 8887 | continue; |
| 8888 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8889 | |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8890 | // Rebuild init-captures, including the implied field declaration. |
| 8891 | if (C->isInitCapture()) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8892 | |
| 8893 | InitCaptureInfoTy InitExprTypePair = |
| 8894 | InitCaptureExprsAndTypes[C - E->capture_begin()]; |
| 8895 | ExprResult Init = InitExprTypePair.first; |
| 8896 | QualType InitQualType = InitExprTypePair.second; |
| 8897 | if (Init.isInvalid() || InitQualType.isNull()) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8898 | Invalid = true; |
| 8899 | continue; |
| 8900 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8901 | VarDecl *OldVD = C->getCapturedVar(); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8902 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 8903 | OldVD->getLocation(), InitExprTypePair.second, |
| 8904 | OldVD->getIdentifier(), Init.get()); |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8905 | if (!NewVD) |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8906 | Invalid = true; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8907 | else { |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8908 | getDerived().transformedLocalDecl(OldVD, NewVD); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8909 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8910 | getSema().buildInitCaptureField(LSI, NewVD); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8911 | continue; |
| 8912 | } |
| 8913 | |
| 8914 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 8915 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8916 | // Determine the capture kind for Sema. |
| 8917 | Sema::TryCaptureKind Kind |
| 8918 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 8919 | : C->getCaptureKind() == LCK_ByCopy |
| 8920 | ? Sema::TryCapture_ExplicitByVal |
| 8921 | : Sema::TryCapture_ExplicitByRef; |
| 8922 | SourceLocation EllipsisLoc; |
| 8923 | if (C->isPackExpansion()) { |
| 8924 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 8925 | bool ShouldExpand = false; |
| 8926 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8927 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8928 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 8929 | C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8930 | Unexpanded, |
| 8931 | ShouldExpand, RetainExpansion, |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8932 | NumExpansions)) { |
| 8933 | Invalid = true; |
| 8934 | continue; |
| 8935 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8936 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8937 | if (ShouldExpand) { |
| 8938 | // The transform has determined that we should perform an expansion; |
| 8939 | // transform and capture each of the arguments. |
| 8940 | // expansion of the pattern. Do so. |
| 8941 | VarDecl *Pack = C->getCapturedVar(); |
| 8942 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8943 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8944 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8945 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8946 | Pack)); |
| 8947 | if (!CapturedVar) { |
| 8948 | Invalid = true; |
| 8949 | continue; |
| 8950 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8951 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8952 | // Capture the transformed variable. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8953 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 8954 | } |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 8955 | |
| 8956 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 8957 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8958 | continue; |
| 8959 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8960 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8961 | EllipsisLoc = C->getEllipsisLoc(); |
| 8962 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8963 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8964 | // Transform the captured variable. |
| 8965 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8966 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8967 | C->getCapturedVar())); |
| 8968 | if (!CapturedVar) { |
| 8969 | Invalid = true; |
| 8970 | continue; |
| 8971 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8972 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8973 | // Capture the transformed variable. |
Douglas Gregor | fdf598e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 8974 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8975 | } |
| 8976 | if (!FinishedExplicitCaptures) |
| 8977 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8978 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8979 | |
| 8980 | // Enter a new evaluation context to insulate the lambda from any |
| 8981 | // cleanups from the enclosing full-expression. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8982 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8983 | |
| 8984 | if (Invalid) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8985 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8986 | /*IsInstantiation=*/true); |
| 8987 | return ExprError(); |
| 8988 | } |
| 8989 | |
| 8990 | // Instantiate the body of the lambda expression. |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8991 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 8992 | if (Body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8993 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8994 | /*IsInstantiation=*/true); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8995 | return ExprError(); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8996 | } |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 8997 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8998 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8999 | /*CurScope=*/nullptr, |
| 9000 | /*IsInstantiation=*/true); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 9001 | } |
| 9002 | |
| 9003 | template<typename Derived> |
| 9004 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9005 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9006 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9007 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9008 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9009 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9010 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9011 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9012 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9013 | Args.reserve(E->arg_size()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9014 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9015 | &ArgumentChanged)) |
| 9016 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9018 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9019 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9020 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9021 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9023 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9024 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9025 | E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9026 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9027 | E->getRParenLoc()); |
| 9028 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9029 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9030 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9031 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 9032 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9033 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9034 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9035 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9036 | Expr *OldBase; |
| 9037 | QualType BaseType; |
| 9038 | QualType ObjectType; |
| 9039 | if (!E->isImplicitAccess()) { |
| 9040 | OldBase = E->getBase(); |
| 9041 | Base = getDerived().TransformExpr(OldBase); |
| 9042 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9043 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9044 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9045 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9046 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9047 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9048 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9049 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9050 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9051 | ObjectTy, |
| 9052 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9053 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9054 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9055 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9056 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9057 | BaseType = ((Expr*) Base.get())->getType(); |
| 9058 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9059 | OldBase = nullptr; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9060 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 9061 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 9062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9063 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9064 | // Transform the first part of the nested-name-specifier that qualifies |
| 9065 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 9066 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9067 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9068 | E->getFirstQualifierFoundInScope(), |
| 9069 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9070 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9071 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9072 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9073 | QualifierLoc |
| 9074 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 9075 | ObjectType, |
| 9076 | FirstQualifierInScope); |
| 9077 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9078 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9079 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9080 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9081 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 9082 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9083 | // TODO: If this is a conversion-function-id, verify that the |
| 9084 | // destination type name (if present) resolves the same way after |
| 9085 | // instantiation as it did in the local scope. |
| 9086 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9087 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9088 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9089 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9090 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9091 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9092 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9093 | // This is a reference to a member without an explicitly-specified |
| 9094 | // template argument list. Optimize for this common case. |
| 9095 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9096 | Base.get() == OldBase && |
| 9097 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9098 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9099 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9100 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9101 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9102 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9103 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9104 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9105 | E->isArrow(), |
| 9106 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9107 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9108 | TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9109 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9110 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9111 | /*TemplateArgs*/nullptr); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9112 | } |
| 9113 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9114 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9115 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9116 | E->getNumTemplateArgs(), |
| 9117 | TransArgs)) |
| 9118 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9119 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9120 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9121 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9122 | E->isArrow(), |
| 9123 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9124 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9125 | TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9126 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9127 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9128 | &TransArgs); |
| 9129 | } |
| 9130 | |
| 9131 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9132 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9133 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9134 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9135 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9136 | QualType BaseType; |
| 9137 | if (!Old->isImplicitAccess()) { |
| 9138 | Base = getDerived().TransformExpr(Old->getBase()); |
| 9139 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9140 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9141 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 9142 | Old->isArrow()); |
| 9143 | if (Base.isInvalid()) |
| 9144 | return ExprError(); |
| 9145 | BaseType = Base.get()->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9146 | } else { |
| 9147 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 9148 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9149 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9150 | NestedNameSpecifierLoc QualifierLoc; |
| 9151 | if (Old->getQualifierLoc()) { |
| 9152 | QualifierLoc |
| 9153 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 9154 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9155 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9156 | } |
| 9157 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9158 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 9159 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9160 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9161 | Sema::LookupOrdinaryName); |
| 9162 | |
| 9163 | // Transform all the decls. |
| 9164 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 9165 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9166 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 9167 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 9168 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9169 | if (!InstD) { |
| 9170 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 9171 | // This can happen because of dependent hiding. |
| 9172 | if (isa<UsingShadowDecl>(*I)) |
| 9173 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9174 | else { |
| 9175 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9176 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9177 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9178 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9179 | |
| 9180 | // Expand using declarations. |
| 9181 | if (isa<UsingDecl>(InstD)) { |
| 9182 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 9183 | for (auto *I : UD->shadows()) |
| 9184 | R.addDecl(I); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9185 | continue; |
| 9186 | } |
| 9187 | |
| 9188 | R.addDecl(InstD); |
| 9189 | } |
| 9190 | |
| 9191 | R.resolveKind(); |
| 9192 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9193 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 9194 | if (Old->getNamingClass()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9195 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9196 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9197 | Old->getMemberLoc(), |
| 9198 | Old->getNamingClass())); |
| 9199 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9200 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9201 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9202 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9203 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9204 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9205 | TemplateArgumentListInfo TransArgs; |
| 9206 | if (Old->hasExplicitTemplateArgs()) { |
| 9207 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 9208 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9209 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 9210 | Old->getNumTemplateArgs(), |
| 9211 | TransArgs)) |
| 9212 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9213 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9214 | |
| 9215 | // FIXME: to do this check properly, we will need to preserve the |
| 9216 | // first-qualifier-in-scope here, just in case we had a dependent |
| 9217 | // base (and therefore couldn't do the check) and a |
| 9218 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9219 | NamedDecl *FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9220 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9221 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9222 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9223 | Old->getOperatorLoc(), |
| 9224 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9225 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9226 | TemplateKWLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9227 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9228 | R, |
| 9229 | (Old->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9230 | ? &TransArgs : nullptr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9231 | } |
| 9232 | |
| 9233 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9234 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9235 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Alexis Hunt | 414e3e3 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 9236 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9237 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 9238 | if (SubExpr.isInvalid()) |
| 9239 | return ExprError(); |
| 9240 | |
| 9241 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9242 | return E; |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9243 | |
| 9244 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 9245 | } |
| 9246 | |
| 9247 | template<typename Derived> |
| 9248 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9249 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9250 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 9251 | if (Pattern.isInvalid()) |
| 9252 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9253 | |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9254 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9255 | return E; |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9256 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 9257 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 9258 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9259 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9260 | |
| 9261 | template<typename Derived> |
| 9262 | ExprResult |
| 9263 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 9264 | // If E is not value-dependent, then nothing will change when we transform it. |
| 9265 | // Note: This is an instantiation-centric view. |
| 9266 | if (!E->isValueDependent()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9267 | return E; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9268 | |
| 9269 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 9270 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9271 | // so |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9272 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 9273 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 9274 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9275 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9276 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 9277 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 9278 | ShouldExpand, RetainExpansion, |
| 9279 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9280 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9281 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9282 | if (RetainExpansion) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9283 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9284 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9285 | NamedDecl *Pack = E->getPack(); |
| 9286 | if (!ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9287 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9288 | Pack)); |
| 9289 | if (!Pack) |
| 9290 | return ExprError(); |
| 9291 | } |
| 9292 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9293 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9294 | // We now know the length of the parameter pack, so build a new expression |
| 9295 | // that stores that length. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9296 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 9297 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9298 | NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9299 | } |
| 9300 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9301 | template<typename Derived> |
| 9302 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 9303 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 9304 | SubstNonTypeTemplateParmPackExpr *E) { |
| 9305 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9306 | return E; |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 9307 | } |
| 9308 | |
| 9309 | template<typename Derived> |
| 9310 | ExprResult |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 9311 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 9312 | SubstNonTypeTemplateParmExpr *E) { |
| 9313 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9314 | return E; |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 9315 | } |
| 9316 | |
| 9317 | template<typename Derived> |
| 9318 | ExprResult |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 9319 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 9320 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9321 | return E; |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 9322 | } |
| 9323 | |
| 9324 | template<typename Derived> |
| 9325 | ExprResult |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 9326 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 9327 | MaterializeTemporaryExpr *E) { |
| 9328 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 9329 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9330 | |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 9331 | template<typename Derived> |
| 9332 | ExprResult |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 9333 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 9334 | CXXStdInitializerListExpr *E) { |
| 9335 | return getDerived().TransformExpr(E->getSubExpr()); |
| 9336 | } |
| 9337 | |
| 9338 | template<typename Derived> |
| 9339 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9340 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9341 | return SemaRef.MaybeBindToTemporary(E); |
| 9342 | } |
| 9343 | |
| 9344 | template<typename Derived> |
| 9345 | ExprResult |
| 9346 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9347 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9348 | } |
| 9349 | |
| 9350 | template<typename Derived> |
| 9351 | ExprResult |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 9352 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 9353 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 9354 | if (SubExpr.isInvalid()) |
| 9355 | return ExprError(); |
| 9356 | |
| 9357 | if (!getDerived().AlwaysRebuild() && |
| 9358 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9359 | return E; |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 9360 | |
| 9361 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9362 | } |
| 9363 | |
| 9364 | template<typename Derived> |
| 9365 | ExprResult |
| 9366 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 9367 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9368 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9369 | bool ArgChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9370 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9371 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 9372 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9373 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9374 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 9375 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9376 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9377 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 9378 | Elements.data(), |
| 9379 | Elements.size()); |
| 9380 | } |
| 9381 | |
| 9382 | template<typename Derived> |
| 9383 | ExprResult |
| 9384 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9385 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9386 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9387 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9388 | bool ArgChanged = false; |
| 9389 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 9390 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9391 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9392 | if (OrigElement.isPackExpansion()) { |
| 9393 | // This key/value element is a pack expansion. |
| 9394 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 9395 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 9396 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 9397 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 9398 | |
| 9399 | // Determine whether the set of unexpanded parameter packs can |
| 9400 | // and should be expanded. |
| 9401 | bool Expand = true; |
| 9402 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9403 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 9404 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9405 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 9406 | OrigElement.Value->getLocEnd()); |
| 9407 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 9408 | PatternRange, |
| 9409 | Unexpanded, |
| 9410 | Expand, RetainExpansion, |
| 9411 | NumExpansions)) |
| 9412 | return ExprError(); |
| 9413 | |
| 9414 | if (!Expand) { |
| 9415 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9416 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9417 | // expansion. |
| 9418 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 9419 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9420 | if (Key.isInvalid()) |
| 9421 | return ExprError(); |
| 9422 | |
| 9423 | if (Key.get() != OrigElement.Key) |
| 9424 | ArgChanged = true; |
| 9425 | |
| 9426 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 9427 | if (Value.isInvalid()) |
| 9428 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9429 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9430 | if (Value.get() != OrigElement.Value) |
| 9431 | ArgChanged = true; |
| 9432 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9433 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9434 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 9435 | }; |
| 9436 | Elements.push_back(Expansion); |
| 9437 | continue; |
| 9438 | } |
| 9439 | |
| 9440 | // Record right away that the argument was changed. This needs |
| 9441 | // to happen even if the array expands to nothing. |
| 9442 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9443 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9444 | // The transform has determined that we should perform an elementwise |
| 9445 | // expansion of the pattern. Do so. |
| 9446 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9447 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 9448 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9449 | if (Key.isInvalid()) |
| 9450 | return ExprError(); |
| 9451 | |
| 9452 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 9453 | if (Value.isInvalid()) |
| 9454 | return ExprError(); |
| 9455 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9456 | ObjCDictionaryElement Element = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9457 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 9458 | }; |
| 9459 | |
| 9460 | // If any unexpanded parameter packs remain, we still have a |
| 9461 | // pack expansion. |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9462 | // FIXME: Can this really happen? |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9463 | if (Key.get()->containsUnexpandedParameterPack() || |
| 9464 | Value.get()->containsUnexpandedParameterPack()) |
| 9465 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9466 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9467 | Elements.push_back(Element); |
| 9468 | } |
| 9469 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9470 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 9471 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9472 | // We've finished with this pack expansion. |
| 9473 | continue; |
| 9474 | } |
| 9475 | |
| 9476 | // Transform and check key. |
| 9477 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9478 | if (Key.isInvalid()) |
| 9479 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9480 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9481 | if (Key.get() != OrigElement.Key) |
| 9482 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9483 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9484 | // Transform and check value. |
| 9485 | ExprResult Value |
| 9486 | = getDerived().TransformExpr(OrigElement.Value); |
| 9487 | if (Value.isInvalid()) |
| 9488 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9489 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9490 | if (Value.get() != OrigElement.Value) |
| 9491 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9492 | |
| 9493 | ObjCDictionaryElement Element = { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 9494 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9495 | }; |
| 9496 | Elements.push_back(Element); |
| 9497 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9498 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9499 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 9500 | return SemaRef.MaybeBindToTemporary(E); |
| 9501 | |
| 9502 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 9503 | Elements.data(), |
| 9504 | Elements.size()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9505 | } |
| 9506 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9507 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9508 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9509 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9510 | TypeSourceInfo *EncodedTypeInfo |
| 9511 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 9512 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9513 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9514 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9515 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9516 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9517 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9518 | |
| 9519 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9520 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9521 | E->getRParenLoc()); |
| 9522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9524 | template<typename Derived> |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9525 | ExprResult TreeTransform<Derived>:: |
| 9526 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 9527 | // This is a kind of implicit conversion, and it needs to get dropped |
| 9528 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 9529 | // do, as well a more specific one: this expression is only valid when |
| 9530 | // it appears *immediately* as an argument expression. |
| 9531 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9532 | } |
| 9533 | |
| 9534 | template<typename Derived> |
| 9535 | ExprResult TreeTransform<Derived>:: |
| 9536 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9537 | TypeSourceInfo *TSInfo |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9538 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9539 | if (!TSInfo) |
| 9540 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9541 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9542 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9543 | if (Result.isInvalid()) |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9544 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9545 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9546 | if (!getDerived().AlwaysRebuild() && |
| 9547 | TSInfo == E->getTypeInfoAsWritten() && |
| 9548 | Result.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9549 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9550 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9551 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9552 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9553 | Result.get()); |
| 9554 | } |
| 9555 | |
| 9556 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9557 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9558 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9559 | // Transform arguments. |
| 9560 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9561 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9562 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9563 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9564 | &ArgChanged)) |
| 9565 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9566 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9567 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 9568 | // Class message: transform the receiver type. |
| 9569 | TypeSourceInfo *ReceiverTypeInfo |
| 9570 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 9571 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9572 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9573 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9574 | // If nothing changed, just retain the existing message send. |
| 9575 | if (!getDerived().AlwaysRebuild() && |
| 9576 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9577 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9578 | |
| 9579 | // Build a new class message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9580 | SmallVector<SourceLocation, 16> SelLocs; |
| 9581 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9582 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 9583 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9584 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9585 | E->getMethodDecl(), |
| 9586 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9587 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9588 | E->getRightLoc()); |
| 9589 | } |
| 9590 | |
| 9591 | // Instance message: transform the receiver |
| 9592 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 9593 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9594 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9595 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 9596 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9597 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9598 | |
| 9599 | // If nothing changed, just retain the existing message send. |
| 9600 | if (!getDerived().AlwaysRebuild() && |
| 9601 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9602 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9603 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9604 | // Build a new instance message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9605 | SmallVector<SourceLocation, 16> SelLocs; |
| 9606 | E->getSelectorLocs(SelLocs); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9607 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9608 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9609 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9610 | E->getMethodDecl(), |
| 9611 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9612 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9613 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9614 | } |
| 9615 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9616 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9617 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9618 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9619 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9620 | } |
| 9621 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9622 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9623 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9624 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9625 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9626 | } |
| 9627 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9628 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9629 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9630 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9631 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9632 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9633 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9634 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9635 | |
| 9636 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9637 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9638 | // If nothing changed, just retain the existing expression. |
| 9639 | if (!getDerived().AlwaysRebuild() && |
| 9640 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9641 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9642 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9643 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9644 | E->getLocation(), |
| 9645 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9646 | } |
| 9647 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9648 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9649 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9650 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9651 | // 'super' and types never change. Property never changes. Just |
| 9652 | // retain the existing expression. |
| 9653 | if (!E->isObjectReceiver()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9654 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9655 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9656 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9657 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9658 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9659 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9660 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9661 | // We don't need to transform the property; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9662 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9663 | // If nothing changed, just retain the existing expression. |
| 9664 | if (!getDerived().AlwaysRebuild() && |
| 9665 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9666 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9667 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9668 | if (E->isExplicitProperty()) |
| 9669 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 9670 | E->getExplicitProperty(), |
| 9671 | E->getLocation()); |
| 9672 | |
| 9673 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 9674 | SemaRef.Context.PseudoObjectTy, |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9675 | E->getImplicitPropertyGetter(), |
| 9676 | E->getImplicitPropertySetter(), |
| 9677 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9678 | } |
| 9679 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9680 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9681 | ExprResult |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9682 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 9683 | // Transform the base expression. |
| 9684 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 9685 | if (Base.isInvalid()) |
| 9686 | return ExprError(); |
| 9687 | |
| 9688 | // Transform the key expression. |
| 9689 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 9690 | if (Key.isInvalid()) |
| 9691 | return ExprError(); |
| 9692 | |
| 9693 | // If nothing changed, just retain the existing expression. |
| 9694 | if (!getDerived().AlwaysRebuild() && |
| 9695 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9696 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9697 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9698 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9699 | Base.get(), Key.get(), |
| 9700 | E->getAtIndexMethodDecl(), |
| 9701 | E->setAtIndexMethodDecl()); |
| 9702 | } |
| 9703 | |
| 9704 | template<typename Derived> |
| 9705 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9706 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9707 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9708 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9709 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9710 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9711 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9712 | // If nothing changed, just retain the existing expression. |
| 9713 | if (!getDerived().AlwaysRebuild() && |
| 9714 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9715 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9716 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9717 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 9718 | E->getOpLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9719 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9720 | } |
| 9721 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9722 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9723 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9724 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9725 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9726 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9727 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9728 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9729 | SubExprs, &ArgumentChanged)) |
| 9730 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9731 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9732 | if (!getDerived().AlwaysRebuild() && |
| 9733 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9734 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9735 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9736 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9737 | SubExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9738 | E->getRParenLoc()); |
| 9739 | } |
| 9740 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9741 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9742 | ExprResult |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 9743 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 9744 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 9745 | if (SrcExpr.isInvalid()) |
| 9746 | return ExprError(); |
| 9747 | |
| 9748 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9749 | if (!Type) |
| 9750 | return ExprError(); |
| 9751 | |
| 9752 | if (!getDerived().AlwaysRebuild() && |
| 9753 | Type == E->getTypeSourceInfo() && |
| 9754 | SrcExpr.get() == E->getSrcExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9755 | return E; |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 9756 | |
| 9757 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 9758 | SrcExpr.get(), Type, |
| 9759 | E->getRParenLoc()); |
| 9760 | } |
| 9761 | |
| 9762 | template<typename Derived> |
| 9763 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9764 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9765 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9766 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9767 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9768 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 9769 | |
| 9770 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 9771 | blockScope->TheDecl->setBlockMissingReturnType( |
| 9772 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9773 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9774 | SmallVector<ParmVarDecl*, 4> params; |
| 9775 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9776 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 9777 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9778 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 9779 | oldBlock->param_begin(), |
| 9780 | oldBlock->param_size(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9781 | nullptr, paramTypes, ¶ms)) { |
| 9782 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9783 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9784 | } |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9785 | |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9786 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9787 | QualType exprResultType = |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 9788 | getDerived().TransformType(exprFunctionType->getReturnType()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 9789 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9790 | QualType functionType = |
| 9791 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9792 | exprFunctionType->getExtProtoInfo()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9793 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9794 | |
| 9795 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9796 | if (!params.empty()) |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 9797 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9798 | |
| 9799 | if (!oldBlock->blockMissingReturnType()) { |
| 9800 | blockScope->HasImplicitReturnType = false; |
| 9801 | blockScope->ReturnType = exprResultType; |
| 9802 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9803 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9804 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9805 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9806 | if (body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9807 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9808 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9809 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9810 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9811 | #ifndef NDEBUG |
| 9812 | // In builds with assertions, make sure that we captured everything we |
| 9813 | // captured before. |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9814 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 9815 | for (const auto &I : oldBlock->captures()) { |
| 9816 | VarDecl *oldCapture = I.getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9817 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9818 | // Ignore parameter packs. |
| 9819 | if (isa<ParmVarDecl>(oldCapture) && |
| 9820 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 9821 | continue; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9822 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9823 | VarDecl *newCapture = |
| 9824 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 9825 | oldCapture)); |
| 9826 | assert(blockScope->CaptureMap.count(newCapture)); |
| 9827 | } |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 9828 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9829 | } |
| 9830 | #endif |
| 9831 | |
| 9832 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9833 | /*Scope=*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9834 | } |
| 9835 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9836 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9837 | ExprResult |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9838 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 9839 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9840 | } |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9841 | |
| 9842 | template<typename Derived> |
| 9843 | ExprResult |
| 9844 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9845 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 9846 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9847 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9848 | SubExprs.reserve(E->getNumSubExprs()); |
| 9849 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 9850 | SubExprs, &ArgumentChanged)) |
| 9851 | return ExprError(); |
| 9852 | |
| 9853 | if (!getDerived().AlwaysRebuild() && |
| 9854 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9855 | return E; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9856 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9857 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9858 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9859 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9860 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9861 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9862 | // Type reconstruction |
| 9863 | //===----------------------------------------------------------------------===// |
| 9864 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9865 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9866 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 9867 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9868 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9869 | getDerived().getBaseEntity()); |
| 9870 | } |
| 9871 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9872 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9873 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 9874 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9875 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9876 | getDerived().getBaseEntity()); |
| 9877 | } |
| 9878 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9879 | template<typename Derived> |
| 9880 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9881 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 9882 | bool WrittenAsLValue, |
| 9883 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9884 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9885 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9886 | } |
| 9887 | |
| 9888 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9889 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9890 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 9891 | QualType ClassType, |
| 9892 | SourceLocation Sigil) { |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 9893 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 9894 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9895 | } |
| 9896 | |
| 9897 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9898 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9899 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 9900 | ArrayType::ArraySizeModifier SizeMod, |
| 9901 | const llvm::APInt *Size, |
| 9902 | Expr *SizeExpr, |
| 9903 | unsigned IndexTypeQuals, |
| 9904 | SourceRange BracketsRange) { |
| 9905 | if (SizeExpr || !Size) |
| 9906 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 9907 | IndexTypeQuals, BracketsRange, |
| 9908 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9909 | |
| 9910 | QualType Types[] = { |
| 9911 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 9912 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 9913 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9914 | }; |
Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 9915 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9916 | QualType SizeType; |
| 9917 | for (unsigned I = 0; I != NumTypes; ++I) |
| 9918 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 9919 | SizeType = Types[I]; |
| 9920 | break; |
| 9921 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9922 | |
Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 9923 | // Note that we can return a VariableArrayType here in the case where |
| 9924 | // the element type was a dependent VariableArrayType. |
| 9925 | IntegerLiteral *ArraySize |
| 9926 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 9927 | /*FIXME*/BracketsRange.getBegin()); |
| 9928 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9929 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9930 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9931 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9932 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9933 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9934 | QualType |
| 9935 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9936 | ArrayType::ArraySizeModifier SizeMod, |
| 9937 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9938 | unsigned IndexTypeQuals, |
| 9939 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9940 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9941 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9942 | } |
| 9943 | |
| 9944 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9945 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9946 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9947 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9948 | unsigned IndexTypeQuals, |
| 9949 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9950 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9951 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9952 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9953 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9954 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9955 | QualType |
| 9956 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9957 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9958 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9959 | unsigned IndexTypeQuals, |
| 9960 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9961 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9962 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9963 | IndexTypeQuals, BracketsRange); |
| 9964 | } |
| 9965 | |
| 9966 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9967 | QualType |
| 9968 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9969 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9970 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9971 | unsigned IndexTypeQuals, |
| 9972 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9973 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9974 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9975 | IndexTypeQuals, BracketsRange); |
| 9976 | } |
| 9977 | |
| 9978 | template<typename Derived> |
| 9979 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9980 | unsigned NumElements, |
| 9981 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9982 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9983 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9984 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9985 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9986 | template<typename Derived> |
| 9987 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 9988 | unsigned NumElements, |
| 9989 | SourceLocation AttributeLoc) { |
| 9990 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 9991 | NumElements, true); |
| 9992 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 9993 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 9994 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9995 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9996 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9997 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9998 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9999 | QualType |
| 10000 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10001 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10002 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10003 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10005 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10006 | template<typename Derived> |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 10007 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 10008 | QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 10009 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10010 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 10011 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10012 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 10013 | getDerived().getBaseEntity(), |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10014 | EPI); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10015 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10016 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10017 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 10018 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 10019 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 10020 | } |
| 10021 | |
| 10022 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10023 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 10024 | assert(D && "no decl found"); |
| 10025 | if (D->isInvalidDecl()) return QualType(); |
| 10026 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10027 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10028 | TypeDecl *Ty; |
| 10029 | if (isa<UsingDecl>(D)) { |
| 10030 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 10031 | assert(Using->hasTypename() && |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10032 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 10033 | |
| 10034 | // A valid resolved using typename decl points to exactly one type decl. |
| 10035 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 10036 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10037 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10038 | } else { |
| 10039 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 10040 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 10041 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 10042 | } |
| 10043 | |
| 10044 | return SemaRef.Context.getTypeDeclType(Ty); |
| 10045 | } |
| 10046 | |
| 10047 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 10048 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 10049 | SourceLocation Loc) { |
| 10050 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10051 | } |
| 10052 | |
| 10053 | template<typename Derived> |
| 10054 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 10055 | return SemaRef.Context.getTypeOfType(Underlying); |
| 10056 | } |
| 10057 | |
| 10058 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 10059 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 10060 | SourceLocation Loc) { |
| 10061 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10062 | } |
| 10063 | |
| 10064 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 10065 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 10066 | UnaryTransformType::UTTKind UKind, |
| 10067 | SourceLocation Loc) { |
| 10068 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 10069 | } |
| 10070 | |
| 10071 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10072 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 10073 | TemplateName Template, |
| 10074 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 10075 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 10076 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10078 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 10079 | template<typename Derived> |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 10080 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 10081 | SourceLocation KWLoc) { |
| 10082 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 10083 | } |
| 10084 | |
| 10085 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10086 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10087 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10088 | bool TemplateKW, |
| 10089 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10090 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10091 | Template); |
| 10092 | } |
| 10093 | |
| 10094 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10095 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10096 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 10097 | const IdentifierInfo &Name, |
| 10098 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10099 | QualType ObjectType, |
| 10100 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10101 | UnqualifiedId TemplateName; |
| 10102 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10103 | Sema::TemplateTy Template; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10104 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10105 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10106 | SS, TemplateKWLoc, TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10107 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10108 | /*EnteringContext=*/false, |
| 10109 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10110 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10111 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10112 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10113 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10114 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10115 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10116 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10117 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10118 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10119 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10120 | // FIXME: Bogus location information. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10121 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10122 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10123 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10124 | Sema::TemplateTy Template; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10125 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10126 | SS, TemplateKWLoc, Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10127 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10128 | /*EnteringContext=*/false, |
| 10129 | Template); |
Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 10130 | return Template.get(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10131 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10132 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10133 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10134 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10135 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 10136 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10137 | Expr *OrigCallee, |
| 10138 | Expr *First, |
| 10139 | Expr *Second) { |
| 10140 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 10141 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10142 | |
Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 10143 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 10144 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 10145 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 10146 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 10147 | First, Second); |
| 10148 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 10149 | if (Result.isInvalid()) |
| 10150 | return ExprError(); |
| 10151 | First = Result.get(); |
| 10152 | } |
| 10153 | |
| 10154 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 10155 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 10156 | if (Result.isInvalid()) |
| 10157 | return ExprError(); |
| 10158 | Second = Result.get(); |
| 10159 | } |
| 10160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10161 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 10162 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10163 | if (!First->getType()->isOverloadableType() && |
| 10164 | !Second->getType()->isOverloadableType()) |
| 10165 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 10166 | Callee->getLocStart(), |
| 10167 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 10168 | } else if (Op == OO_Arrow) { |
| 10169 | // -> is never a builtin operation. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10170 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 10171 | } else if (Second == nullptr || isPostIncDec) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10172 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10173 | // The argument is not of overloadable type, so try to create a |
| 10174 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10175 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10176 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10177 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10178 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10179 | } |
| 10180 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10181 | if (!First->getType()->isOverloadableType() && |
| 10182 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10183 | // Neither of the arguments is an overloadable type, so try to |
| 10184 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10185 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10186 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10187 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10188 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10189 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10190 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10191 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10192 | } |
| 10193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10194 | |
| 10195 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10196 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 10197 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10198 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10199 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10200 | assert(ULE->requiresADL()); |
Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 10201 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10202 | } else { |
Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 10203 | // If we've resolved this to a particular non-member function, just call |
| 10204 | // that function. If we resolved it to a member function, |
| 10205 | // CreateOverloaded* will find that function for us. |
| 10206 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 10207 | if (!isa<CXXMethodDecl>(ND)) |
| 10208 | Functions.addDecl(ND); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10209 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10210 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10211 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10212 | Expr *Args[2] = { First, Second }; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10213 | unsigned NumArgs = 1 + (Second != nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10214 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10215 | // Create the overloaded operator invocation for unary operators. |
| 10216 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10217 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10218 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10219 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10220 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10221 | |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 10222 | if (Op == OO_Subscript) { |
| 10223 | SourceLocation LBrace; |
| 10224 | SourceLocation RBrace; |
| 10225 | |
| 10226 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 10227 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 10228 | LBrace = SourceLocation::getFromRawEncoding( |
| 10229 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 10230 | RBrace = SourceLocation::getFromRawEncoding( |
| 10231 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 10232 | } else { |
| 10233 | LBrace = Callee->getLocStart(); |
| 10234 | RBrace = OpLoc; |
| 10235 | } |
| 10236 | |
| 10237 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 10238 | First, Second); |
| 10239 | } |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 10240 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10241 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10242 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10243 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10244 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 10245 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10246 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10247 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10248 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10249 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10250 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10251 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10252 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10253 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10254 | SourceLocation OperatorLoc, |
| 10255 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10256 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10257 | TypeSourceInfo *ScopeType, |
| 10258 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10259 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10260 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10261 | QualType BaseType = Base->getType(); |
| 10262 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10263 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10264 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 10265 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 10266 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10267 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10268 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10269 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10270 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10271 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10272 | /*FIXME?*/true); |
| 10273 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10274 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10275 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10276 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 10277 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 10278 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 10279 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 10280 | |
Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 10281 | // The scope type is now known to be a valid nested name specifier |
| 10282 | // component. Tack it on to the end of the nested name specifier. |
| 10283 | if (ScopeType) |
| 10284 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 10285 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10286 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10287 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10288 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10289 | OperatorLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10290 | SS, TemplateKWLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10291 | /*FIXME: FirstQualifier*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10292 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10293 | /*TemplateArgs*/ nullptr); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10294 | } |
| 10295 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 10296 | template<typename Derived> |
| 10297 | StmtResult |
| 10298 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 10299 | SourceLocation Loc = S->getLocStart(); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 10300 | CapturedDecl *CD = S->getCapturedDecl(); |
| 10301 | unsigned NumParams = CD->getNumParams(); |
| 10302 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 10303 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 10304 | for (unsigned I = 0; I < NumParams; ++I) { |
| 10305 | if (I != ContextParamPos) { |
| 10306 | Params.push_back( |
| 10307 | std::make_pair( |
| 10308 | CD->getParam(I)->getName(), |
| 10309 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 10310 | } else { |
| 10311 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 10312 | } |
| 10313 | } |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10314 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 10315 | S->getCapturedRegionKind(), Params); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10316 | StmtResult Body; |
| 10317 | { |
| 10318 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 10319 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 10320 | } |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 10321 | |
| 10322 | if (Body.isInvalid()) { |
| 10323 | getSema().ActOnCapturedRegionError(); |
| 10324 | return StmtError(); |
| 10325 | } |
| 10326 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 10327 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 10328 | } |
| 10329 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10330 | } // end namespace clang |
| 10331 | |
| 10332 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |