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, |
Warren Hunt | b530bc0 | 2014-07-19 00:45:07 +0000 | [diff] [blame^] | 1656 | Stmt *TryBlock, Stmt *Handler, int HandlerIndex, |
| 1657 | int HandlerParentIndex) { |
| 1658 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler, |
| 1659 | HandlerIndex, HandlerParentIndex); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1662 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1663 | Stmt *Block) { |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1664 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1667 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| 1668 | return getSema().ActOnSEHFinallyBlock(Loc, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1671 | /// \brief Build a new expression that references a declaration. |
| 1672 | /// |
| 1673 | /// By default, performs semantic analysis to build the new expression. |
| 1674 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1675 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1676 | LookupResult &R, |
| 1677 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1678 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1679 | } |
| 1680 | |
| 1681 | |
| 1682 | /// \brief Build a new expression that references a declaration. |
| 1683 | /// |
| 1684 | /// By default, performs semantic analysis to build the new expression. |
| 1685 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1686 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1687 | ValueDecl *VD, |
| 1688 | const DeclarationNameInfo &NameInfo, |
| 1689 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1690 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1691 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1692 | |
| 1693 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1694 | |
| 1695 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | } |
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 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1699 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1700 | /// By default, performs semantic analysis to build the new expression. |
| 1701 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1702 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1703 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1704 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1707 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1709 | /// By default, performs semantic analysis to build the new expression. |
| 1710 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1711 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1712 | SourceLocation OperatorLoc, |
| 1713 | bool isArrow, |
| 1714 | CXXScopeSpec &SS, |
| 1715 | TypeSourceInfo *ScopeType, |
| 1716 | SourceLocation CCLoc, |
| 1717 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1718 | PseudoDestructorTypeStorage Destroyed); |
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 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1722 | /// By default, performs semantic analysis to build the new expression. |
| 1723 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1724 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1725 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1726 | Expr *SubExpr) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1727 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1728 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1730 | /// \brief Build a new builtin offsetof expression. |
| 1731 | /// |
| 1732 | /// By default, performs semantic analysis to build the new expression. |
| 1733 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1734 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1735 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1736 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1737 | unsigned NumComponents, |
| 1738 | SourceLocation RParenLoc) { |
| 1739 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1740 | NumComponents, RParenLoc); |
| 1741 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1742 | |
| 1743 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1744 | /// type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1745 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1746 | /// By default, performs semantic analysis to build the new expression. |
| 1747 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1748 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1749 | SourceLocation OpLoc, |
| 1750 | UnaryExprOrTypeTrait ExprKind, |
| 1751 | SourceRange R) { |
| 1752 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1755 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1756 | /// expression argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1757 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1758 | /// By default, performs semantic analysis to build the new expression. |
| 1759 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1760 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1761 | UnaryExprOrTypeTrait ExprKind, |
| 1762 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1763 | ExprResult Result |
Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1764 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1765 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1766 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1768 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1769 | } |
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 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1772 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1773 | /// By default, performs semantic analysis to build the new expression. |
| 1774 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1775 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1776 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1777 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1778 | SourceLocation RBracketLoc) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1779 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1780 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1781 | RBracketLoc); |
| 1782 | } |
| 1783 | |
| 1784 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1785 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1786 | /// By default, performs semantic analysis to build the new expression. |
| 1787 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1788 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1789 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1790 | SourceLocation RParenLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1791 | Expr *ExecConfig = nullptr) { |
| 1792 | return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1793 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1797 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1798 | /// By default, performs semantic analysis to build the new expression. |
| 1799 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1800 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1801 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1802 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1803 | SourceLocation TemplateKWLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1804 | const DeclarationNameInfo &MemberNameInfo, |
| 1805 | ValueDecl *Member, |
| 1806 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1807 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1808 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1809 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1810 | isArrow); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1811 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1812 | // We have a reference to an unnamed field. This is always the |
| 1813 | // base of an anonymous struct/union member access, i.e. the |
| 1814 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1815 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1816 | assert(Member->getType()->isRecordType() && |
| 1817 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1818 | |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1819 | BaseResult = |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1820 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1821 | QualifierLoc.getNestedNameSpecifier(), |
| 1822 | FoundDecl, Member); |
| 1823 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1824 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1825 | Base = BaseResult.get(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1826 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1827 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1828 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1829 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1830 | cast<FieldDecl>(Member)->getType(), |
| 1831 | VK, OK_Ordinary); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1832 | return ME; |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1833 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1835 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1836 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1837 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1838 | Base = BaseResult.get(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1839 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1840 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1841 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1842 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1843 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1844 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1845 | R.resolveKind(); |
| 1846 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1847 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1848 | SS, TemplateKWLoc, |
| 1849 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1850 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1851 | } |
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 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1855 | /// By default, performs semantic analysis to build the new expression. |
| 1856 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1857 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1858 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1859 | Expr *LHS, Expr *RHS) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1860 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1865 | /// By default, performs semantic analysis to build the new expression. |
| 1866 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1867 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1868 | SourceLocation QuestionLoc, |
| 1869 | Expr *LHS, |
| 1870 | SourceLocation ColonLoc, |
| 1871 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1872 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1873 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1876 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1878 | /// By default, performs semantic analysis to build the new expression. |
| 1879 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1880 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1881 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1882 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1883 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1884 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1885 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1886 | } |
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 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1889 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1890 | /// By default, performs semantic analysis to build the new expression. |
| 1891 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1892 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1893 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1894 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1895 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1896 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1897 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1898 | } |
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 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1902 | /// By default, performs semantic analysis to build the new expression. |
| 1903 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1904 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1905 | SourceLocation OpLoc, |
| 1906 | SourceLocation AccessorLoc, |
| 1907 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1908 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1909 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1910 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1911 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1912 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1913 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1914 | /*FirstQualifierInScope*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1915 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1916 | /* TemplateArgs */ nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1917 | } |
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 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1920 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1921 | /// By default, performs semantic analysis to build the new expression. |
| 1922 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1923 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1924 | MultiExprArg Inits, |
| 1925 | SourceLocation RBraceLoc, |
| 1926 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1927 | ExprResult Result |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1928 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1929 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1930 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1931 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1932 | // Patch in the result type we were given, which may have been computed |
| 1933 | // when the initial InitListExpr was built. |
| 1934 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1935 | ILE->setType(ResultTy); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1936 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1937 | } |
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 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1940 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1941 | /// By default, performs semantic analysis to build the new expression. |
| 1942 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1943 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1944 | MultiExprArg ArrayExprs, |
| 1945 | SourceLocation EqualOrColonLoc, |
| 1946 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1947 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1948 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1950 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1951 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1952 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1953 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1954 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1955 | } |
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 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1959 | /// By default, builds the implicit value initialization without performing |
| 1960 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1961 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1962 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1963 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1964 | } |
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 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1967 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1968 | /// By default, performs semantic analysis to build the new expression. |
| 1969 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1970 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1971 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1972 | SourceLocation RParenLoc) { |
| 1973 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1974 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1975 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1980 | /// By default, performs semantic analysis to build the new expression. |
| 1981 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1982 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1983 | MultiExprArg SubExprs, |
| 1984 | SourceLocation RParenLoc) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1985 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1986 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1987 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1988 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1989 | /// |
| 1990 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1991 | /// rather than attempting to map the label statement itself. |
| 1992 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1993 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1994 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1995 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1996 | } |
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 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2000 | /// By default, performs semantic analysis to build the new expression. |
| 2001 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2002 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2003 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2004 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2005 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2006 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2007 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2008 | /// \brief Build a new __builtin_choose_expr expression. |
| 2009 | /// |
| 2010 | /// By default, performs semantic analysis to build the new expression. |
| 2011 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2012 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2013 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | SourceLocation RParenLoc) { |
| 2015 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2016 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2017 | RParenLoc); |
| 2018 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2019 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2020 | /// \brief Build a new generic selection expression. |
| 2021 | /// |
| 2022 | /// By default, performs semantic analysis to build the new expression. |
| 2023 | /// Subclasses may override this routine to provide different behavior. |
| 2024 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2025 | SourceLocation DefaultLoc, |
| 2026 | SourceLocation RParenLoc, |
| 2027 | Expr *ControllingExpr, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2028 | ArrayRef<TypeSourceInfo *> Types, |
| 2029 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2030 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2031 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2034 | /// \brief Build a new overloaded operator call expression. |
| 2035 | /// |
| 2036 | /// By default, performs semantic analysis to build the new expression. |
| 2037 | /// The semantic analysis provides the behavior of template instantiation, |
| 2038 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2039 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2040 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2041 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2042 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2043 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2044 | Expr *Callee, |
| 2045 | Expr *First, |
| 2046 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2047 | |
| 2048 | /// \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] | 2049 | /// reinterpret_cast. |
| 2050 | /// |
| 2051 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2052 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2053 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2054 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2055 | Stmt::StmtClass Class, |
| 2056 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2057 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2058 | SourceLocation RAngleLoc, |
| 2059 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2060 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2061 | SourceLocation RParenLoc) { |
| 2062 | switch (Class) { |
| 2063 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2064 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2065 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2066 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2067 | |
| 2068 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2069 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2070 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2071 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2072 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2073 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2074 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2075 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2076 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2077 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2078 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2079 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2080 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2081 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2082 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2083 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2084 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2085 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2086 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2087 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2089 | /// \brief Build a new C++ static_cast expression. |
| 2090 | /// |
| 2091 | /// By default, performs semantic analysis to build the new expression. |
| 2092 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2093 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2094 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2095 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2096 | SourceLocation RAngleLoc, |
| 2097 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2098 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2099 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2100 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2101 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2102 | SourceRange(LAngleLoc, RAngleLoc), |
| 2103 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | /// \brief Build a new C++ dynamic_cast expression. |
| 2107 | /// |
| 2108 | /// By default, performs semantic analysis to build the new expression. |
| 2109 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2110 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2111 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2112 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2113 | SourceLocation RAngleLoc, |
| 2114 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2115 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2116 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2117 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2118 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2119 | SourceRange(LAngleLoc, RAngleLoc), |
| 2120 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | /// \brief Build a new C++ reinterpret_cast expression. |
| 2124 | /// |
| 2125 | /// By default, performs semantic analysis to build the new expression. |
| 2126 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2127 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2128 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2129 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2130 | SourceLocation RAngleLoc, |
| 2131 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2132 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2133 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2134 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2135 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2136 | SourceRange(LAngleLoc, RAngleLoc), |
| 2137 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | /// \brief Build a new C++ const_cast expression. |
| 2141 | /// |
| 2142 | /// By default, performs semantic analysis to build the new expression. |
| 2143 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2144 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2145 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2146 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2147 | SourceLocation RAngleLoc, |
| 2148 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2149 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2150 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2151 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2152 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2153 | SourceRange(LAngleLoc, RAngleLoc), |
| 2154 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2155 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2156 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2157 | /// \brief Build a new C++ functional-style cast expression. |
| 2158 | /// |
| 2159 | /// By default, performs semantic analysis to build the new expression. |
| 2160 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2161 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2162 | SourceLocation LParenLoc, |
| 2163 | Expr *Sub, |
| 2164 | SourceLocation RParenLoc) { |
| 2165 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2166 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2167 | RParenLoc); |
| 2168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2169 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2170 | /// \brief Build a new C++ typeid(type) expression. |
| 2171 | /// |
| 2172 | /// By default, performs semantic analysis to build the new expression. |
| 2173 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2174 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2175 | SourceLocation TypeidLoc, |
| 2176 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2177 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2178 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2179 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2180 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2181 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2182 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2183 | /// \brief Build a new C++ typeid(expr) expression. |
| 2184 | /// |
| 2185 | /// By default, performs semantic analysis to build the new expression. |
| 2186 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2187 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2188 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2189 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2190 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2191 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2192 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2195 | /// \brief Build a new C++ __uuidof(type) expression. |
| 2196 | /// |
| 2197 | /// By default, performs semantic analysis to build the new expression. |
| 2198 | /// Subclasses may override this routine to provide different behavior. |
| 2199 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2200 | SourceLocation TypeidLoc, |
| 2201 | TypeSourceInfo *Operand, |
| 2202 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2203 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2204 | RParenLoc); |
| 2205 | } |
| 2206 | |
| 2207 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2208 | /// |
| 2209 | /// By default, performs semantic analysis to build the new expression. |
| 2210 | /// Subclasses may override this routine to provide different behavior. |
| 2211 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2212 | SourceLocation TypeidLoc, |
| 2213 | Expr *Operand, |
| 2214 | SourceLocation RParenLoc) { |
| 2215 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2216 | RParenLoc); |
| 2217 | } |
| 2218 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2219 | /// \brief Build a new C++ "this" expression. |
| 2220 | /// |
| 2221 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2222 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2223 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2224 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2225 | QualType ThisType, |
| 2226 | bool isImplicit) { |
Eli Friedman | 20139d3 | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2227 | getSema().CheckCXXThisCapture(ThisLoc); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2228 | return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | /// \brief Build a new C++ throw expression. |
| 2232 | /// |
| 2233 | /// By default, performs semantic analysis to build the new expression. |
| 2234 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2235 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2236 | bool IsThrownVariableInScope) { |
| 2237 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | /// \brief Build a new C++ default-argument expression. |
| 2241 | /// |
| 2242 | /// By default, builds a new default-argument expression, which does not |
| 2243 | /// require any semantic analysis. Subclasses may override this routine to |
| 2244 | /// provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2245 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2246 | ParmVarDecl *Param) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2247 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2250 | /// \brief Build a new C++11 default-initialization expression. |
| 2251 | /// |
| 2252 | /// By default, builds a new default field initialization expression, which |
| 2253 | /// does not require any semantic analysis. Subclasses may override this |
| 2254 | /// routine to provide different behavior. |
| 2255 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2256 | FieldDecl *Field) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2257 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field); |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2260 | /// \brief Build a new C++ zero-initialization expression. |
| 2261 | /// |
| 2262 | /// By default, performs semantic analysis to build the new expression. |
| 2263 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2264 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2265 | SourceLocation LParenLoc, |
| 2266 | SourceLocation RParenLoc) { |
| 2267 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2268 | None, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2269 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2270 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2271 | /// \brief Build a new C++ "new" expression. |
| 2272 | /// |
| 2273 | /// By default, performs semantic analysis to build the new expression. |
| 2274 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2275 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2276 | bool UseGlobal, |
| 2277 | SourceLocation PlacementLParen, |
| 2278 | MultiExprArg PlacementArgs, |
| 2279 | SourceLocation PlacementRParen, |
| 2280 | SourceRange TypeIdParens, |
| 2281 | QualType AllocatedType, |
| 2282 | TypeSourceInfo *AllocatedTypeInfo, |
| 2283 | Expr *ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2284 | SourceRange DirectInitRange, |
| 2285 | Expr *Initializer) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2286 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2287 | PlacementLParen, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2288 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2289 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2290 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2291 | AllocatedType, |
| 2292 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2293 | ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2294 | DirectInitRange, |
| 2295 | Initializer); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2297 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2298 | /// \brief Build a new C++ "delete" expression. |
| 2299 | /// |
| 2300 | /// By default, performs semantic analysis to build the new expression. |
| 2301 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2302 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2303 | bool IsGlobalDelete, |
| 2304 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2305 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2306 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2307 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2309 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2310 | /// \brief Build a new type trait expression. |
| 2311 | /// |
| 2312 | /// By default, performs semantic analysis to build the new expression. |
| 2313 | /// Subclasses may override this routine to provide different behavior. |
| 2314 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2315 | SourceLocation StartLoc, |
| 2316 | ArrayRef<TypeSourceInfo *> Args, |
| 2317 | SourceLocation RParenLoc) { |
| 2318 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2319 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2320 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2321 | /// \brief Build a new array type trait expression. |
| 2322 | /// |
| 2323 | /// By default, performs semantic analysis to build the new expression. |
| 2324 | /// Subclasses may override this routine to provide different behavior. |
| 2325 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2326 | SourceLocation StartLoc, |
| 2327 | TypeSourceInfo *TSInfo, |
| 2328 | Expr *DimExpr, |
| 2329 | SourceLocation RParenLoc) { |
| 2330 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2331 | } |
| 2332 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2333 | /// \brief Build a new expression trait expression. |
| 2334 | /// |
| 2335 | /// By default, performs semantic analysis to build the new expression. |
| 2336 | /// Subclasses may override this routine to provide different behavior. |
| 2337 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2338 | SourceLocation StartLoc, |
| 2339 | Expr *Queried, |
| 2340 | SourceLocation RParenLoc) { |
| 2341 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2342 | } |
| 2343 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2344 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2345 | /// expression. |
| 2346 | /// |
| 2347 | /// By default, performs semantic analysis to build the new expression. |
| 2348 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2349 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2350 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2351 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2352 | const DeclarationNameInfo &NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2353 | const TemplateArgumentListInfo *TemplateArgs, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2354 | bool IsAddressOfOperand, |
| 2355 | TypeSourceInfo **RecoveryTSI) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2356 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2357 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2358 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2359 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2360 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2361 | TemplateArgs); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2362 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2363 | return getSema().BuildQualifiedDeclarationNameExpr( |
| 2364 | SS, NameInfo, IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | /// \brief Build a new template-id expression. |
| 2368 | /// |
| 2369 | /// By default, performs semantic analysis to build the new expression. |
| 2370 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2371 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2372 | SourceLocation TemplateKWLoc, |
| 2373 | LookupResult &R, |
| 2374 | bool RequiresADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2375 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2376 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2377 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | /// \brief Build a new object-construction expression. |
| 2381 | /// |
| 2382 | /// By default, performs semantic analysis to build the new expression. |
| 2383 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2384 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2385 | SourceLocation Loc, |
| 2386 | CXXConstructorDecl *Constructor, |
| 2387 | bool IsElidable, |
| 2388 | MultiExprArg Args, |
| 2389 | bool HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2390 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2391 | bool StdInitListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2392 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2393 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2394 | SourceRange ParenRange) { |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2395 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2396 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2397 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2398 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2399 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2400 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2401 | ConvertedArgs, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2402 | HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2403 | ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2404 | StdInitListInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2405 | RequiresZeroInit, ConstructKind, |
| 2406 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | /// \brief Build a new object-construction expression. |
| 2410 | /// |
| 2411 | /// By default, performs semantic analysis to build the new expression. |
| 2412 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2413 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2414 | SourceLocation LParenLoc, |
| 2415 | MultiExprArg Args, |
| 2416 | SourceLocation RParenLoc) { |
| 2417 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2418 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2419 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2420 | RParenLoc); |
| 2421 | } |
| 2422 | |
| 2423 | /// \brief Build a new object-construction expression. |
| 2424 | /// |
| 2425 | /// By default, performs semantic analysis to build the new expression. |
| 2426 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2427 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2428 | SourceLocation LParenLoc, |
| 2429 | MultiExprArg Args, |
| 2430 | SourceLocation RParenLoc) { |
| 2431 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2432 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2433 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2434 | RParenLoc); |
| 2435 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2436 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2437 | /// \brief Build a new member reference expression. |
| 2438 | /// |
| 2439 | /// By default, performs semantic analysis to build the new expression. |
| 2440 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2441 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2442 | QualType BaseType, |
| 2443 | bool IsArrow, |
| 2444 | SourceLocation OperatorLoc, |
| 2445 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2446 | SourceLocation TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2447 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2448 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2449 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2450 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2451 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2452 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2453 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2454 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2455 | SS, TemplateKWLoc, |
| 2456 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2457 | MemberNameInfo, |
| 2458 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2461 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2462 | /// |
| 2463 | /// By default, performs semantic analysis to build the new expression. |
| 2464 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2465 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2466 | SourceLocation OperatorLoc, |
| 2467 | bool IsArrow, |
| 2468 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2469 | SourceLocation TemplateKWLoc, |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2470 | NamedDecl *FirstQualifierInScope, |
| 2471 | LookupResult &R, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2472 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2473 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2474 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2475 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2476 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2477 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2478 | SS, TemplateKWLoc, |
| 2479 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2480 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2481 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2482 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2483 | /// \brief Build a new noexcept expression. |
| 2484 | /// |
| 2485 | /// By default, performs semantic analysis to build the new expression. |
| 2486 | /// Subclasses may override this routine to provide different behavior. |
| 2487 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2488 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2489 | } |
| 2490 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2491 | /// \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] | 2492 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2493 | SourceLocation PackLoc, |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2494 | SourceLocation RParenLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2495 | Optional<unsigned> Length) { |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2496 | if (Length) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2497 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2498 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2499 | RParenLoc, *Length); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2500 | |
| 2501 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2502 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2503 | RParenLoc); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2504 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2505 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2506 | /// \brief Build a new Objective-C boxed expression. |
| 2507 | /// |
| 2508 | /// By default, performs semantic analysis to build the new expression. |
| 2509 | /// Subclasses may override this routine to provide different behavior. |
| 2510 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2511 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2512 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2513 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2514 | /// \brief Build a new Objective-C array literal. |
| 2515 | /// |
| 2516 | /// By default, performs semantic analysis to build the new expression. |
| 2517 | /// Subclasses may override this routine to provide different behavior. |
| 2518 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2519 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2520 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2521 | MultiExprArg(Elements, NumElements)); |
| 2522 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2523 | |
| 2524 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2525 | Expr *Base, Expr *Key, |
| 2526 | ObjCMethodDecl *getterMethod, |
| 2527 | ObjCMethodDecl *setterMethod) { |
| 2528 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2529 | getterMethod, setterMethod); |
| 2530 | } |
| 2531 | |
| 2532 | /// \brief Build a new Objective-C dictionary literal. |
| 2533 | /// |
| 2534 | /// By default, performs semantic analysis to build the new expression. |
| 2535 | /// Subclasses may override this routine to provide different behavior. |
| 2536 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2537 | ObjCDictionaryElement *Elements, |
| 2538 | unsigned NumElements) { |
| 2539 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2540 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2541 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2542 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2543 | /// |
| 2544 | /// By default, performs semantic analysis to build the new expression. |
| 2545 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2546 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2547 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2548 | SourceLocation RParenLoc) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2549 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2550 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2551 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2552 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2553 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2554 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2555 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2556 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2557 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2558 | MultiExprArg Args, |
| 2559 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2560 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2561 | ReceiverTypeInfo->getType(), |
| 2562 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2563 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2564 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2568 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2569 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2570 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2571 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2572 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2573 | MultiExprArg Args, |
| 2574 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2575 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2576 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2577 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2578 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2579 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2582 | /// \brief Build a new Objective-C ivar reference expression. |
| 2583 | /// |
| 2584 | /// By default, performs semantic analysis to build the new expression. |
| 2585 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2586 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2587 | SourceLocation IvarLoc, |
| 2588 | bool IsArrow, bool IsFreeIvar) { |
| 2589 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2590 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2591 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| 2592 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2593 | /*FIXME:*/IvarLoc, IsArrow, |
| 2594 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2595 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2596 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2597 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2598 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2599 | |
| 2600 | /// \brief Build a new Objective-C property reference expression. |
| 2601 | /// |
| 2602 | /// By default, performs semantic analysis to build the new expression. |
| 2603 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2604 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2605 | ObjCPropertyDecl *Property, |
| 2606 | SourceLocation PropertyLoc) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2607 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2608 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 2609 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 2610 | /*FIXME:*/PropertyLoc, |
| 2611 | /*IsArrow=*/false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2612 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2613 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2614 | NameInfo, |
| 2615 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2616 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2617 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2618 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2619 | /// |
| 2620 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2621 | /// Subclasses may override this routine to provide different behavior. |
| 2622 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2623 | ObjCMethodDecl *Getter, |
| 2624 | ObjCMethodDecl *Setter, |
| 2625 | SourceLocation PropertyLoc) { |
| 2626 | // Since these expressions can only be value-dependent, we do not |
| 2627 | // need to perform semantic analysis again. |
| 2628 | return Owned( |
| 2629 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2630 | VK_LValue, OK_ObjCProperty, |
| 2631 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2634 | /// \brief Build a new Objective-C "isa" expression. |
| 2635 | /// |
| 2636 | /// By default, performs semantic analysis to build the new expression. |
| 2637 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2638 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2639 | SourceLocation OpLoc, bool IsArrow) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2640 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2641 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 2642 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2643 | OpLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2644 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2645 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2646 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2647 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2648 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2650 | /// \brief Build a new shuffle vector expression. |
| 2651 | /// |
| 2652 | /// By default, performs semantic analysis to build the new expression. |
| 2653 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2654 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2655 | MultiExprArg SubExprs, |
| 2656 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2657 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2658 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2659 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2660 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2661 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2662 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2663 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2664 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2665 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2666 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2667 | SemaRef.Context.BuiltinFnTy, |
| 2668 | VK_RValue, BuiltinLoc); |
| 2669 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2670 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2671 | CK_BuiltinFnToFnPtr).get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2672 | |
| 2673 | // Build the CallExpr |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2674 | ExprResult TheCall = new (SemaRef.Context) CallExpr( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2675 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2676 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2677 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2678 | // Type-check the __builtin_shufflevector expression. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2679 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2680 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2681 | |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 2682 | /// \brief Build a new convert vector expression. |
| 2683 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 2684 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 2685 | SourceLocation RParenLoc) { |
| 2686 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 2687 | BuiltinLoc, RParenLoc); |
| 2688 | } |
| 2689 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2690 | /// \brief Build a new template argument pack expansion. |
| 2691 | /// |
| 2692 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2693 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2694 | /// different behavior. |
| 2695 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2696 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2697 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2698 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2699 | case TemplateArgument::Expression: { |
| 2700 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2701 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2702 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2703 | if (Result.isInvalid()) |
| 2704 | return TemplateArgumentLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2705 | |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2706 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2707 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2708 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2709 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2710 | return TemplateArgumentLoc(TemplateArgument( |
| 2711 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2712 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2713 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2714 | Pattern.getTemplateNameLoc(), |
| 2715 | EllipsisLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2716 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2717 | case TemplateArgument::Null: |
| 2718 | case TemplateArgument::Integral: |
| 2719 | case TemplateArgument::Declaration: |
| 2720 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2721 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2722 | case TemplateArgument::NullPtr: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2723 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2724 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2725 | case TemplateArgument::Type: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2726 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2727 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2728 | EllipsisLoc, |
| 2729 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2730 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2731 | Expansion); |
| 2732 | break; |
| 2733 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2734 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2735 | return TemplateArgumentLoc(); |
| 2736 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2737 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2738 | /// \brief Build a new expression pack expansion. |
| 2739 | /// |
| 2740 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2741 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2742 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2743 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2744 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2745 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2746 | } |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2747 | |
| 2748 | /// \brief Build a new atomic operation expression. |
| 2749 | /// |
| 2750 | /// By default, performs semantic analysis to build the new expression. |
| 2751 | /// Subclasses may override this routine to provide different behavior. |
| 2752 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2753 | MultiExprArg SubExprs, |
| 2754 | QualType RetTy, |
| 2755 | AtomicExpr::AtomicOp Op, |
| 2756 | SourceLocation RParenLoc) { |
| 2757 | // Just create the expression; there is not any interesting semantic |
| 2758 | // analysis here because we can't actually build an AtomicExpr until |
| 2759 | // we are sure it is semantically sound. |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2760 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2761 | RParenLoc); |
| 2762 | } |
| 2763 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2764 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2765 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2766 | QualType ObjectType, |
| 2767 | NamedDecl *FirstQualifierInScope, |
| 2768 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2769 | |
| 2770 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2771 | QualType ObjectType, |
| 2772 | NamedDecl *FirstQualifierInScope, |
| 2773 | CXXScopeSpec &SS); |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 2774 | |
| 2775 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 2776 | NamedDecl *FirstQualifierInScope, |
| 2777 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2778 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2779 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2780 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2781 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2782 | if (!S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2783 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2784 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2785 | switch (S->getStmtClass()) { |
| 2786 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2787 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2788 | // Transform individual statement nodes |
| 2789 | #define STMT(Node, Parent) \ |
| 2790 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2791 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2792 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2793 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2794 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2795 | // Transform expressions by calling TransformExpr. |
| 2796 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2797 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2798 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2799 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2800 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2801 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2802 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2803 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2804 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2805 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2806 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2807 | } |
| 2808 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2809 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2811 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2812 | template<typename Derived> |
| 2813 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2814 | if (!S) |
| 2815 | return S; |
| 2816 | |
| 2817 | switch (S->getClauseKind()) { |
| 2818 | default: break; |
| 2819 | // Transform individual clause nodes |
| 2820 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2821 | case OMPC_ ## Name : \ |
| 2822 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2823 | #include "clang/Basic/OpenMPKinds.def" |
| 2824 | } |
| 2825 | |
| 2826 | return S; |
| 2827 | } |
| 2828 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2829 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2830 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2831 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2832 | if (!E) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2833 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2834 | |
| 2835 | switch (E->getStmtClass()) { |
| 2836 | case Stmt::NoStmtClass: break; |
| 2837 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2838 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2839 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2840 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2841 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2842 | } |
| 2843 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2844 | return E; |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | template<typename Derived> |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2848 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 2849 | bool CXXDirectInit) { |
| 2850 | // Initializers are instantiated like expressions, except that various outer |
| 2851 | // layers are stripped. |
| 2852 | if (!Init) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2853 | return Init; |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2854 | |
| 2855 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2856 | Init = ExprTemp->getSubExpr(); |
| 2857 | |
Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 2858 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 2859 | Init = MTE->GetTemporaryExpr(); |
| 2860 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2861 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 2862 | Init = Binder->getSubExpr(); |
| 2863 | |
| 2864 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 2865 | Init = ICE->getSubExprAsWritten(); |
| 2866 | |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 2867 | if (CXXStdInitializerListExpr *ILE = |
| 2868 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| 2869 | return TransformInitializer(ILE->getSubExpr(), CXXDirectInit); |
| 2870 | |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2871 | // If this is not a direct-initializer, we only need to reconstruct |
| 2872 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 2873 | // the initializer is already the right type. |
| 2874 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 2875 | if (!CXXDirectInit && !(Construct && Construct->isListInitialization())) |
| 2876 | return getDerived().TransformExpr(Init); |
| 2877 | |
| 2878 | // Revert value-initialization back to empty parens. |
| 2879 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 2880 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2881 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2882 | Parens.getEnd()); |
| 2883 | } |
| 2884 | |
| 2885 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 2886 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2887 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2888 | SourceLocation()); |
| 2889 | |
| 2890 | // Revert initialization by constructor back to a parenthesized or braced list |
| 2891 | // of expressions. Any other form of initializer can just be reused directly. |
| 2892 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2893 | return getDerived().TransformExpr(Init); |
| 2894 | |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2895 | // If the initialization implicitly converted an initializer list to a |
| 2896 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 2897 | if (Construct && Construct->isStdInitListInitialization()) |
| 2898 | return TransformInitializer(Construct->getArg(0), CXXDirectInit); |
| 2899 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2900 | SmallVector<Expr*, 8> NewArgs; |
| 2901 | bool ArgChanged = false; |
| 2902 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 2903 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| 2904 | return ExprError(); |
| 2905 | |
| 2906 | // If this was list initialization, revert to list form. |
| 2907 | if (Construct->isListInitialization()) |
| 2908 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 2909 | Construct->getLocEnd(), |
| 2910 | Construct->getType()); |
| 2911 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2912 | // Build a ParenListExpr to represent anything else. |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 2913 | SourceRange Parens = Construct->getParenOrBraceRange(); |
Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 2914 | if (Parens.isInvalid()) { |
| 2915 | // This was a variable declaration's initialization for which no initializer |
| 2916 | // was specified. |
| 2917 | assert(NewArgs.empty() && |
| 2918 | "no parens or braces but have direct init with arguments?"); |
| 2919 | return ExprEmpty(); |
| 2920 | } |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2921 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 2922 | Parens.getEnd()); |
| 2923 | } |
| 2924 | |
| 2925 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2926 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2927 | unsigned NumInputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2928 | bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2929 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2930 | bool *ArgChanged) { |
| 2931 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2932 | // If requested, drop call arguments that need to be dropped. |
| 2933 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2934 | if (ArgChanged) |
| 2935 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2936 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2937 | break; |
| 2938 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2939 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2940 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2941 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2942 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2943 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2944 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2945 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2946 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2947 | // Determine whether the set of unexpanded parameter packs can and should |
| 2948 | // be expanded. |
| 2949 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2950 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2951 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 2952 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2953 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2954 | Pattern->getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2955 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2956 | Expand, RetainExpansion, |
| 2957 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2958 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2959 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2960 | if (!Expand) { |
| 2961 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2962 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2963 | // expansion. |
| 2964 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2965 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2966 | if (OutPattern.isInvalid()) |
| 2967 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2968 | |
| 2969 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2970 | Expansion->getEllipsisLoc(), |
| 2971 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2972 | if (Out.isInvalid()) |
| 2973 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2974 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2975 | if (ArgChanged) |
| 2976 | *ArgChanged = true; |
| 2977 | Outputs.push_back(Out.get()); |
| 2978 | continue; |
| 2979 | } |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2980 | |
| 2981 | // Record right away that the argument was changed. This needs |
| 2982 | // to happen even if the array expands to nothing. |
| 2983 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2984 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2985 | // The transform has determined that we should perform an elementwise |
| 2986 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2987 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2988 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2989 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2990 | if (Out.isInvalid()) |
| 2991 | return true; |
| 2992 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 2993 | // FIXME: Can this happen? We should not try to expand the pack |
| 2994 | // in this case. |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2995 | if (Out.get()->containsUnexpandedParameterPack()) { |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 2996 | Out = getDerived().RebuildPackExpansion( |
| 2997 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2998 | if (Out.isInvalid()) |
| 2999 | return true; |
| 3000 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3001 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3002 | Outputs.push_back(Out.get()); |
| 3003 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3004 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3005 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3006 | // forgetting the partially-substituted parameter pack. |
| 3007 | if (RetainExpansion) { |
| 3008 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3009 | |
| 3010 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3011 | if (Out.isInvalid()) |
| 3012 | return true; |
| 3013 | |
| 3014 | Out = getDerived().RebuildPackExpansion( |
| 3015 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3016 | if (Out.isInvalid()) |
| 3017 | return true; |
| 3018 | |
| 3019 | Outputs.push_back(Out.get()); |
| 3020 | } |
| 3021 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3022 | continue; |
| 3023 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3024 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3025 | ExprResult Result = |
| 3026 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3027 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3028 | if (Result.isInvalid()) |
| 3029 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3030 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3031 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3032 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3033 | |
| 3034 | Outputs.push_back(Result.get()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3035 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3036 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3037 | return false; |
| 3038 | } |
| 3039 | |
| 3040 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3041 | NestedNameSpecifierLoc |
| 3042 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3043 | NestedNameSpecifierLoc NNS, |
| 3044 | QualType ObjectType, |
| 3045 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3046 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3047 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3048 | Qualifier = Qualifier.getPrefix()) |
| 3049 | Qualifiers.push_back(Qualifier); |
| 3050 | |
| 3051 | CXXScopeSpec SS; |
| 3052 | while (!Qualifiers.empty()) { |
| 3053 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3054 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3055 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3056 | switch (QNNS->getKind()) { |
| 3057 | case NestedNameSpecifier::Identifier: |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3058 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3059 | *QNNS->getAsIdentifier(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3060 | Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3061 | Q.getLocalEndLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3062 | ObjectType, false, SS, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3063 | FirstQualifierInScope, false)) |
| 3064 | return NestedNameSpecifierLoc(); |
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 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3067 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3068 | case NestedNameSpecifier::Namespace: { |
| 3069 | NamespaceDecl *NS |
| 3070 | = cast_or_null<NamespaceDecl>( |
| 3071 | getDerived().TransformDecl( |
| 3072 | Q.getLocalBeginLoc(), |
| 3073 | QNNS->getAsNamespace())); |
| 3074 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3075 | break; |
| 3076 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3077 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3078 | case NestedNameSpecifier::NamespaceAlias: { |
| 3079 | NamespaceAliasDecl *Alias |
| 3080 | = cast_or_null<NamespaceAliasDecl>( |
| 3081 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3082 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3083 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3084 | Q.getLocalEndLoc()); |
| 3085 | break; |
| 3086 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3087 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3088 | case NestedNameSpecifier::Global: |
| 3089 | // There is no meaningful transformation that one could perform on the |
| 3090 | // global scope. |
| 3091 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3092 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3093 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3094 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3095 | case NestedNameSpecifier::TypeSpec: { |
| 3096 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3097 | FirstQualifierInScope, SS); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3098 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3099 | if (!TL) |
| 3100 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3101 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3102 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3103 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3104 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3105 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3106 | "Can't get cv-qualifiers here"); |
Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3107 | if (TL.getType()->isEnumeralType()) |
| 3108 | SemaRef.Diag(TL.getBeginLoc(), |
| 3109 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3110 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3111 | Q.getLocalEndLoc()); |
| 3112 | break; |
| 3113 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3114 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3115 | // error because a previous error should have already been emitted. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3116 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3117 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3118 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3119 | << TL.getType() << SS.getRange(); |
| 3120 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3121 | return NestedNameSpecifierLoc(); |
| 3122 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3123 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3124 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3125 | // 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] | 3126 | FirstQualifierInScope = nullptr; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3127 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3128 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3129 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3130 | // 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] | 3131 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3132 | !getDerived().AlwaysRebuild()) |
| 3133 | return NNS; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3134 | |
| 3135 | // If we can re-use the source-location data from the original |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3136 | // nested-name-specifier, do so. |
| 3137 | if (SS.location_size() == NNS.getDataLength() && |
| 3138 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3139 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3140 | |
| 3141 | // Allocate new nested-name-specifier location information. |
| 3142 | return SS.getWithLocInContext(SemaRef.Context); |
| 3143 | } |
| 3144 | |
| 3145 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3146 | DeclarationNameInfo |
| 3147 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3148 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3149 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3150 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3151 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3152 | |
| 3153 | switch (Name.getNameKind()) { |
| 3154 | case DeclarationName::Identifier: |
| 3155 | case DeclarationName::ObjCZeroArgSelector: |
| 3156 | case DeclarationName::ObjCOneArgSelector: |
| 3157 | case DeclarationName::ObjCMultiArgSelector: |
| 3158 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3159 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3160 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3161 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3163 | case DeclarationName::CXXConstructorName: |
| 3164 | case DeclarationName::CXXDestructorName: |
| 3165 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3166 | TypeSourceInfo *NewTInfo; |
| 3167 | CanQualType NewCanTy; |
| 3168 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3169 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3170 | if (!NewTInfo) |
| 3171 | return DeclarationNameInfo(); |
| 3172 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3173 | } |
| 3174 | else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3175 | NewTInfo = nullptr; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3176 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3177 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3178 | if (NewT.isNull()) |
| 3179 | return DeclarationNameInfo(); |
| 3180 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3181 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3182 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3183 | DeclarationName NewName |
| 3184 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3185 | NewCanTy); |
| 3186 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3187 | NewNameInfo.setName(NewName); |
| 3188 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3189 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3193 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3198 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3199 | TemplateName Name, |
| 3200 | SourceLocation NameLoc, |
| 3201 | QualType ObjectType, |
| 3202 | NamedDecl *FirstQualifierInScope) { |
| 3203 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3204 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3205 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3206 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3207 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3208 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3209 | Template)); |
| 3210 | if (!TransTemplate) |
| 3211 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3212 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3213 | if (!getDerived().AlwaysRebuild() && |
| 3214 | SS.getScopeRep() == QTN->getQualifier() && |
| 3215 | TransTemplate == Template) |
| 3216 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3217 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3218 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3219 | TransTemplate); |
| 3220 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3221 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3222 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3223 | if (SS.getScopeRep()) { |
| 3224 | // These apply to the scope specifier, not the template. |
| 3225 | ObjectType = QualType(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3226 | FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3229 | if (!getDerived().AlwaysRebuild() && |
| 3230 | SS.getScopeRep() == DTN->getQualifier() && |
| 3231 | ObjectType.isNull()) |
| 3232 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3233 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3234 | if (DTN->isIdentifier()) { |
| 3235 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3236 | *DTN->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3237 | NameLoc, |
| 3238 | ObjectType, |
| 3239 | FirstQualifierInScope); |
| 3240 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3241 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3242 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3243 | ObjectType); |
| 3244 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3245 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3246 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3247 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3248 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3249 | Template)); |
| 3250 | if (!TransTemplate) |
| 3251 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3252 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3253 | if (!getDerived().AlwaysRebuild() && |
| 3254 | TransTemplate == Template) |
| 3255 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3256 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3257 | return TemplateName(TransTemplate); |
| 3258 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3259 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3260 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3261 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3262 | TemplateTemplateParmDecl *TransParam |
| 3263 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3264 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3265 | if (!TransParam) |
| 3266 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3267 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3268 | if (!getDerived().AlwaysRebuild() && |
| 3269 | TransParam == SubstPack->getParameterPack()) |
| 3270 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3271 | |
| 3272 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3273 | SubstPack->getArgumentPack()); |
| 3274 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3275 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3276 | // These should be getting filtered out before they reach the AST. |
| 3277 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3281 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3282 | const TemplateArgument &Arg, |
| 3283 | TemplateArgumentLoc &Output) { |
| 3284 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3285 | switch (Arg.getKind()) { |
| 3286 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3287 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3288 | break; |
| 3289 | |
| 3290 | case TemplateArgument::Type: |
| 3291 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3292 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3293 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3294 | break; |
| 3295 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3296 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3297 | case TemplateArgument::TemplateExpansion: { |
| 3298 | NestedNameSpecifierLocBuilder Builder; |
| 3299 | TemplateName Template = Arg.getAsTemplate(); |
| 3300 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3301 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3302 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3303 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3304 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3305 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3306 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3307 | Builder.getWithLocInContext(SemaRef.Context), |
| 3308 | Loc); |
| 3309 | else |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3310 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3311 | Builder.getWithLocInContext(SemaRef.Context), |
| 3312 | Loc, Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3313 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3314 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3315 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3316 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3317 | case TemplateArgument::Expression: |
| 3318 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3319 | break; |
| 3320 | |
| 3321 | case TemplateArgument::Declaration: |
| 3322 | case TemplateArgument::Integral: |
| 3323 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3324 | case TemplateArgument::NullPtr: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3325 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3326 | break; |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | template<typename Derived> |
| 3331 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3332 | const TemplateArgumentLoc &Input, |
| 3333 | TemplateArgumentLoc &Output) { |
| 3334 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3335 | switch (Arg.getKind()) { |
| 3336 | case TemplateArgument::Null: |
| 3337 | case TemplateArgument::Integral: |
Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3338 | case TemplateArgument::Pack: |
| 3339 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3340 | case TemplateArgument::NullPtr: |
| 3341 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3343 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3344 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3345 | if (!DI) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3346 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3347 | |
| 3348 | DI = getDerived().TransformType(DI); |
| 3349 | if (!DI) return true; |
| 3350 | |
| 3351 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3352 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3353 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3354 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3355 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3356 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3357 | if (QualifierLoc) { |
| 3358 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3359 | if (!QualifierLoc) |
| 3360 | return true; |
| 3361 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3362 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3363 | CXXScopeSpec SS; |
| 3364 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3365 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3366 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3367 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3368 | if (Template.isNull()) |
| 3369 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3370 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3371 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3372 | Input.getTemplateNameLoc()); |
| 3373 | return false; |
| 3374 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3375 | |
| 3376 | case TemplateArgument::TemplateExpansion: |
| 3377 | llvm_unreachable("Caller should expand pack expansions"); |
| 3378 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3379 | case TemplateArgument::Expression: { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3380 | // Template argument expressions are constant expressions. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3381 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3382 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3383 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3384 | Expr *InputExpr = Input.getSourceExpression(); |
| 3385 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3386 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3387 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3388 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3389 | if (E.isInvalid()) return true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3390 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3391 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3392 | } |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3393 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3394 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3395 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3396 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3397 | } |
| 3398 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3399 | /// \brief Iterator adaptor that invents template argument location information |
| 3400 | /// for each of the template arguments in its underlying iterator. |
| 3401 | template<typename Derived, typename InputIterator> |
| 3402 | class TemplateArgumentLocInventIterator { |
| 3403 | TreeTransform<Derived> &Self; |
| 3404 | InputIterator Iter; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3405 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3406 | public: |
| 3407 | typedef TemplateArgumentLoc value_type; |
| 3408 | typedef TemplateArgumentLoc reference; |
| 3409 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3410 | difference_type; |
| 3411 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3412 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3413 | class pointer { |
| 3414 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3415 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3416 | public: |
| 3417 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3418 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3419 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3420 | }; |
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 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3423 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3424 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3425 | InputIterator Iter) |
| 3426 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3427 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3428 | TemplateArgumentLocInventIterator &operator++() { |
| 3429 | ++Iter; |
| 3430 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3431 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3432 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3433 | TemplateArgumentLocInventIterator operator++(int) { |
| 3434 | TemplateArgumentLocInventIterator Old(*this); |
| 3435 | ++(*this); |
| 3436 | return Old; |
| 3437 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3438 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3439 | reference operator*() const { |
| 3440 | TemplateArgumentLoc Result; |
| 3441 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3442 | return Result; |
| 3443 | } |
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 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3446 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3447 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3448 | const TemplateArgumentLocInventIterator &Y) { |
| 3449 | return X.Iter == Y.Iter; |
| 3450 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3451 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3452 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3453 | const TemplateArgumentLocInventIterator &Y) { |
| 3454 | return X.Iter != Y.Iter; |
| 3455 | } |
| 3456 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3457 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3458 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3459 | template<typename InputIterator> |
| 3460 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3461 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3462 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3463 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3464 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3465 | TemplateArgumentLoc In = *First; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3466 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3467 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3468 | // Unpack argument packs, which we translate them into separate |
| 3469 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3470 | // FIXME: We could do much better if we could guarantee that the |
| 3471 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3472 | // all of the template arguments in the argument pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3473 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3474 | TemplateArgument::pack_iterator> |
| 3475 | PackLocIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3476 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3477 | In.getArgument().pack_begin()), |
| 3478 | PackLocIterator(*this, |
| 3479 | In.getArgument().pack_end()), |
| 3480 | Outputs)) |
| 3481 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3482 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3483 | continue; |
| 3484 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3485 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3486 | if (In.getArgument().isPackExpansion()) { |
| 3487 | // We have a pack expansion, for which we will be substituting into |
| 3488 | // the pattern. |
| 3489 | SourceLocation Ellipsis; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3490 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3491 | TemplateArgumentLoc Pattern |
Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3492 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3493 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3494 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3495 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3496 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3497 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3498 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3499 | // Determine whether the set of unexpanded parameter packs can and should |
| 3500 | // be expanded. |
| 3501 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3502 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3503 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3504 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3505 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3506 | Unexpanded, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3507 | Expand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3508 | RetainExpansion, |
| 3509 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3510 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3511 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3512 | if (!Expand) { |
| 3513 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3514 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3515 | // expansion. |
| 3516 | TemplateArgumentLoc OutPattern; |
| 3517 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3518 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3519 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3520 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3521 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3522 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3523 | if (Out.getArgument().isNull()) |
| 3524 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3525 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3526 | Outputs.addArgument(Out); |
| 3527 | continue; |
| 3528 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3529 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3530 | // The transform has determined that we should perform an elementwise |
| 3531 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3532 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3533 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3534 | |
| 3535 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3536 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3537 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3538 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3539 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3540 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3541 | if (Out.getArgument().isNull()) |
| 3542 | return true; |
| 3543 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3544 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3545 | Outputs.addArgument(Out); |
| 3546 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3547 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3548 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3549 | // forgetting the partially-substituted parameter pack. |
| 3550 | if (RetainExpansion) { |
| 3551 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3552 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3553 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3554 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3555 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3556 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3557 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3558 | if (Out.getArgument().isNull()) |
| 3559 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3560 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3561 | Outputs.addArgument(Out); |
| 3562 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3563 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3564 | continue; |
| 3565 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3566 | |
| 3567 | // The simple case: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3568 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3569 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3570 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3571 | Outputs.addArgument(Out); |
| 3572 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3573 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3574 | return false; |
| 3575 | |
| 3576 | } |
| 3577 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3578 | //===----------------------------------------------------------------------===// |
| 3579 | // Type transformation |
| 3580 | //===----------------------------------------------------------------------===// |
| 3581 | |
| 3582 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3583 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3584 | if (getDerived().AlreadyTransformed(T)) |
| 3585 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3586 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3587 | // Temporary workaround. All of these transformations should |
| 3588 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3589 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3590 | getDerived().getBaseLocation()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3591 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3592 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3593 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3594 | if (!NewDI) |
| 3595 | return QualType(); |
| 3596 | |
| 3597 | return NewDI->getType(); |
| 3598 | } |
| 3599 | |
| 3600 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3601 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3602 | // Refine the base location to the type's location. |
| 3603 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3604 | getDerived().getBaseEntity()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3605 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3606 | return DI; |
| 3607 | |
| 3608 | TypeLocBuilder TLB; |
| 3609 | |
| 3610 | TypeLoc TL = DI->getTypeLoc(); |
| 3611 | TLB.reserve(TL.getFullDataSize()); |
| 3612 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3613 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3614 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3615 | return nullptr; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3616 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3617 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | template<typename Derived> |
| 3621 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3622 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3623 | switch (T.getTypeLocClass()) { |
| 3624 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3625 | #define TYPELOC(CLASS, PARENT) \ |
| 3626 | case TypeLoc::CLASS: \ |
| 3627 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3628 | T.castAs<CLASS##TypeLoc>()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3629 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3630 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3632 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3636 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3637 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3638 | /// types). This is the right thing for template instantiation, but |
| 3639 | /// probably not for other clients. |
| 3640 | template<typename Derived> |
| 3641 | QualType |
| 3642 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3643 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3644 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3645 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3646 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3647 | if (Result.isNull()) |
| 3648 | return QualType(); |
| 3649 | |
| 3650 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3651 | // FIXME: this is the right thing for template instantiation, but |
| 3652 | // probably not for other clients. |
| 3653 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3654 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3655 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3656 | // 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] | 3657 | // resulting type. |
| 3658 | if (Quals.hasObjCLifetime()) { |
| 3659 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3660 | Quals.removeObjCLifetime(); |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3661 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3662 | // Objective-C ARC: |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3663 | // A lifetime qualifier applied to a substituted template parameter |
| 3664 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3665 | const AutoType *AutoTy; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3666 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3667 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3668 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3669 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3670 | Qs.removeObjCLifetime(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3671 | Replacement |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3672 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3673 | Qs); |
| 3674 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3675 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3676 | Replacement); |
| 3677 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3678 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3679 | // 'auto' types behave the same way as template parameters. |
| 3680 | QualType Deduced = AutoTy->getDeducedType(); |
| 3681 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3682 | Qs.removeObjCLifetime(); |
| 3683 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3684 | Qs); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 3685 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(), |
| 3686 | AutoTy->isDependentType()); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3687 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3688 | } else { |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3689 | // Otherwise, complain about the addition of a qualifier to an |
| 3690 | // already-qualified type. |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3691 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3692 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3693 | << Result << R; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3694 | |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3695 | Quals.removeObjCLifetime(); |
| 3696 | } |
| 3697 | } |
| 3698 | } |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3699 | if (!Quals.empty()) { |
| 3700 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3701 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3702 | if (Result.hasLocalQualifiers()) |
| 3703 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3704 | // No location information to preserve. |
| 3705 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3706 | |
| 3707 | return Result; |
| 3708 | } |
| 3709 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3710 | template<typename Derived> |
| 3711 | TypeLoc |
| 3712 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3713 | QualType ObjectType, |
| 3714 | NamedDecl *UnqualLookup, |
| 3715 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3716 | if (getDerived().AlreadyTransformed(TL.getType())) |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3717 | return TL; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3718 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3719 | TypeSourceInfo *TSI = |
| 3720 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 3721 | if (TSI) |
| 3722 | return TSI->getTypeLoc(); |
| 3723 | return TypeLoc(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3724 | } |
| 3725 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3726 | template<typename Derived> |
| 3727 | TypeSourceInfo * |
| 3728 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3729 | QualType ObjectType, |
| 3730 | NamedDecl *UnqualLookup, |
| 3731 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3732 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3733 | return TSInfo; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3734 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3735 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 3736 | UnqualLookup, SS); |
| 3737 | } |
| 3738 | |
| 3739 | template <typename Derived> |
| 3740 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 3741 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 3742 | CXXScopeSpec &SS) { |
| 3743 | QualType T = TL.getType(); |
| 3744 | assert(!getDerived().AlreadyTransformed(T)); |
| 3745 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3746 | TypeLocBuilder TLB; |
| 3747 | QualType Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3748 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3749 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3750 | TemplateSpecializationTypeLoc SpecTL = |
| 3751 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3752 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3753 | TemplateName Template |
| 3754 | = getDerived().TransformTemplateName(SS, |
| 3755 | SpecTL.getTypePtr()->getTemplateName(), |
| 3756 | SpecTL.getTemplateNameLoc(), |
| 3757 | ObjectType, UnqualLookup); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3758 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3759 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3760 | |
| 3761 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3762 | Template); |
| 3763 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3764 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3765 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3766 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3767 | TemplateName Template |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3768 | = getDerived().RebuildTemplateName(SS, |
| 3769 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3770 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3771 | ObjectType, UnqualLookup); |
| 3772 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3773 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3774 | |
| 3775 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3776 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3777 | Template, |
| 3778 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3779 | } else { |
| 3780 | // Nothing special needs to be done for these. |
| 3781 | Result = getDerived().TransformType(TLB, TL); |
| 3782 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3783 | |
| 3784 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3785 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3786 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3787 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3788 | } |
| 3789 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3790 | template <class TyLoc> static inline |
| 3791 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3792 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3793 | NewT.setNameLoc(T.getNameLoc()); |
| 3794 | return T.getType(); |
| 3795 | } |
| 3796 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3797 | template<typename Derived> |
| 3798 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3799 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3800 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3801 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3802 | if (T.needsExtraLocalData()) |
| 3803 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3804 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3806 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3807 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3808 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3809 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3810 | // FIXME: recurse? |
| 3811 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3813 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3814 | template <typename Derived> |
| 3815 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 3816 | AdjustedTypeLoc TL) { |
| 3817 | // Adjustments applied during transformation are handled elsewhere. |
| 3818 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3819 | } |
| 3820 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3821 | template<typename Derived> |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 3822 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 3823 | DecayedTypeLoc TL) { |
| 3824 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3825 | if (OriginalType.isNull()) |
| 3826 | return QualType(); |
| 3827 | |
| 3828 | QualType Result = TL.getType(); |
| 3829 | if (getDerived().AlwaysRebuild() || |
| 3830 | OriginalType != TL.getOriginalLoc().getType()) |
| 3831 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 3832 | TLB.push<DecayedTypeLoc>(Result); |
| 3833 | // Nothing to set for DecayedTypeLoc. |
| 3834 | return Result; |
| 3835 | } |
| 3836 | |
| 3837 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3838 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3839 | PointerTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3840 | QualType PointeeType |
| 3841 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3842 | if (PointeeType.isNull()) |
| 3843 | return QualType(); |
| 3844 | |
| 3845 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3846 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3847 | // A dependent pointer type 'T *' has is being transformed such |
| 3848 | // that an Objective-C class type is being replaced for 'T'. The |
| 3849 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3850 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3851 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3852 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3853 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3854 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3855 | return Result; |
| 3856 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3857 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3858 | if (getDerived().AlwaysRebuild() || |
| 3859 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3860 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3861 | if (Result.isNull()) |
| 3862 | return QualType(); |
| 3863 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3864 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3865 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3866 | // pointing to. |
| 3867 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3868 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3869 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3870 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3871 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3872 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3873 | |
| 3874 | template<typename Derived> |
| 3875 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3876 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3877 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3878 | QualType PointeeType |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3879 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3880 | if (PointeeType.isNull()) |
| 3881 | return QualType(); |
| 3882 | |
| 3883 | QualType Result = TL.getType(); |
| 3884 | if (getDerived().AlwaysRebuild() || |
| 3885 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3886 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3887 | TL.getSigilLoc()); |
| 3888 | if (Result.isNull()) |
| 3889 | return QualType(); |
| 3890 | } |
| 3891 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3892 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3893 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3894 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3897 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3898 | /// don't care whether the type itself is an l-value type or an r-value |
| 3899 | /// type; we only care if the type was *written* as an l-value type |
| 3900 | /// or an r-value type. |
| 3901 | template<typename Derived> |
| 3902 | QualType |
| 3903 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3904 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3905 | const ReferenceType *T = TL.getTypePtr(); |
| 3906 | |
| 3907 | // Note that this works with the pointee-as-written. |
| 3908 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3909 | if (PointeeType.isNull()) |
| 3910 | return QualType(); |
| 3911 | |
| 3912 | QualType Result = TL.getType(); |
| 3913 | if (getDerived().AlwaysRebuild() || |
| 3914 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3915 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3916 | T->isSpelledAsLValue(), |
| 3917 | TL.getSigilLoc()); |
| 3918 | if (Result.isNull()) |
| 3919 | return QualType(); |
| 3920 | } |
| 3921 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3922 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3923 | // referring to. |
| 3924 | TLB.TypeWasModifiedSafely( |
| 3925 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3926 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3927 | // r-value references can be rebuilt as l-value references. |
| 3928 | ReferenceTypeLoc NewTL; |
| 3929 | if (isa<LValueReferenceType>(Result)) |
| 3930 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3931 | else |
| 3932 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3933 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3934 | |
| 3935 | return Result; |
| 3936 | } |
| 3937 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3938 | template<typename Derived> |
| 3939 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3940 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3941 | LValueReferenceTypeLoc TL) { |
| 3942 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3943 | } |
| 3944 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | template<typename Derived> |
| 3946 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3947 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3948 | RValueReferenceTypeLoc TL) { |
| 3949 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3950 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3951 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3952 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3953 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3954 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3955 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3956 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3957 | if (PointeeType.isNull()) |
| 3958 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3959 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3960 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3961 | TypeSourceInfo *NewClsTInfo = nullptr; |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3962 | if (OldClsTInfo) { |
| 3963 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3964 | if (!NewClsTInfo) |
| 3965 | return QualType(); |
| 3966 | } |
| 3967 | |
| 3968 | const MemberPointerType *T = TL.getTypePtr(); |
| 3969 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3970 | QualType NewClsType; |
| 3971 | if (NewClsTInfo) |
| 3972 | NewClsType = NewClsTInfo->getType(); |
| 3973 | else { |
| 3974 | NewClsType = getDerived().TransformType(OldClsType); |
| 3975 | if (NewClsType.isNull()) |
| 3976 | return QualType(); |
| 3977 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3979 | QualType Result = TL.getType(); |
| 3980 | if (getDerived().AlwaysRebuild() || |
| 3981 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3982 | NewClsType != OldClsType) { |
| 3983 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3984 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3985 | if (Result.isNull()) |
| 3986 | return QualType(); |
| 3987 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3988 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3989 | // If we had to adjust the pointee type when building a member pointer, make |
| 3990 | // sure to push TypeLoc info for it. |
| 3991 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 3992 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 3993 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 3994 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 3995 | } |
| 3996 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3997 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3998 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3999 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4000 | |
| 4001 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4004 | template<typename Derived> |
| 4005 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4006 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4007 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4008 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4009 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4010 | if (ElementType.isNull()) |
| 4011 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4012 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4013 | QualType Result = TL.getType(); |
| 4014 | if (getDerived().AlwaysRebuild() || |
| 4015 | ElementType != T->getElementType()) { |
| 4016 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4017 | T->getSizeModifier(), |
| 4018 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4019 | T->getIndexTypeCVRQualifiers(), |
| 4020 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4021 | if (Result.isNull()) |
| 4022 | return QualType(); |
| 4023 | } |
Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4024 | |
| 4025 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4026 | // a ConstantArrayType is allowed to have an element type which is a |
| 4027 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4028 | // types have the same location layout. |
| 4029 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4030 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4031 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4033 | Expr *Size = TL.getSizeExpr(); |
| 4034 | if (Size) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4035 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4036 | Sema::ConstantEvaluated); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4037 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4038 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4039 | } |
| 4040 | NewTL.setSizeExpr(Size); |
| 4041 | |
| 4042 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4045 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4046 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4047 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4048 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4049 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4050 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4051 | if (ElementType.isNull()) |
| 4052 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4053 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4054 | QualType Result = TL.getType(); |
| 4055 | if (getDerived().AlwaysRebuild() || |
| 4056 | ElementType != T->getElementType()) { |
| 4057 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4058 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4059 | T->getIndexTypeCVRQualifiers(), |
| 4060 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4061 | if (Result.isNull()) |
| 4062 | return QualType(); |
| 4063 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4064 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4065 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4066 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4067 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4068 | NewTL.setSizeExpr(nullptr); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4069 | |
| 4070 | return Result; |
| 4071 | } |
| 4072 | |
| 4073 | template<typename Derived> |
| 4074 | QualType |
| 4075 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4076 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4077 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4078 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4079 | if (ElementType.isNull()) |
| 4080 | return QualType(); |
| 4081 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4082 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4083 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 4084 | if (SizeResult.isInvalid()) |
| 4085 | return QualType(); |
| 4086 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4087 | Expr *Size = SizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4088 | |
| 4089 | QualType Result = TL.getType(); |
| 4090 | if (getDerived().AlwaysRebuild() || |
| 4091 | ElementType != T->getElementType() || |
| 4092 | Size != T->getSizeExpr()) { |
| 4093 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4094 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4095 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4096 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4097 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4098 | if (Result.isNull()) |
| 4099 | return QualType(); |
| 4100 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4101 | |
Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4102 | // We might have constant size array now, but fortunately it has the same |
| 4103 | // location layout. |
| 4104 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4105 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4106 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4107 | NewTL.setSizeExpr(Size); |
| 4108 | |
| 4109 | return Result; |
| 4110 | } |
| 4111 | |
| 4112 | template<typename Derived> |
| 4113 | QualType |
| 4114 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4115 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4116 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4117 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4118 | if (ElementType.isNull()) |
| 4119 | return QualType(); |
| 4120 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4121 | // Array bounds are constant expressions. |
| 4122 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4123 | Sema::ConstantEvaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4124 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4125 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4126 | Expr *origSize = TL.getSizeExpr(); |
| 4127 | if (!origSize) origSize = T->getSizeExpr(); |
| 4128 | |
| 4129 | ExprResult sizeResult |
| 4130 | = getDerived().TransformExpr(origSize); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4131 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4132 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4133 | return QualType(); |
| 4134 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4135 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4136 | |
| 4137 | QualType Result = TL.getType(); |
| 4138 | if (getDerived().AlwaysRebuild() || |
| 4139 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4140 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4141 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4142 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4143 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4144 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4145 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4146 | if (Result.isNull()) |
| 4147 | return QualType(); |
| 4148 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4149 | |
| 4150 | // We might have any sort of array type now, but fortunately they |
| 4151 | // all have the same location layout. |
| 4152 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4153 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4154 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4155 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4156 | |
| 4157 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4158 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4159 | |
| 4160 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4161 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4162 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4163 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4164 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4165 | |
| 4166 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4167 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4168 | if (ElementType.isNull()) |
| 4169 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4170 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4171 | // Vector sizes are constant expressions. |
| 4172 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4173 | Sema::ConstantEvaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4174 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4175 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4176 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4177 | if (Size.isInvalid()) |
| 4178 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4179 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4180 | QualType Result = TL.getType(); |
| 4181 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4182 | ElementType != T->getElementType() || |
| 4183 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4184 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4185 | Size.get(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4186 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4187 | if (Result.isNull()) |
| 4188 | return QualType(); |
| 4189 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4190 | |
| 4191 | // Result might be dependent or not. |
| 4192 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4193 | DependentSizedExtVectorTypeLoc NewTL |
| 4194 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4195 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4196 | } else { |
| 4197 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4198 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4199 | } |
| 4200 | |
| 4201 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4202 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | |
| 4204 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4205 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4206 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4207 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4208 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4209 | if (ElementType.isNull()) |
| 4210 | return QualType(); |
| 4211 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4212 | QualType Result = TL.getType(); |
| 4213 | if (getDerived().AlwaysRebuild() || |
| 4214 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4215 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4216 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4217 | if (Result.isNull()) |
| 4218 | return QualType(); |
| 4219 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4220 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4221 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4222 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4223 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4224 | return Result; |
| 4225 | } |
| 4226 | |
| 4227 | template<typename Derived> |
| 4228 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4229 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4230 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4231 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4232 | if (ElementType.isNull()) |
| 4233 | return QualType(); |
| 4234 | |
| 4235 | QualType Result = TL.getType(); |
| 4236 | if (getDerived().AlwaysRebuild() || |
| 4237 | ElementType != T->getElementType()) { |
| 4238 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4239 | T->getNumElements(), |
| 4240 | /*FIXME*/ SourceLocation()); |
| 4241 | if (Result.isNull()) |
| 4242 | return QualType(); |
| 4243 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4244 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4245 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4246 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4247 | |
| 4248 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4249 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4251 | template <typename Derived> |
| 4252 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4253 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4254 | bool ExpectParameterPack) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4255 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4256 | TypeSourceInfo *NewDI = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4257 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4258 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4259 | // 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] | 4260 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4261 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4262 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4263 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4264 | TypeLocBuilder TLB; |
| 4265 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4266 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4267 | |
| 4268 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4269 | OldExpansionTL.getPatternLoc()); |
| 4270 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4271 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4272 | |
| 4273 | Result = RebuildPackExpansionType(Result, |
| 4274 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4275 | OldExpansionTL.getEllipsisLoc(), |
| 4276 | NumExpansions); |
| 4277 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4278 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4279 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4280 | PackExpansionTypeLoc NewExpansionTL |
| 4281 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4282 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4283 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4284 | } else |
| 4285 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4286 | if (!NewDI) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4287 | return nullptr; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4288 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4289 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4290 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4291 | |
| 4292 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4293 | OldParm->getDeclContext(), |
| 4294 | OldParm->getInnerLocStart(), |
| 4295 | OldParm->getLocation(), |
| 4296 | OldParm->getIdentifier(), |
| 4297 | NewDI->getType(), |
| 4298 | NewDI, |
| 4299 | OldParm->getStorageClass(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4300 | /* DefArg */ nullptr); |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4301 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4302 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4303 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | template<typename Derived> |
| 4307 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4308 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4309 | ParmVarDecl **Params, unsigned NumParams, |
| 4310 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4311 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4312 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4313 | int indexAdjustment = 0; |
| 4314 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4315 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4316 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4317 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4318 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4319 | Optional<unsigned> NumExpansions; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4320 | ParmVarDecl *NewParm = nullptr; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4321 | if (OldParm->isParameterPack()) { |
| 4322 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4323 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4324 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4325 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4326 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4327 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4328 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4329 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4330 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4331 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4332 | // Determine whether we should expand the parameter packs. |
| 4333 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4334 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4335 | Optional<unsigned> OrigNumExpansions = |
| 4336 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4337 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4338 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4339 | Pattern.getSourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4340 | Unexpanded, |
| 4341 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4342 | RetainExpansion, |
| 4343 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4344 | return true; |
| 4345 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4346 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4347 | if (ShouldExpand) { |
| 4348 | // Expand the function parameter pack into multiple, separate |
| 4349 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4350 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4351 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4352 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4353 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4354 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4355 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4356 | OrigNumExpansions, |
| 4357 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4358 | if (!NewParm) |
| 4359 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4360 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4361 | OutParamTypes.push_back(NewParm->getType()); |
| 4362 | if (PVars) |
| 4363 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4364 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4365 | |
| 4366 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4367 | // forgetting the partially-substituted parameter pack. |
| 4368 | if (RetainExpansion) { |
| 4369 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4370 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4371 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4372 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4373 | OrigNumExpansions, |
| 4374 | /*ExpectParameterPack=*/false); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4375 | if (!NewParm) |
| 4376 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4377 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4378 | OutParamTypes.push_back(NewParm->getType()); |
| 4379 | if (PVars) |
| 4380 | PVars->push_back(NewParm); |
| 4381 | } |
| 4382 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4383 | // The next parameter should have the same adjustment as the |
| 4384 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4385 | // on every push. Also, if we push nothing, the adjustment should |
| 4386 | // go down by one. |
| 4387 | indexAdjustment--; |
| 4388 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4389 | // We're done with the pack expansion. |
| 4390 | continue; |
| 4391 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4392 | |
| 4393 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4394 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4395 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4396 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4397 | indexAdjustment, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4398 | NumExpansions, |
| 4399 | /*ExpectParameterPack=*/true); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4400 | } else { |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4401 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4402 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4403 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4404 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4405 | if (!NewParm) |
| 4406 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4407 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4408 | OutParamTypes.push_back(NewParm->getType()); |
| 4409 | if (PVars) |
| 4410 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4411 | continue; |
| 4412 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4413 | |
| 4414 | // Deal with the possibility that we don't have a parameter |
| 4415 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4416 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4417 | bool IsPackExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4418 | Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4419 | QualType NewType; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4420 | if (const PackExpansionType *Expansion |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4421 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4422 | // We have a function parameter pack that may need to be expanded. |
| 4423 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4424 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4425 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4426 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4427 | // Determine whether we should expand the parameter packs. |
| 4428 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4429 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4430 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4431 | Unexpanded, |
| 4432 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4433 | RetainExpansion, |
| 4434 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4435 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4436 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4437 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4438 | if (ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4439 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4440 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4441 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4442 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4443 | QualType NewType = getDerived().TransformType(Pattern); |
| 4444 | if (NewType.isNull()) |
| 4445 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4446 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4447 | OutParamTypes.push_back(NewType); |
| 4448 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4449 | PVars->push_back(nullptr); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4450 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4451 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4452 | // We're done with the pack expansion. |
| 4453 | continue; |
| 4454 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4455 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4456 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4457 | // forgetting the partially-substituted parameter pack. |
| 4458 | if (RetainExpansion) { |
| 4459 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4460 | QualType NewType = getDerived().TransformType(Pattern); |
| 4461 | if (NewType.isNull()) |
| 4462 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4463 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4464 | OutParamTypes.push_back(NewType); |
| 4465 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4466 | PVars->push_back(nullptr); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4467 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4468 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4469 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4470 | // expansion. |
| 4471 | OldType = Expansion->getPattern(); |
| 4472 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4473 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4474 | NewType = getDerived().TransformType(OldType); |
| 4475 | } else { |
| 4476 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4477 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4479 | if (NewType.isNull()) |
| 4480 | return true; |
| 4481 | |
| 4482 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4483 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4484 | NumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4485 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4486 | OutParamTypes.push_back(NewType); |
| 4487 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4488 | PVars->push_back(nullptr); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4491 | #ifndef NDEBUG |
| 4492 | if (PVars) { |
| 4493 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4494 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4495 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4496 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4497 | #endif |
| 4498 | |
| 4499 | return false; |
| 4500 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4501 | |
| 4502 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4503 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4504 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4505 | FunctionProtoTypeLoc TL) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4506 | return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | template<typename Derived> |
| 4510 | QualType |
| 4511 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4512 | FunctionProtoTypeLoc TL, |
| 4513 | CXXRecordDecl *ThisContext, |
| 4514 | unsigned ThisTypeQuals) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4515 | // Transform the parameters and return type. |
| 4516 | // |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4517 | // 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] | 4518 | // When the function has a trailing return type, we instantiate the |
| 4519 | // parameters before the return type, since the return type can then refer |
| 4520 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4521 | // |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4522 | SmallVector<QualType, 4> ParamTypes; |
| 4523 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4524 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4525 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4526 | QualType ResultType; |
| 4527 | |
Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4528 | if (T->hasTrailingReturn()) { |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4529 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4530 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4531 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4532 | return QualType(); |
| 4533 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4534 | { |
| 4535 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4536 | // If a declaration declares a member function or member function |
| 4537 | // 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] | 4538 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4539 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4540 | // declarator. |
| 4541 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4542 | |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4543 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4544 | if (ResultType.isNull()) |
| 4545 | return QualType(); |
| 4546 | } |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4547 | } |
| 4548 | else { |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4549 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4550 | if (ResultType.isNull()) |
| 4551 | return QualType(); |
| 4552 | |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4553 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4554 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4555 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4556 | return QualType(); |
| 4557 | } |
| 4558 | |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4559 | // FIXME: Need to transform the exception-specification too. |
| 4560 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4561 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4562 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4563 | T->getNumParams() != ParamTypes.size() || |
| 4564 | !std::equal(T->param_type_begin(), T->param_type_end(), |
| 4565 | ParamTypes.begin())) { |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 4566 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 4567 | T->getExtProtoInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4568 | if (Result.isNull()) |
| 4569 | return QualType(); |
| 4570 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4571 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4572 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4573 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4574 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4575 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4576 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4577 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 4578 | NewTL.setParam(i, ParamDecls[i]); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4579 | |
| 4580 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4581 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4582 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4583 | template<typename Derived> |
| 4584 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4585 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4586 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4587 | const FunctionNoProtoType *T = TL.getTypePtr(); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4588 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4589 | if (ResultType.isNull()) |
| 4590 | return QualType(); |
| 4591 | |
| 4592 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4593 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4594 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4595 | |
| 4596 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4597 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4598 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4599 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4600 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4601 | |
| 4602 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4603 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4604 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4605 | template<typename Derived> QualType |
| 4606 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4607 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4608 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4609 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4610 | if (!D) |
| 4611 | return QualType(); |
| 4612 | |
| 4613 | QualType Result = TL.getType(); |
| 4614 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4615 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4616 | if (Result.isNull()) |
| 4617 | return QualType(); |
| 4618 | } |
| 4619 | |
| 4620 | // We might get an arbitrary type spec type back. We should at |
| 4621 | // least always get a type spec type, though. |
| 4622 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4623 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4624 | |
| 4625 | return Result; |
| 4626 | } |
| 4627 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4628 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4629 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4630 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4631 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4632 | TypedefNameDecl *Typedef |
| 4633 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4634 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4635 | if (!Typedef) |
| 4636 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4637 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4638 | QualType Result = TL.getType(); |
| 4639 | if (getDerived().AlwaysRebuild() || |
| 4640 | Typedef != T->getDecl()) { |
| 4641 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4642 | if (Result.isNull()) |
| 4643 | return QualType(); |
| 4644 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4645 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4646 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4647 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4648 | |
| 4649 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4651 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4652 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4653 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4654 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4655 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4656 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4657 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4658 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4659 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4660 | if (E.isInvalid()) |
| 4661 | return QualType(); |
| 4662 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4663 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4664 | if (E.isInvalid()) |
| 4665 | return QualType(); |
| 4666 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4667 | QualType Result = TL.getType(); |
| 4668 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4669 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4670 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4671 | if (Result.isNull()) |
| 4672 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4673 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4674 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4676 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4677 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4678 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4679 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4680 | |
| 4681 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4682 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4683 | |
| 4684 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4685 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4686 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4687 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4688 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4689 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4690 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4691 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4692 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4693 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4694 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4695 | if (Result.isNull()) |
| 4696 | return QualType(); |
| 4697 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4699 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4700 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4701 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4702 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4703 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4704 | |
| 4705 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4706 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4707 | |
| 4708 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4709 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4710 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4711 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4712 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4713 | // decltype expressions are not potentially evaluated contexts |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4714 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4715 | nullptr, /*IsDecltype=*/ true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4716 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4717 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4718 | if (E.isInvalid()) |
| 4719 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4720 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4721 | E = getSema().ActOnDecltypeExpression(E.get()); |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4722 | if (E.isInvalid()) |
| 4723 | return QualType(); |
| 4724 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4725 | QualType Result = TL.getType(); |
| 4726 | if (getDerived().AlwaysRebuild() || |
| 4727 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4728 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4729 | if (Result.isNull()) |
| 4730 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4731 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4732 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4733 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4734 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4735 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4736 | |
| 4737 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4741 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4742 | TypeLocBuilder &TLB, |
| 4743 | UnaryTransformTypeLoc TL) { |
| 4744 | QualType Result = TL.getType(); |
| 4745 | if (Result->isDependentType()) { |
| 4746 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4747 | QualType NewBase = |
| 4748 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4749 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4750 | T->getUTTKind(), |
| 4751 | TL.getKWLoc()); |
| 4752 | if (Result.isNull()) |
| 4753 | return QualType(); |
| 4754 | } |
| 4755 | |
| 4756 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4757 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4758 | NewTL.setParensRange(TL.getParensRange()); |
| 4759 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4760 | return Result; |
| 4761 | } |
| 4762 | |
| 4763 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4764 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4765 | AutoTypeLoc TL) { |
| 4766 | const AutoType *T = TL.getTypePtr(); |
| 4767 | QualType OldDeduced = T->getDeducedType(); |
| 4768 | QualType NewDeduced; |
| 4769 | if (!OldDeduced.isNull()) { |
| 4770 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4771 | if (NewDeduced.isNull()) |
| 4772 | return QualType(); |
| 4773 | } |
| 4774 | |
| 4775 | QualType Result = TL.getType(); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 4776 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 4777 | T->isDependentType()) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 4778 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4779 | if (Result.isNull()) |
| 4780 | return QualType(); |
| 4781 | } |
| 4782 | |
| 4783 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4784 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4785 | |
| 4786 | return Result; |
| 4787 | } |
| 4788 | |
| 4789 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4790 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4791 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4792 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4793 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4794 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4795 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4796 | if (!Record) |
| 4797 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4798 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4799 | QualType Result = TL.getType(); |
| 4800 | if (getDerived().AlwaysRebuild() || |
| 4801 | Record != T->getDecl()) { |
| 4802 | Result = getDerived().RebuildRecordType(Record); |
| 4803 | if (Result.isNull()) |
| 4804 | return QualType(); |
| 4805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4807 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4808 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4809 | |
| 4810 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4811 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4812 | |
| 4813 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4814 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4815 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4816 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4817 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4818 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4819 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4820 | if (!Enum) |
| 4821 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4822 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4823 | QualType Result = TL.getType(); |
| 4824 | if (getDerived().AlwaysRebuild() || |
| 4825 | Enum != T->getDecl()) { |
| 4826 | Result = getDerived().RebuildEnumType(Enum); |
| 4827 | if (Result.isNull()) |
| 4828 | return QualType(); |
| 4829 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4830 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4831 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4832 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4833 | |
| 4834 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4835 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4836 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4837 | template<typename Derived> |
| 4838 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4839 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4840 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4841 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4842 | TL.getTypePtr()->getDecl()); |
| 4843 | if (!D) return QualType(); |
| 4844 | |
| 4845 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4846 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4847 | return T; |
| 4848 | } |
| 4849 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4850 | template<typename Derived> |
| 4851 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4852 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4853 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4854 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4857 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4858 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4859 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4860 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4861 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4862 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4863 | // Substitute into the replacement type, which itself might involve something |
| 4864 | // that needs to be transformed. This only tends to occur with default |
| 4865 | // template arguments of template template parameters. |
| 4866 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4867 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4868 | if (Replacement.isNull()) |
| 4869 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4870 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4871 | // Always canonicalize the replacement type. |
| 4872 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4873 | QualType Result |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4874 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4875 | Replacement); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4876 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4877 | // Propagate type-source information. |
| 4878 | SubstTemplateTypeParmTypeLoc NewTL |
| 4879 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4880 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4881 | return Result; |
| 4882 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4886 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4887 | TypeLocBuilder &TLB, |
| 4888 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4889 | return TransformTypeSpecType(TLB, TL); |
| 4890 | } |
| 4891 | |
| 4892 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4893 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4894 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4895 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4896 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4897 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4898 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4899 | // because we can't have a dependent nested-name-specifier anyway. |
| 4900 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4901 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4902 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4903 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4904 | if (Template.isNull()) |
| 4905 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4906 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4907 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4908 | } |
| 4909 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4910 | template<typename Derived> |
| 4911 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4912 | AtomicTypeLoc TL) { |
| 4913 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4914 | if (ValueType.isNull()) |
| 4915 | return QualType(); |
| 4916 | |
| 4917 | QualType Result = TL.getType(); |
| 4918 | if (getDerived().AlwaysRebuild() || |
| 4919 | ValueType != TL.getValueLoc().getType()) { |
| 4920 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4921 | if (Result.isNull()) |
| 4922 | return QualType(); |
| 4923 | } |
| 4924 | |
| 4925 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4926 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4927 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4928 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4929 | |
| 4930 | return Result; |
| 4931 | } |
| 4932 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4933 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4934 | /// container that provides a \c getArgLoc() member function. |
| 4935 | /// |
| 4936 | /// This iterator is intended to be used with the iterator form of |
| 4937 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4938 | template<typename ArgLocContainer> |
| 4939 | class TemplateArgumentLocContainerIterator { |
| 4940 | ArgLocContainer *Container; |
| 4941 | unsigned Index; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4942 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4943 | public: |
| 4944 | typedef TemplateArgumentLoc value_type; |
| 4945 | typedef TemplateArgumentLoc reference; |
| 4946 | typedef int difference_type; |
| 4947 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4948 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4949 | class pointer { |
| 4950 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4951 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4952 | public: |
| 4953 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4954 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4955 | const TemplateArgumentLoc *operator->() const { |
| 4956 | return &Arg; |
| 4957 | } |
| 4958 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4959 | |
| 4960 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4961 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4962 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4963 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4964 | unsigned Index) |
| 4965 | : Container(&Container), Index(Index) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4966 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4967 | TemplateArgumentLocContainerIterator &operator++() { |
| 4968 | ++Index; |
| 4969 | return *this; |
| 4970 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4971 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4972 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4973 | TemplateArgumentLocContainerIterator Old(*this); |
| 4974 | ++(*this); |
| 4975 | return Old; |
| 4976 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4977 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4978 | TemplateArgumentLoc operator*() const { |
| 4979 | return Container->getArgLoc(Index); |
| 4980 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4981 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4982 | pointer operator->() const { |
| 4983 | return pointer(Container->getArgLoc(Index)); |
| 4984 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4985 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4986 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4987 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4988 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4989 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4990 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4991 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4992 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4993 | return !(X == Y); |
| 4994 | } |
| 4995 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4996 | |
| 4997 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4998 | template <typename Derived> |
| 4999 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 5000 | TypeLocBuilder &TLB, |
| 5001 | TemplateSpecializationTypeLoc TL, |
| 5002 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5003 | TemplateArgumentListInfo NewTemplateArgs; |
| 5004 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5005 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5006 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 5007 | ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5008 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5009 | ArgIterator(TL, TL.getNumArgs()), |
| 5010 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 5011 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5012 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5013 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 5014 | |
| 5015 | QualType Result = |
| 5016 | getDerived().RebuildTemplateSpecializationType(Template, |
| 5017 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5018 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5019 | |
| 5020 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5021 | // Specializations of template template parameters are represented as |
| 5022 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 5023 | // within a dependent context can transform them into |
| 5024 | // DependentTemplateSpecializationTypes. |
| 5025 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5026 | DependentTemplateSpecializationTypeLoc NewTL |
| 5027 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5028 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5029 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5030 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5031 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5032 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5033 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5034 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5035 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5036 | return Result; |
| 5037 | } |
| 5038 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5039 | TemplateSpecializationTypeLoc NewTL |
| 5040 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5041 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5042 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5043 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5044 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5045 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5046 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5047 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5048 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5049 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5051 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5052 | template <typename Derived> |
| 5053 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 5054 | TypeLocBuilder &TLB, |
| 5055 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 5056 | TemplateName Template, |
| 5057 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5058 | TemplateArgumentListInfo NewTemplateArgs; |
| 5059 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5060 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 5061 | typedef TemplateArgumentLocContainerIterator< |
| 5062 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5063 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5064 | ArgIterator(TL, TL.getNumArgs()), |
| 5065 | NewTemplateArgs)) |
| 5066 | return QualType(); |
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 | // 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] | 5069 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5070 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 5071 | QualType Result |
| 5072 | = getSema().Context.getDependentTemplateSpecializationType( |
| 5073 | TL.getTypePtr()->getKeyword(), |
| 5074 | DTN->getQualifier(), |
| 5075 | DTN->getIdentifier(), |
| 5076 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5077 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5078 | DependentTemplateSpecializationTypeLoc NewTL |
| 5079 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5080 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5081 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5082 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5083 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5084 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5085 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5086 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5087 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5088 | return Result; |
| 5089 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5090 | |
| 5091 | QualType Result |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5092 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5093 | TL.getTemplateNameLoc(), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5094 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5095 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5096 | if (!Result.isNull()) { |
| 5097 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 5098 | TemplateSpecializationTypeLoc NewTL |
| 5099 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5100 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5101 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5102 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5103 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5104 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5105 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5106 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5107 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5108 | return Result; |
| 5109 | } |
| 5110 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5111 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5112 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5113 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5114 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5115 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5116 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5117 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5118 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5119 | if (TL.getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5120 | QualifierLoc |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5121 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5122 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5123 | return QualType(); |
| 5124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5125 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5126 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 5127 | if (NamedT.isNull()) |
| 5128 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 5129 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5130 | // C++0x [dcl.type.elab]p2: |
| 5131 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 5132 | // resolves to an alias template specialization, the |
| 5133 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5134 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 5135 | if (const TemplateSpecializationType *TST = |
| 5136 | NamedT->getAs<TemplateSpecializationType>()) { |
| 5137 | TemplateName Template = TST->getTemplateName(); |
| 5138 | if (TypeAliasTemplateDecl *TAT = |
| 5139 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 5140 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 5141 | diag::err_tag_reference_non_tag) << 4; |
| 5142 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 5143 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5144 | } |
| 5145 | } |
| 5146 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5147 | QualType Result = TL.getType(); |
| 5148 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5149 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5150 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5151 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5152 | T->getKeyword(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5153 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5154 | if (Result.isNull()) |
| 5155 | return QualType(); |
| 5156 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5157 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5158 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5159 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5160 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5161 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5162 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5163 | |
| 5164 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5165 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5166 | TypeLocBuilder &TLB, |
| 5167 | AttributedTypeLoc TL) { |
| 5168 | const AttributedType *oldType = TL.getTypePtr(); |
| 5169 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5170 | if (modifiedType.isNull()) |
| 5171 | return QualType(); |
| 5172 | |
| 5173 | QualType result = TL.getType(); |
| 5174 | |
| 5175 | // FIXME: dependent operand expressions? |
| 5176 | if (getDerived().AlwaysRebuild() || |
| 5177 | modifiedType != oldType->getModifiedType()) { |
| 5178 | // TODO: this is really lame; we should really be rebuilding the |
| 5179 | // equivalent type from first principles. |
| 5180 | QualType equivalentType |
| 5181 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5182 | if (equivalentType.isNull()) |
| 5183 | return QualType(); |
| 5184 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5185 | modifiedType, |
| 5186 | equivalentType); |
| 5187 | } |
| 5188 | |
| 5189 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5190 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5191 | if (TL.hasAttrOperand()) |
| 5192 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5193 | if (TL.hasAttrExprOperand()) |
| 5194 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5195 | else if (TL.hasAttrEnumOperand()) |
| 5196 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5197 | |
| 5198 | return result; |
| 5199 | } |
| 5200 | |
| 5201 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5202 | QualType |
| 5203 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5204 | ParenTypeLoc TL) { |
| 5205 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5206 | if (Inner.isNull()) |
| 5207 | return QualType(); |
| 5208 | |
| 5209 | QualType Result = TL.getType(); |
| 5210 | if (getDerived().AlwaysRebuild() || |
| 5211 | Inner != TL.getInnerLoc().getType()) { |
| 5212 | Result = getDerived().RebuildParenType(Inner); |
| 5213 | if (Result.isNull()) |
| 5214 | return QualType(); |
| 5215 | } |
| 5216 | |
| 5217 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5218 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5219 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5220 | return Result; |
| 5221 | } |
| 5222 | |
| 5223 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5224 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5225 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5226 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5227 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5228 | NestedNameSpecifierLoc QualifierLoc |
| 5229 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5230 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5231 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5233 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5234 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5235 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5236 | QualifierLoc, |
| 5237 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5238 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5239 | if (Result.isNull()) |
| 5240 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5241 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5242 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5243 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5244 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5245 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5246 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5247 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5248 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5249 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5250 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5251 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5252 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5253 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5254 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5255 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5256 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5257 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5258 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5259 | QualType TreeTransform<Derived>:: |
| 5260 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5261 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5262 | NestedNameSpecifierLoc QualifierLoc; |
| 5263 | if (TL.getQualifierLoc()) { |
| 5264 | QualifierLoc |
| 5265 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5266 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5267 | return QualType(); |
| 5268 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5269 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5270 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5271 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5272 | } |
| 5273 | |
| 5274 | template<typename Derived> |
| 5275 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5276 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5277 | DependentTemplateSpecializationTypeLoc TL, |
| 5278 | NestedNameSpecifierLoc QualifierLoc) { |
| 5279 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5280 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5281 | TemplateArgumentListInfo NewTemplateArgs; |
| 5282 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5283 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5284 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5285 | typedef TemplateArgumentLocContainerIterator< |
| 5286 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5287 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5288 | ArgIterator(TL, TL.getNumArgs()), |
| 5289 | NewTemplateArgs)) |
| 5290 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5291 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5292 | QualType Result |
| 5293 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5294 | QualifierLoc, |
| 5295 | T->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5296 | TL.getTemplateNameLoc(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5297 | NewTemplateArgs); |
| 5298 | if (Result.isNull()) |
| 5299 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5300 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5301 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5302 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5303 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5304 | // Copy information relevant to the template specialization. |
| 5305 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5306 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5307 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5308 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5309 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5310 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5311 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5312 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5313 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5314 | // Copy information relevant to the elaborated type. |
| 5315 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5316 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5317 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5318 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5319 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5320 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5321 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5322 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5323 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5324 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5325 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5326 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5327 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5328 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5329 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5330 | TemplateSpecializationTypeLoc SpecTL |
| 5331 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5332 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5333 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5334 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5335 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5336 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5337 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5338 | } |
| 5339 | return Result; |
| 5340 | } |
| 5341 | |
| 5342 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5343 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5344 | PackExpansionTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5345 | QualType Pattern |
| 5346 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5347 | if (Pattern.isNull()) |
| 5348 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5349 | |
| 5350 | QualType Result = TL.getType(); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5351 | if (getDerived().AlwaysRebuild() || |
| 5352 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5353 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5354 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5355 | TL.getEllipsisLoc(), |
| 5356 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5357 | if (Result.isNull()) |
| 5358 | return QualType(); |
| 5359 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5360 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5361 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5362 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5363 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5364 | } |
| 5365 | |
| 5366 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5367 | QualType |
| 5368 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5369 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5370 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5371 | TLB.pushFullCopy(TL); |
| 5372 | return TL.getType(); |
| 5373 | } |
| 5374 | |
| 5375 | template<typename Derived> |
| 5376 | QualType |
| 5377 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5378 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5379 | // ObjCObjectType is never dependent. |
| 5380 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5381 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5383 | |
| 5384 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5385 | QualType |
| 5386 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5387 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5388 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5389 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5390 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5393 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5394 | // Statement transformation |
| 5395 | //===----------------------------------------------------------------------===// |
| 5396 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5397 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5398 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5399 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5403 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5404 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5405 | return getDerived().TransformCompoundStmt(S, false); |
| 5406 | } |
| 5407 | |
| 5408 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5409 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5410 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5411 | bool IsStmtExpr) { |
Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5412 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5413 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5414 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5415 | bool SubStmtChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5416 | SmallVector<Stmt*, 8> Statements; |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5417 | for (auto *B : S->body()) { |
| 5418 | StmtResult Result = getDerived().TransformStmt(B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5419 | if (Result.isInvalid()) { |
| 5420 | // Immediately fail if this was a DeclStmt, since it's very |
| 5421 | // likely that this will cause problems for future statements. |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5422 | if (isa<DeclStmt>(B)) |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5423 | return StmtError(); |
| 5424 | |
| 5425 | // Otherwise, just keep processing substatements and fail later. |
| 5426 | SubStmtInvalid = true; |
| 5427 | continue; |
| 5428 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5429 | |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5430 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5431 | Statements.push_back(Result.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5433 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5434 | if (SubStmtInvalid) |
| 5435 | return StmtError(); |
| 5436 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5437 | if (!getDerived().AlwaysRebuild() && |
| 5438 | !SubStmtChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5439 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5440 | |
| 5441 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5442 | Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5443 | S->getRBracLoc(), |
| 5444 | IsStmtExpr); |
| 5445 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5446 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5447 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5448 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5449 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5450 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5451 | { |
Eli Friedman | 1f4f9dd | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5452 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5453 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5454 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5455 | // Transform the left-hand case value. |
| 5456 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5457 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5458 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5459 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5461 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5462 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5463 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5464 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5465 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5466 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5467 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5468 | // Build the case statement. |
| 5469 | // Case statements are always rebuilt so that they will attached to their |
| 5470 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5471 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5472 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5473 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5474 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5475 | S->getColonLoc()); |
| 5476 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5477 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5478 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5479 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5480 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5481 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5482 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5483 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5484 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5485 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5489 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5490 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5491 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5492 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5493 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5494 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5495 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5496 | // Default statements are always rebuilt |
| 5497 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5498 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5499 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5500 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5501 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5502 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5503 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5504 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5505 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5506 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5507 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5508 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5509 | S->getDecl()); |
| 5510 | if (!LD) |
| 5511 | return StmtError(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5512 | |
| 5513 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5514 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5515 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5516 | cast<LabelDecl>(LD), SourceLocation(), |
| 5517 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5518 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5519 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5520 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5521 | StmtResult |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5522 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5523 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5524 | if (SubStmt.isInvalid()) |
| 5525 | return StmtError(); |
| 5526 | |
| 5527 | // TODO: transform attributes |
| 5528 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5529 | return S; |
| 5530 | |
| 5531 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5532 | S->getAttrs(), |
| 5533 | SubStmt.get()); |
| 5534 | } |
| 5535 | |
| 5536 | template<typename Derived> |
| 5537 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5538 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5539 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5540 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5541 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5542 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5543 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5544 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5545 | getDerived().TransformDefinition( |
| 5546 | S->getConditionVariable()->getLocation(), |
| 5547 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5548 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5549 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5550 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5551 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5552 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5553 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5554 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5555 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5556 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5557 | if (S->getCond()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5558 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5559 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5560 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5561 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5562 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5563 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5564 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5565 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5566 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5567 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5568 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5569 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5570 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5571 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5572 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5573 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5574 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5575 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5576 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5577 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5578 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5579 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5580 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5581 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5582 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5583 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5584 | Then.get() == S->getThen() && |
| 5585 | Else.get() == S->getElse()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5586 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5587 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5588 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5589 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5590 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5594 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5595 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5596 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5597 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5598 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5599 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5600 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5601 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5602 | getDerived().TransformDefinition( |
| 5603 | S->getConditionVariable()->getLocation(), |
| 5604 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5605 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5606 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5607 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5608 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5609 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5610 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5611 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5612 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5613 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5614 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5615 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5616 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5617 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5618 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5619 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5620 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5621 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5622 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5623 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5624 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5625 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5626 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5627 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5628 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5629 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5630 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5631 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5632 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5633 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5634 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5635 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5636 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5637 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5638 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5639 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5640 | getDerived().TransformDefinition( |
| 5641 | S->getConditionVariable()->getLocation(), |
| 5642 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5643 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5644 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5645 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5646 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5647 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5648 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5649 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5650 | |
| 5651 | if (S->getCond()) { |
| 5652 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5653 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 5654 | S->getWhileLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5655 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5656 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5657 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5658 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5659 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5660 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5661 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5662 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5663 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5664 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5665 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5666 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5667 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5668 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5669 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5671 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5672 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5673 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5674 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5675 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5677 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5678 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5679 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5680 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5681 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5682 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5683 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5684 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5685 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5686 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5687 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5688 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5689 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5690 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5691 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5692 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5693 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5694 | if (!getDerived().AlwaysRebuild() && |
| 5695 | Cond.get() == S->getCond() && |
| 5696 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5697 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5698 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5699 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5700 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5701 | S->getRParenLoc()); |
| 5702 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5703 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5704 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5705 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5706 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5707 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5708 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5709 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5710 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5711 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5712 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5713 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5714 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5715 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5716 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5717 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5718 | getDerived().TransformDefinition( |
| 5719 | S->getConditionVariable()->getLocation(), |
| 5720 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5721 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5722 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5723 | } else { |
| 5724 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5725 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5726 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5727 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5728 | |
| 5729 | if (S->getCond()) { |
| 5730 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5731 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 5732 | S->getForLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5733 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5734 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5735 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5736 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5737 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5738 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5739 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5740 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5741 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5742 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5743 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5744 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5745 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5746 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5747 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5748 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5749 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 5750 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5751 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5752 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5753 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5754 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5755 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5756 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5757 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5758 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5759 | if (!getDerived().AlwaysRebuild() && |
| 5760 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5761 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5762 | Inc.get() == S->getInc() && |
| 5763 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5764 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5765 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5766 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5767 | Init.get(), FullCond, ConditionVar, |
| 5768 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5769 | } |
| 5770 | |
| 5771 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5772 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5773 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5774 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5775 | S->getLabel()); |
| 5776 | if (!LD) |
| 5777 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5778 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5779 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5780 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5781 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5785 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5786 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5787 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5788 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5789 | return StmtError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5790 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5791 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5792 | if (!getDerived().AlwaysRebuild() && |
| 5793 | Target.get() == S->getTarget()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5794 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5795 | |
| 5796 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5797 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5801 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5802 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5803 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5804 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5805 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5806 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5807 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5808 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5809 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5811 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5812 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5813 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5814 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5815 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5816 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5817 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5818 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5819 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5820 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5821 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5822 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5823 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5824 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5825 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5826 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5827 | bool DeclChanged = false; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5828 | SmallVector<Decl *, 4> Decls; |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 5829 | for (auto *D : S->decls()) { |
| 5830 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5831 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5832 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5833 | |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 5834 | if (Transformed != D) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5835 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5836 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5837 | Decls.push_back(Transformed); |
| 5838 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5839 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5840 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5841 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5842 | |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 5843 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5844 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5845 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5846 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5847 | StmtResult |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5848 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5849 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5850 | SmallVector<Expr*, 8> Constraints; |
| 5851 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5852 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5853 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5854 | ExprResult AsmString; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5855 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5856 | |
| 5857 | bool ExprsChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5858 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5859 | // Go through the outputs. |
| 5860 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5861 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5862 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5863 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5864 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5865 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5866 | // Transform the output expr. |
| 5867 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5868 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5869 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5870 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5871 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5872 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5873 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5874 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5875 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5876 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5877 | // Go through the inputs. |
| 5878 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5879 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5880 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5881 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5882 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5883 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5884 | // Transform the input expr. |
| 5885 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5886 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5887 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5888 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5889 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5890 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5891 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5892 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5893 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5894 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5895 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5896 | return S; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5897 | |
| 5898 | // Go through the clobbers. |
| 5899 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5900 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5901 | |
| 5902 | // No need to transform the asm string literal. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5903 | AsmString = S->getAsmString(); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5904 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5905 | S->isVolatile(), S->getNumOutputs(), |
| 5906 | S->getNumInputs(), Names.data(), |
| 5907 | Constraints, Exprs, AsmString.get(), |
| 5908 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5909 | } |
| 5910 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5911 | template<typename Derived> |
| 5912 | StmtResult |
| 5913 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5914 | ArrayRef<Token> AsmToks = |
| 5915 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5916 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5917 | bool HadError = false, HadChange = false; |
| 5918 | |
| 5919 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 5920 | SmallVector<Expr*, 8> TransformedExprs; |
| 5921 | TransformedExprs.reserve(SrcExprs.size()); |
| 5922 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 5923 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 5924 | if (!Result.isUsable()) { |
| 5925 | HadError = true; |
| 5926 | } else { |
| 5927 | HadChange |= (Result.get() != SrcExprs[i]); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5928 | TransformedExprs.push_back(Result.get()); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | if (HadError) return StmtError(); |
| 5933 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 5934 | return Owned(S); |
| 5935 | |
Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 5936 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5937 | AsmToks, S->getAsmString(), |
| 5938 | S->getNumOutputs(), S->getNumInputs(), |
| 5939 | S->getAllConstraints(), S->getClobbers(), |
| 5940 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5941 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5942 | |
| 5943 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5944 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5945 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5946 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5947 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5948 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5949 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5950 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5951 | // Transform the @catch statements (if present). |
| 5952 | bool AnyCatchChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5953 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5954 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5955 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5956 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5957 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5958 | if (Catch.get() != S->getCatchStmt(I)) |
| 5959 | AnyCatchChanged = true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5960 | CatchStmts.push_back(Catch.get()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5961 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5962 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5963 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5964 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5965 | if (S->getFinallyStmt()) { |
| 5966 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5967 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5968 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | // If nothing changed, just retain this statement. |
| 5972 | if (!getDerived().AlwaysRebuild() && |
| 5973 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5974 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5975 | Finally.get() == S->getFinallyStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5976 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5977 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5978 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5979 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5980 | CatchStmts, Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5981 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5982 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5983 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5984 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5985 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5986 | // Transform the @catch parameter, if there is one. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5987 | VarDecl *Var = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5988 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5989 | TypeSourceInfo *TSInfo = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5990 | if (FromVar->getTypeSourceInfo()) { |
| 5991 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5992 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5993 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5994 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5995 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5996 | QualType T; |
| 5997 | if (TSInfo) |
| 5998 | T = TSInfo->getType(); |
| 5999 | else { |
| 6000 | T = getDerived().TransformType(FromVar->getType()); |
| 6001 | if (T.isNull()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6002 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6003 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6004 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6005 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 6006 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6007 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6008 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6009 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6010 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6011 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6012 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6013 | |
| 6014 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6015 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6016 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6017 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6018 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6019 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6020 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6021 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6022 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6023 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6024 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6025 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6026 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6027 | // If nothing changed, just retain this statement. |
| 6028 | if (!getDerived().AlwaysRebuild() && |
| 6029 | Body.get() == S->getFinallyBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6030 | return S; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6031 | |
| 6032 | // Build a new statement. |
| 6033 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6034 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6036 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6037 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6038 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6039 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6040 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6041 | if (S->getThrowExpr()) { |
| 6042 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 6043 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6044 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6045 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6046 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6047 | if (!getDerived().AlwaysRebuild() && |
| 6048 | Operand.get() == S->getThrowExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6049 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6050 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6051 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6052 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6053 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6054 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6055 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6056 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6057 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6058 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6059 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6060 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6061 | return StmtError(); |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 6062 | Object = |
| 6063 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 6064 | Object.get()); |
| 6065 | if (Object.isInvalid()) |
| 6066 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6067 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6068 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6069 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6070 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6071 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6072 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6073 | // If nothing change, just retain the current statement. |
| 6074 | if (!getDerived().AlwaysRebuild() && |
| 6075 | Object.get() == S->getSynchExpr() && |
| 6076 | Body.get() == S->getSynchBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6077 | return S; |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6078 | |
| 6079 | // Build a new statement. |
| 6080 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6081 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6082 | } |
| 6083 | |
| 6084 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6085 | StmtResult |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6086 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 6087 | ObjCAutoreleasePoolStmt *S) { |
| 6088 | // Transform the body. |
| 6089 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 6090 | if (Body.isInvalid()) |
| 6091 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6092 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6093 | // If nothing changed, just retain this statement. |
| 6094 | if (!getDerived().AlwaysRebuild() && |
| 6095 | Body.get() == S->getSubStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6096 | return S; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6097 | |
| 6098 | // Build a new statement. |
| 6099 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 6100 | S->getAtLoc(), Body.get()); |
| 6101 | } |
| 6102 | |
| 6103 | template<typename Derived> |
| 6104 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6105 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6106 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6107 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6108 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6109 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6110 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6111 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6112 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6113 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6114 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6115 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6116 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6117 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6118 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6119 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6120 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6121 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6122 | // If nothing changed, just retain this statement. |
| 6123 | if (!getDerived().AlwaysRebuild() && |
| 6124 | Element.get() == S->getElement() && |
| 6125 | Collection.get() == S->getCollection() && |
| 6126 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6127 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6128 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6129 | // Build a new statement. |
| 6130 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6131 | Element.get(), |
| 6132 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6133 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6134 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6135 | } |
| 6136 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6137 | template <typename Derived> |
| 6138 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6139 | // Transform the exception declaration, if any. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6140 | VarDecl *Var = nullptr; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6141 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 6142 | TypeSourceInfo *T = |
| 6143 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 6144 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6145 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6146 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6147 | Var = getDerived().RebuildExceptionDecl( |
| 6148 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 6149 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6150 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6151 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6152 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6153 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6154 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6155 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6156 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6157 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6158 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6159 | if (!getDerived().AlwaysRebuild() && !Var && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6160 | Handler.get() == S->getHandlerBlock()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6161 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6162 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6163 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6164 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6165 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6166 | template <typename Derived> |
| 6167 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6168 | // Transform the try block itself. |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6169 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6170 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6171 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6172 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6173 | // Transform the handlers. |
| 6174 | bool HandlerChanged = false; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6175 | SmallVector<Stmt *, 8> Handlers; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6176 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6177 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6178 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6179 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6180 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6181 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6182 | Handlers.push_back(Handler.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6183 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6184 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6185 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6186 | !HandlerChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6187 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6188 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6189 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6190 | Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6191 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6192 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6193 | template<typename Derived> |
| 6194 | StmtResult |
| 6195 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6196 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6197 | if (Range.isInvalid()) |
| 6198 | return StmtError(); |
| 6199 | |
| 6200 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6201 | if (BeginEnd.isInvalid()) |
| 6202 | return StmtError(); |
| 6203 | |
| 6204 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6205 | if (Cond.isInvalid()) |
| 6206 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6207 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6208 | Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc()); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6209 | if (Cond.isInvalid()) |
| 6210 | return StmtError(); |
| 6211 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6212 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6213 | |
| 6214 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6215 | if (Inc.isInvalid()) |
| 6216 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6217 | if (Inc.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6218 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6219 | |
| 6220 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6221 | if (LoopVar.isInvalid()) |
| 6222 | return StmtError(); |
| 6223 | |
| 6224 | StmtResult NewStmt = S; |
| 6225 | if (getDerived().AlwaysRebuild() || |
| 6226 | Range.get() != S->getRangeStmt() || |
| 6227 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6228 | Cond.get() != S->getCond() || |
| 6229 | Inc.get() != S->getInc() || |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6230 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6231 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6232 | S->getColonLoc(), Range.get(), |
| 6233 | BeginEnd.get(), Cond.get(), |
| 6234 | Inc.get(), LoopVar.get(), |
| 6235 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6236 | if (NewStmt.isInvalid()) |
| 6237 | return StmtError(); |
| 6238 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6239 | |
| 6240 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6241 | if (Body.isInvalid()) |
| 6242 | return StmtError(); |
| 6243 | |
| 6244 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6245 | // 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] | 6246 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6247 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6248 | S->getColonLoc(), Range.get(), |
| 6249 | BeginEnd.get(), Cond.get(), |
| 6250 | Inc.get(), LoopVar.get(), |
| 6251 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6252 | if (NewStmt.isInvalid()) |
| 6253 | return StmtError(); |
| 6254 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6255 | |
| 6256 | if (NewStmt.get() == S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6257 | return S; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6258 | |
| 6259 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6260 | } |
| 6261 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6262 | template<typename Derived> |
| 6263 | StmtResult |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6264 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6265 | MSDependentExistsStmt *S) { |
| 6266 | // Transform the nested-name-specifier, if any. |
| 6267 | NestedNameSpecifierLoc QualifierLoc; |
| 6268 | if (S->getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6269 | QualifierLoc |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6270 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6271 | if (!QualifierLoc) |
| 6272 | return StmtError(); |
| 6273 | } |
| 6274 | |
| 6275 | // Transform the declaration name. |
| 6276 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6277 | if (NameInfo.getName()) { |
| 6278 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6279 | if (!NameInfo.getName()) |
| 6280 | return StmtError(); |
| 6281 | } |
| 6282 | |
| 6283 | // Check whether anything changed. |
| 6284 | if (!getDerived().AlwaysRebuild() && |
| 6285 | QualifierLoc == S->getQualifierLoc() && |
| 6286 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6287 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6288 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6289 | // Determine whether this name exists, if we can. |
| 6290 | CXXScopeSpec SS; |
| 6291 | SS.Adopt(QualifierLoc); |
| 6292 | bool Dependent = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6293 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6294 | case Sema::IER_Exists: |
| 6295 | if (S->isIfExists()) |
| 6296 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6297 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6298 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6299 | |
| 6300 | case Sema::IER_DoesNotExist: |
| 6301 | if (S->isIfNotExists()) |
| 6302 | break; |
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 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6305 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6306 | case Sema::IER_Dependent: |
| 6307 | Dependent = true; |
| 6308 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6309 | |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6310 | case Sema::IER_Error: |
| 6311 | return StmtError(); |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6312 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6313 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6314 | // We need to continue with the instantiation, so do so now. |
| 6315 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6316 | if (SubStmt.isInvalid()) |
| 6317 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6318 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6319 | // If we have resolved the name, just transform to the substatement. |
| 6320 | if (!Dependent) |
| 6321 | return SubStmt; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6322 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6323 | // The name is still dependent, so build a dependent expression again. |
| 6324 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6325 | S->isIfExists(), |
| 6326 | QualifierLoc, |
| 6327 | NameInfo, |
| 6328 | SubStmt.get()); |
| 6329 | } |
| 6330 | |
| 6331 | template<typename Derived> |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6332 | ExprResult |
| 6333 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6334 | NestedNameSpecifierLoc QualifierLoc; |
| 6335 | if (E->getQualifierLoc()) { |
| 6336 | QualifierLoc |
| 6337 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6338 | if (!QualifierLoc) |
| 6339 | return ExprError(); |
| 6340 | } |
| 6341 | |
| 6342 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6343 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6344 | if (!PD) |
| 6345 | return ExprError(); |
| 6346 | |
| 6347 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6348 | if (Base.isInvalid()) |
| 6349 | return ExprError(); |
| 6350 | |
| 6351 | return new (SemaRef.getASTContext()) |
| 6352 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6353 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6354 | QualifierLoc, E->getMemberLoc()); |
| 6355 | } |
| 6356 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6357 | template <typename Derived> |
| 6358 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6359 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6360 | if (TryBlock.isInvalid()) |
| 6361 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6362 | |
| 6363 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6364 | if (Handler.isInvalid()) |
| 6365 | return StmtError(); |
| 6366 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6367 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 6368 | Handler.get() == S->getHandler()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6369 | return S; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6370 | |
Warren Hunt | b530bc0 | 2014-07-19 00:45:07 +0000 | [diff] [blame^] | 6371 | return getDerived().RebuildSEHTryStmt( |
| 6372 | S->getIsCXXTry(), S->getTryLoc(), TryBlock.get(), Handler.get(), |
| 6373 | S->getHandlerIndex(), S->getHandlerParentIndex()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6374 | } |
| 6375 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6376 | template <typename Derived> |
| 6377 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6378 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6379 | if (Block.isInvalid()) |
| 6380 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6381 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6382 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6383 | } |
| 6384 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6385 | template <typename Derived> |
| 6386 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6387 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6388 | if (FilterExpr.isInvalid()) |
| 6389 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6390 | |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6391 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6392 | if (Block.isInvalid()) |
| 6393 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6394 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6395 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 6396 | Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6397 | } |
| 6398 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6399 | template <typename Derived> |
| 6400 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6401 | if (isa<SEHFinallyStmt>(Handler)) |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6402 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6403 | else |
| 6404 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6405 | } |
| 6406 | |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 6407 | template<typename Derived> |
| 6408 | StmtResult |
| 6409 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 6410 | return S; |
| 6411 | } |
| 6412 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6413 | //===----------------------------------------------------------------------===// |
| 6414 | // OpenMP directive transformation |
| 6415 | //===----------------------------------------------------------------------===// |
| 6416 | template <typename Derived> |
| 6417 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 6418 | OMPExecutableDirective *D) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6419 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6420 | // Transform the clauses |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6421 | llvm::SmallVector<OMPClause *, 16> TClauses; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6422 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6423 | TClauses.reserve(Clauses.size()); |
| 6424 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6425 | I != E; ++I) { |
| 6426 | if (*I) { |
| 6427 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6428 | if (Clause) |
| 6429 | TClauses.push_back(Clause); |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6430 | } else { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 6431 | TClauses.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6432 | } |
| 6433 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6434 | StmtResult AssociatedStmt; |
| 6435 | if (D->hasAssociatedStmt()) { |
| 6436 | if (!D->getAssociatedStmt()) { |
| 6437 | return StmtError(); |
| 6438 | } |
| 6439 | AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt()); |
| 6440 | if (AssociatedStmt.isInvalid()) { |
| 6441 | return StmtError(); |
| 6442 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6443 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6444 | if (TClauses.size() != Clauses.size()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6445 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6446 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6447 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6448 | return getDerived().RebuildOMPExecutableDirective( |
| 6449 | D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(), |
| 6450 | D->getLocEnd()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6451 | } |
| 6452 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6453 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6454 | StmtResult |
| 6455 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 6456 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6457 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| 6458 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6459 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6460 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6461 | return Res; |
| 6462 | } |
| 6463 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6464 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6465 | StmtResult |
| 6466 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 6467 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6468 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| 6469 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6470 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6471 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6472 | return Res; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6473 | } |
| 6474 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6475 | template <typename Derived> |
| 6476 | StmtResult |
| 6477 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 6478 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6479 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| 6480 | D->getLocStart()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6481 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6482 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6483 | return Res; |
| 6484 | } |
| 6485 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6486 | template <typename Derived> |
| 6487 | StmtResult |
| 6488 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 6489 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6490 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| 6491 | D->getLocStart()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6492 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6493 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6494 | return Res; |
| 6495 | } |
| 6496 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6497 | template <typename Derived> |
| 6498 | StmtResult |
| 6499 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 6500 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6501 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| 6502 | D->getLocStart()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6503 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6504 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6505 | return Res; |
| 6506 | } |
| 6507 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6508 | template <typename Derived> |
| 6509 | StmtResult |
| 6510 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 6511 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6512 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| 6513 | D->getLocStart()); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6514 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6515 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6516 | return Res; |
| 6517 | } |
| 6518 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6519 | template <typename Derived> |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 6520 | StmtResult |
| 6521 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 6522 | DeclarationNameInfo DirName; |
| 6523 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| 6524 | D->getLocStart()); |
| 6525 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6526 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6527 | return Res; |
| 6528 | } |
| 6529 | |
| 6530 | template <typename Derived> |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6531 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 6532 | OMPParallelForDirective *D) { |
| 6533 | DeclarationNameInfo DirName; |
| 6534 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| 6535 | nullptr, D->getLocStart()); |
| 6536 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6537 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6538 | return Res; |
| 6539 | } |
| 6540 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6541 | template <typename Derived> |
| 6542 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 6543 | OMPParallelSectionsDirective *D) { |
| 6544 | DeclarationNameInfo DirName; |
| 6545 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| 6546 | nullptr, D->getLocStart()); |
| 6547 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6548 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6549 | return Res; |
| 6550 | } |
| 6551 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6552 | template <typename Derived> |
| 6553 | StmtResult |
| 6554 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 6555 | DeclarationNameInfo DirName; |
| 6556 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| 6557 | D->getLocStart()); |
| 6558 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6559 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6560 | return Res; |
| 6561 | } |
| 6562 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6563 | template <typename Derived> |
| 6564 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 6565 | OMPTaskyieldDirective *D) { |
| 6566 | DeclarationNameInfo DirName; |
| 6567 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| 6568 | D->getLocStart()); |
| 6569 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6570 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6571 | return Res; |
| 6572 | } |
| 6573 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 6574 | template <typename Derived> |
| 6575 | StmtResult |
| 6576 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 6577 | DeclarationNameInfo DirName; |
| 6578 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| 6579 | D->getLocStart()); |
| 6580 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6581 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6582 | return Res; |
| 6583 | } |
| 6584 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 6585 | template <typename Derived> |
| 6586 | StmtResult |
| 6587 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 6588 | DeclarationNameInfo DirName; |
| 6589 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| 6590 | D->getLocStart()); |
| 6591 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6592 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6593 | return Res; |
| 6594 | } |
| 6595 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6596 | //===----------------------------------------------------------------------===// |
| 6597 | // OpenMP clause transformation |
| 6598 | //===----------------------------------------------------------------------===// |
| 6599 | template <typename Derived> |
| 6600 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 6601 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 6602 | if (Cond.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6603 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6604 | return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(), |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6605 | C->getLParenLoc(), C->getLocEnd()); |
| 6606 | } |
| 6607 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6608 | template <typename Derived> |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6609 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 6610 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 6611 | if (Cond.isInvalid()) |
| 6612 | return nullptr; |
| 6613 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(), |
| 6614 | C->getLParenLoc(), C->getLocEnd()); |
| 6615 | } |
| 6616 | |
| 6617 | template <typename Derived> |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6618 | OMPClause * |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6619 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 6620 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 6621 | if (NumThreads.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6622 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6623 | return getDerived().RebuildOMPNumThreadsClause( |
| 6624 | NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6625 | } |
| 6626 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6627 | template <typename Derived> |
| 6628 | OMPClause * |
| 6629 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 6630 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 6631 | if (E.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6632 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6633 | return getDerived().RebuildOMPSafelenClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6634 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6635 | } |
| 6636 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6637 | template <typename Derived> |
| 6638 | OMPClause * |
| 6639 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 6640 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 6641 | if (E.isInvalid()) |
| 6642 | return 0; |
| 6643 | return getDerived().RebuildOMPCollapseClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6644 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6645 | } |
| 6646 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6647 | template <typename Derived> |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6648 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6649 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6650 | return getDerived().RebuildOMPDefaultClause( |
| 6651 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(), |
| 6652 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6653 | } |
| 6654 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6655 | template <typename Derived> |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6656 | OMPClause * |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6657 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6658 | return getDerived().RebuildOMPProcBindClause( |
| 6659 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(), |
| 6660 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6661 | } |
| 6662 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6663 | template <typename Derived> |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6664 | OMPClause * |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6665 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 6666 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 6667 | if (E.isInvalid()) |
| 6668 | return nullptr; |
| 6669 | return getDerived().RebuildOMPScheduleClause( |
| 6670 | C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(), |
| 6671 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd()); |
| 6672 | } |
| 6673 | |
| 6674 | template <typename Derived> |
| 6675 | OMPClause * |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6676 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *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 | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6683 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *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 | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6690 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 6691 | // No need to rebuild this clause, no template-dependent parameters. |
| 6692 | return C; |
| 6693 | } |
| 6694 | |
| 6695 | template <typename Derived> |
| 6696 | OMPClause * |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6697 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 6698 | // No need to rebuild this clause, no template-dependent parameters. |
| 6699 | return C; |
| 6700 | } |
| 6701 | |
| 6702 | template <typename Derived> |
| 6703 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6704 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6705 | llvm::SmallVector<Expr *, 16> Vars; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6706 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6707 | for (auto *VE : C->varlists()) { |
| 6708 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6709 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6710 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6711 | Vars.push_back(EVar.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6712 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6713 | return getDerived().RebuildOMPPrivateClause( |
| 6714 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6715 | } |
| 6716 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6717 | template <typename Derived> |
| 6718 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 6719 | OMPFirstprivateClause *C) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6720 | llvm::SmallVector<Expr *, 16> Vars; |
| 6721 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6722 | for (auto *VE : C->varlists()) { |
| 6723 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6724 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6725 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6726 | Vars.push_back(EVar.get()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6727 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6728 | return getDerived().RebuildOMPFirstprivateClause( |
| 6729 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6730 | } |
| 6731 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6732 | template <typename Derived> |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6733 | OMPClause * |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6734 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 6735 | llvm::SmallVector<Expr *, 16> Vars; |
| 6736 | Vars.reserve(C->varlist_size()); |
| 6737 | for (auto *VE : C->varlists()) { |
| 6738 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6739 | if (EVar.isInvalid()) |
| 6740 | return nullptr; |
| 6741 | Vars.push_back(EVar.get()); |
| 6742 | } |
| 6743 | return getDerived().RebuildOMPLastprivateClause( |
| 6744 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 6745 | } |
| 6746 | |
| 6747 | template <typename Derived> |
| 6748 | OMPClause * |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6749 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 6750 | llvm::SmallVector<Expr *, 16> Vars; |
| 6751 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6752 | for (auto *VE : C->varlists()) { |
| 6753 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6754 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6755 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6756 | Vars.push_back(EVar.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6757 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6758 | return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(), |
| 6759 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6760 | } |
| 6761 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6762 | template <typename Derived> |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6763 | OMPClause * |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6764 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 6765 | llvm::SmallVector<Expr *, 16> Vars; |
| 6766 | Vars.reserve(C->varlist_size()); |
| 6767 | for (auto *VE : C->varlists()) { |
| 6768 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6769 | if (EVar.isInvalid()) |
| 6770 | return nullptr; |
| 6771 | Vars.push_back(EVar.get()); |
| 6772 | } |
| 6773 | CXXScopeSpec ReductionIdScopeSpec; |
| 6774 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 6775 | |
| 6776 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 6777 | if (NameInfo.getName()) { |
| 6778 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6779 | if (!NameInfo.getName()) |
| 6780 | return nullptr; |
| 6781 | } |
| 6782 | return getDerived().RebuildOMPReductionClause( |
| 6783 | Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(), |
| 6784 | C->getLocEnd(), ReductionIdScopeSpec, NameInfo); |
| 6785 | } |
| 6786 | |
| 6787 | template <typename Derived> |
| 6788 | OMPClause * |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6789 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 6790 | llvm::SmallVector<Expr *, 16> Vars; |
| 6791 | Vars.reserve(C->varlist_size()); |
| 6792 | for (auto *VE : C->varlists()) { |
| 6793 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6794 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6795 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6796 | Vars.push_back(EVar.get()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6797 | } |
| 6798 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 6799 | if (Step.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6800 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6801 | return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(), |
| 6802 | C->getLParenLoc(), |
| 6803 | C->getColonLoc(), C->getLocEnd()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6804 | } |
| 6805 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6806 | template <typename Derived> |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6807 | OMPClause * |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6808 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 6809 | llvm::SmallVector<Expr *, 16> Vars; |
| 6810 | Vars.reserve(C->varlist_size()); |
| 6811 | for (auto *VE : C->varlists()) { |
| 6812 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6813 | if (EVar.isInvalid()) |
| 6814 | return nullptr; |
| 6815 | Vars.push_back(EVar.get()); |
| 6816 | } |
| 6817 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 6818 | if (Alignment.isInvalid()) |
| 6819 | return nullptr; |
| 6820 | return getDerived().RebuildOMPAlignedClause( |
| 6821 | Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(), |
| 6822 | C->getColonLoc(), C->getLocEnd()); |
| 6823 | } |
| 6824 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6825 | template <typename Derived> |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6826 | OMPClause * |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6827 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 6828 | llvm::SmallVector<Expr *, 16> Vars; |
| 6829 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6830 | for (auto *VE : C->varlists()) { |
| 6831 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6832 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6833 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6834 | Vars.push_back(EVar.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6835 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6836 | return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(), |
| 6837 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6838 | } |
| 6839 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6840 | template <typename Derived> |
| 6841 | OMPClause * |
| 6842 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 6843 | llvm::SmallVector<Expr *, 16> Vars; |
| 6844 | Vars.reserve(C->varlist_size()); |
| 6845 | for (auto *VE : C->varlists()) { |
| 6846 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6847 | if (EVar.isInvalid()) |
| 6848 | return nullptr; |
| 6849 | Vars.push_back(EVar.get()); |
| 6850 | } |
| 6851 | return getDerived().RebuildOMPCopyprivateClause( |
| 6852 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 6853 | } |
| 6854 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6855 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6856 | // Expression transformation |
| 6857 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6858 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6859 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6860 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6861 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6862 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6863 | |
| 6864 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6865 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6866 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6867 | NestedNameSpecifierLoc QualifierLoc; |
| 6868 | if (E->getQualifierLoc()) { |
| 6869 | QualifierLoc |
| 6870 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6871 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6872 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6873 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6874 | |
| 6875 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6876 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6877 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6878 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6879 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6880 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6881 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6882 | if (NameInfo.getName()) { |
| 6883 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6884 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6885 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6886 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6887 | |
| 6888 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6889 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6890 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6891 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6892 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6893 | |
| 6894 | // Mark it referenced in the new context regardless. |
| 6895 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6896 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6897 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6898 | return E; |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6899 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6900 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6901 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6902 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6903 | TemplateArgs = &TransArgs; |
| 6904 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6905 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6906 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6907 | E->getNumTemplateArgs(), |
| 6908 | TransArgs)) |
| 6909 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6910 | } |
| 6911 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6912 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6913 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6914 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6915 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6916 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6917 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6918 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6919 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6920 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6921 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6922 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6923 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6924 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6925 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6928 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6929 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6930 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6931 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6932 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6933 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6934 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6935 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6936 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6937 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6939 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6940 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6941 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6942 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6943 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6944 | } |
| 6945 | |
| 6946 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6947 | ExprResult |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6948 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 6949 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 6950 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6951 | return SemaRef.MaybeBindToTemporary(E); |
| 6952 | } |
| 6953 | |
| 6954 | template<typename Derived> |
| 6955 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6956 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6957 | ExprResult ControllingExpr = |
| 6958 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6959 | if (ControllingExpr.isInvalid()) |
| 6960 | return ExprError(); |
| 6961 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6962 | SmallVector<Expr *, 4> AssocExprs; |
| 6963 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6964 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6965 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6966 | if (TS) { |
| 6967 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6968 | if (!AssocType) |
| 6969 | return ExprError(); |
| 6970 | AssocTypes.push_back(AssocType); |
| 6971 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6972 | AssocTypes.push_back(nullptr); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6973 | } |
| 6974 | |
| 6975 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6976 | if (AssocExpr.isInvalid()) |
| 6977 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6978 | AssocExprs.push_back(AssocExpr.get()); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6982 | E->getDefaultLoc(), |
| 6983 | E->getRParenLoc(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6984 | ControllingExpr.get(), |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 6985 | AssocTypes, |
| 6986 | AssocExprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | template<typename Derived> |
| 6990 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6991 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6992 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6993 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6994 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6995 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6996 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6997 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6998 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6999 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7000 | E->getRParen()); |
| 7001 | } |
| 7002 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7003 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 7004 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 7005 | /// object available. |
| 7006 | template<typename Derived> |
| 7007 | ExprResult |
| 7008 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 7009 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7010 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7011 | else |
| 7012 | return getDerived().TransformExpr(E); |
| 7013 | } |
| 7014 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7015 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7016 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7017 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 7018 | ExprResult SubExpr; |
| 7019 | if (E->getOpcode() == UO_AddrOf) |
| 7020 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 7021 | else |
| 7022 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7023 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7024 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7025 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7026 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7027 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7028 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7029 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 7030 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7031 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7032 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7034 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7035 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7036 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 7037 | // Transform the type. |
| 7038 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7039 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7040 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7041 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7042 | // Transform all of the components into components similar to what the |
| 7043 | // parser uses. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7044 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 7045 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 7046 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7047 | // template code that we don't care. |
| 7048 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7049 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7050 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7051 | SmallVector<Component, 4> Components; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7052 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 7053 | const Node &ON = E->getComponent(I); |
| 7054 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 7055 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 7056 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 7057 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7058 | switch (ON.getKind()) { |
| 7059 | case Node::Array: { |
| 7060 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7061 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7062 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7063 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7064 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7065 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 7066 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7067 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7068 | break; |
| 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 | case Node::Field: |
| 7072 | case Node::Identifier: |
| 7073 | Comp.isBrackets = false; |
| 7074 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 7075 | if (!Comp.U.IdentInfo) |
| 7076 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7077 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7078 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7079 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 7080 | case Node::Base: |
| 7081 | // Will be recomputed during the rebuild. |
| 7082 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7083 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7084 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7085 | Components.push_back(Comp); |
| 7086 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7087 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7088 | // If nothing changed, retain the existing expression. |
| 7089 | if (!getDerived().AlwaysRebuild() && |
| 7090 | Type == E->getTypeSourceInfo() && |
| 7091 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7092 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7093 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7094 | // Build a new offsetof expression. |
| 7095 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 7096 | Components.data(), Components.size(), |
| 7097 | E->getRParenLoc()); |
| 7098 | } |
| 7099 | |
| 7100 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7101 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7102 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 7103 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 7104 | "opaque value expression requires transformation"); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7105 | return E; |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | template<typename Derived> |
| 7109 | ExprResult |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7110 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 7111 | // Rebuild the syntactic form. The original syntactic form has |
| 7112 | // opaque-value expressions in it, so strip those away and rebuild |
| 7113 | // the result. This is a really awful way of doing this, but the |
| 7114 | // better solution (rebuilding the semantic expressions and |
| 7115 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 7116 | // TreeTransform to not strip away implicit conversions. |
| 7117 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 7118 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7119 | if (result.isInvalid()) return ExprError(); |
| 7120 | |
| 7121 | // If that gives us a pseudo-object result back, the pseudo-object |
| 7122 | // expression must have been an lvalue-to-rvalue conversion which we |
| 7123 | // should reapply. |
| 7124 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7125 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7126 | |
| 7127 | return result; |
| 7128 | } |
| 7129 | |
| 7130 | template<typename Derived> |
| 7131 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7132 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 7133 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7134 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7135 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7136 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7137 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7138 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7139 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7140 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7141 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7142 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7143 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7144 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 7145 | E->getKind(), |
| 7146 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7147 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7148 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7149 | // C++0x [expr.sizeof]p1: |
| 7150 | // The operand is either an expression, which is an unevaluated operand |
| 7151 | // [...] |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7152 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7153 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7154 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7155 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 7156 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 7157 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 7158 | ExprResult SubExpr; |
| 7159 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 7160 | if (auto *DRE = |
| 7161 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 7162 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 7163 | PE, DRE, false, &RecoveryTSI); |
| 7164 | else |
| 7165 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 7166 | |
| 7167 | if (RecoveryTSI) { |
| 7168 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 7169 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 7170 | } else if (SubExpr.isInvalid()) |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7171 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7172 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7173 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7174 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7175 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7176 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 7177 | E->getOperatorLoc(), |
| 7178 | E->getKind(), |
| 7179 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7180 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7181 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7182 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7183 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7184 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7185 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7186 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7187 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7188 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7189 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7190 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7191 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7192 | |
| 7193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7194 | if (!getDerived().AlwaysRebuild() && |
| 7195 | LHS.get() == E->getLHS() && |
| 7196 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7197 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7198 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7199 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7200 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7201 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7202 | E->getRBracketLoc()); |
| 7203 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7204 | |
| 7205 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7206 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7207 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7208 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7209 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7210 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7211 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7212 | |
| 7213 | // Transform arguments. |
| 7214 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7215 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7216 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7217 | &ArgChanged)) |
| 7218 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7219 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7220 | if (!getDerived().AlwaysRebuild() && |
| 7221 | Callee.get() == E->getCallee() && |
| 7222 | !ArgChanged) |
Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 7223 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7224 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7225 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7226 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7227 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7228 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7229 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7230 | E->getRParenLoc()); |
| 7231 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7232 | |
| 7233 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7234 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7235 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7236 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7237 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7238 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7239 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7240 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7241 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7242 | QualifierLoc |
| 7243 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7244 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7245 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7246 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7247 | } |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7248 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7249 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 7250 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7251 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 7252 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7253 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7254 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7255 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7256 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 7257 | if (FoundDecl == E->getMemberDecl()) { |
| 7258 | FoundDecl = Member; |
| 7259 | } else { |
| 7260 | FoundDecl = cast_or_null<NamedDecl>( |
| 7261 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 7262 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7263 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7264 | } |
| 7265 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7266 | if (!getDerived().AlwaysRebuild() && |
| 7267 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7268 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7269 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7270 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7271 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7272 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 7273 | // Mark it referenced in the new context regardless. |
| 7274 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7275 | SemaRef.MarkMemberReferenced(E); |
| 7276 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7277 | return E; |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 7278 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7279 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7280 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7281 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7282 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 7283 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7284 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7285 | E->getNumTemplateArgs(), |
| 7286 | TransArgs)) |
| 7287 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7288 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7289 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7290 | // FIXME: Bogus source location for the operator |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7291 | SourceLocation FakeOperatorLoc = |
| 7292 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7293 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7294 | // FIXME: to do this check properly, we will need to preserve the |
| 7295 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7296 | // base (and therefore couldn't do the check) and a |
| 7297 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7298 | NamedDecl *FirstQualifierInScope = nullptr; |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7299 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7300 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7301 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7302 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7303 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7304 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7305 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7306 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7307 | (E->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7308 | ? &TransArgs : nullptr), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7309 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7310 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7311 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7312 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7313 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7314 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7315 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7316 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7317 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7318 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7319 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7320 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7321 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7322 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7323 | if (!getDerived().AlwaysRebuild() && |
| 7324 | LHS.get() == E->getLHS() && |
| 7325 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7326 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7327 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7328 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7329 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7330 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7331 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7332 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7333 | } |
| 7334 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7335 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7336 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7337 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7338 | CompoundAssignOperator *E) { |
| 7339 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7341 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7342 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7343 | ExprResult TreeTransform<Derived>:: |
| 7344 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 7345 | // Just rebuild the common and RHS expressions and see whether we |
| 7346 | // get any changes. |
| 7347 | |
| 7348 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 7349 | if (commonExpr.isInvalid()) |
| 7350 | return ExprError(); |
| 7351 | |
| 7352 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 7353 | if (rhs.isInvalid()) |
| 7354 | return ExprError(); |
| 7355 | |
| 7356 | if (!getDerived().AlwaysRebuild() && |
| 7357 | commonExpr.get() == e->getCommon() && |
| 7358 | rhs.get() == e->getFalseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7359 | return e; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7360 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7361 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7362 | e->getQuestionLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7363 | nullptr, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7364 | e->getColonLoc(), |
| 7365 | rhs.get()); |
| 7366 | } |
| 7367 | |
| 7368 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7369 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7370 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7371 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7372 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7373 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7374 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7375 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7376 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7377 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7378 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7379 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7380 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7381 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7382 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7383 | if (!getDerived().AlwaysRebuild() && |
| 7384 | Cond.get() == E->getCond() && |
| 7385 | LHS.get() == E->getLHS() && |
| 7386 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7387 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7388 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7389 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 7390 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7391 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 7392 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7393 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7394 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7395 | |
| 7396 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7397 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7398 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 7399 | // Implicit casts are eliminated during transformation, since they |
| 7400 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7401 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7402 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7403 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7404 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7405 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7406 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7407 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7408 | if (!Type) |
| 7409 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7410 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7411 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7412 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7413 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7414 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7415 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7416 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7417 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7418 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7419 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7420 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 7421 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7422 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7423 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7424 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7425 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7426 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7427 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7428 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7429 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7430 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 7431 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 7432 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7433 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7434 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7435 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7436 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7437 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7440 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7441 | Init.get() == E->getInitializer()) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7442 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7443 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 7444 | // Note: the expression type doesn't necessarily match the |
| 7445 | // type-as-written, but that's okay, because it should always be |
| 7446 | // derivable from the initializer. |
| 7447 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7448 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7449 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7450 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7451 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7452 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7453 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7454 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7455 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7456 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7457 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7458 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7459 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7460 | if (!getDerived().AlwaysRebuild() && |
| 7461 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7462 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7463 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7464 | // FIXME: Bad source location |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7465 | SourceLocation FakeOperatorLoc = |
| 7466 | SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7467 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7468 | E->getAccessorLoc(), |
| 7469 | E->getAccessor()); |
| 7470 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7471 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7472 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7473 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7474 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7475 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7476 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7477 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7478 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7479 | Inits, &InitChanged)) |
| 7480 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7481 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7482 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7483 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7484 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7485 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 7486 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7487 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7488 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7489 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7490 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7491 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7492 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7493 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7494 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7495 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7496 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7497 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7498 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7499 | // transform the designators. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7500 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7501 | bool ExprChanged = false; |
| 7502 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 7503 | DEnd = E->designators_end(); |
| 7504 | D != DEnd; ++D) { |
| 7505 | if (D->isFieldDesignator()) { |
| 7506 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 7507 | D->getDotLoc(), |
| 7508 | D->getFieldLoc())); |
| 7509 | continue; |
| 7510 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7511 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7512 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7513 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7514 | if (Index.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 | |
| 7517 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7518 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7519 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7520 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7521 | ArrayExprs.push_back(Index.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7522 | continue; |
| 7523 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7524 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7525 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7526 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7527 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 7528 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7529 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7530 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7531 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7532 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7533 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7534 | |
| 7535 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7536 | End.get(), |
| 7537 | D->getLBracketLoc(), |
| 7538 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7539 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7540 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 7541 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7542 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7543 | ArrayExprs.push_back(Start.get()); |
| 7544 | ArrayExprs.push_back(End.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7545 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7546 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7547 | if (!getDerived().AlwaysRebuild() && |
| 7548 | Init.get() == E->getInit() && |
| 7549 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7550 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7551 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7552 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7553 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7554 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7555 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7556 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7557 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7558 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7559 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7560 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7561 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7562 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7563 | // FIXME: Will we ever have proper type location here? Will we actually |
| 7564 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7565 | QualType T = getDerived().TransformType(E->getType()); |
| 7566 | if (T.isNull()) |
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 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7569 | if (!getDerived().AlwaysRebuild() && |
| 7570 | T == E->getType()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7571 | return E; |
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 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 7574 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7575 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7576 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7577 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7578 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 7579 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 7580 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7581 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7582 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7583 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7584 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7585 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7586 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7587 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7588 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7589 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7590 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7591 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7592 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7593 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7594 | } |
| 7595 | |
| 7596 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7597 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7598 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7599 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7600 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7601 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 7602 | &ArgumentChanged)) |
| 7603 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7604 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7605 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7606 | Inits, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7607 | E->getRParenLoc()); |
| 7608 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7609 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7610 | /// \brief Transform an address-of-label expression. |
| 7611 | /// |
| 7612 | /// By default, the transformation of an address-of-label expression always |
| 7613 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 7614 | /// the corresponding label statement by semantic analysis. |
| 7615 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7616 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7617 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7618 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 7619 | E->getLabel()); |
| 7620 | if (!LD) |
| 7621 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7622 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7623 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7624 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7625 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7626 | |
| 7627 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7628 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7629 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7630 | SemaRef.ActOnStartStmtExpr(); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7631 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7632 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7633 | if (SubStmt.isInvalid()) { |
| 7634 | SemaRef.ActOnStmtExprError(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7635 | return ExprError(); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7636 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7638 | if (!getDerived().AlwaysRebuild() && |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7639 | SubStmt.get() == E->getSubStmt()) { |
| 7640 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 7641 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7642 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7643 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7644 | |
| 7645 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7646 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7647 | E->getRParenLoc()); |
| 7648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7650 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7651 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7652 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7653 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7654 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7655 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7656 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7657 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7658 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7659 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7660 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7661 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7662 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7663 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7664 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7665 | if (!getDerived().AlwaysRebuild() && |
| 7666 | Cond.get() == E->getCond() && |
| 7667 | LHS.get() == E->getLHS() && |
| 7668 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7669 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7671 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7672 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7673 | E->getRParenLoc()); |
| 7674 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7675 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7676 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7677 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7678 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7679 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7680 | } |
| 7681 | |
| 7682 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7683 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7684 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7685 | switch (E->getOperator()) { |
| 7686 | case OO_New: |
| 7687 | case OO_Delete: |
| 7688 | case OO_Array_New: |
| 7689 | case OO_Array_Delete: |
| 7690 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7691 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7692 | case OO_Call: { |
| 7693 | // This is a call to an object's operator(). |
| 7694 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 7695 | |
| 7696 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7697 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7698 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7699 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7700 | |
| 7701 | // FIXME: Poor location information |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7702 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| 7703 | static_cast<Expr *>(Object.get())->getLocEnd()); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7704 | |
| 7705 | // Transform the call arguments. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7706 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7707 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7708 | Args)) |
| 7709 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7710 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7711 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7712 | Args, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7713 | E->getLocEnd()); |
| 7714 | } |
| 7715 | |
| 7716 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 7717 | case OO_##Name: |
| 7718 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 7719 | #include "clang/Basic/OperatorKinds.def" |
| 7720 | case OO_Subscript: |
| 7721 | // Handled below. |
| 7722 | break; |
| 7723 | |
| 7724 | case OO_Conditional: |
| 7725 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7726 | |
| 7727 | case OO_None: |
| 7728 | case NUM_OVERLOADED_OPERATORS: |
| 7729 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7730 | } |
| 7731 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7732 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7733 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7734 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7735 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7736 | ExprResult First; |
| 7737 | if (E->getOperator() == OO_Amp) |
| 7738 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 7739 | else |
| 7740 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7741 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7742 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7743 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7744 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7745 | if (E->getNumArgs() == 2) { |
| 7746 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 7747 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7748 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7749 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7751 | if (!getDerived().AlwaysRebuild() && |
| 7752 | Callee.get() == E->getCallee() && |
| 7753 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7754 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7755 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7756 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7757 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7758 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7759 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7760 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 7761 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7762 | Callee.get(), |
| 7763 | First.get(), |
| 7764 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7765 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7766 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7767 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7768 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7769 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7770 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7771 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7772 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7773 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7774 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7775 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 7776 | // Transform the callee. |
| 7777 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 7778 | if (Callee.isInvalid()) |
| 7779 | return ExprError(); |
| 7780 | |
| 7781 | // Transform exec config. |
| 7782 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 7783 | if (EC.isInvalid()) |
| 7784 | return ExprError(); |
| 7785 | |
| 7786 | // Transform arguments. |
| 7787 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7788 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7789 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7790 | &ArgChanged)) |
| 7791 | return ExprError(); |
| 7792 | |
| 7793 | if (!getDerived().AlwaysRebuild() && |
| 7794 | Callee.get() == E->getCallee() && |
| 7795 | !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7796 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7797 | |
| 7798 | // FIXME: Wrong source location information for the '('. |
| 7799 | SourceLocation FakeLParenLoc |
| 7800 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 7801 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7802 | Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7803 | E->getRParenLoc(), EC.get()); |
| 7804 | } |
| 7805 | |
| 7806 | template<typename Derived> |
| 7807 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7808 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7809 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7810 | if (!Type) |
| 7811 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7812 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7813 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7814 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7815 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7816 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7817 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7818 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7819 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7820 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7821 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7822 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7823 | E->getStmtClass(), |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7824 | E->getAngleBrackets().getBegin(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7825 | Type, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7826 | E->getAngleBrackets().getEnd(), |
| 7827 | // FIXME. this should be '(' location |
| 7828 | E->getAngleBrackets().getEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7829 | SubExpr.get(), |
Abramo Bagnara | 9fb4386 | 2012-10-15 21:08:58 +0000 | [diff] [blame] | 7830 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7831 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7832 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7833 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7834 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7835 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 7836 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7837 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7838 | |
| 7839 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7840 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7841 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 7842 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7843 | } |
| 7844 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7845 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7846 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7847 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7848 | CXXReinterpretCastExpr *E) { |
| 7849 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7850 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7851 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7852 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7853 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7854 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 7855 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7856 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7857 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7858 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7859 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7860 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7861 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7862 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7863 | if (!Type) |
| 7864 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7865 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7866 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7867 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7868 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7869 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7870 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7871 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7872 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7873 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7874 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7875 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7876 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 7877 | E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7878 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7879 | E->getRParenLoc()); |
| 7880 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7881 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7882 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7883 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7884 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7885 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7886 | TypeSourceInfo *TInfo |
| 7887 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7888 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7889 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7891 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7892 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7893 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7894 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7895 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7896 | E->getLocStart(), |
| 7897 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7898 | E->getLocEnd()); |
| 7899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7900 | |
Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7901 | // We don't know whether the subexpression is potentially evaluated until |
| 7902 | // after we perform semantic analysis. We speculatively assume it is |
| 7903 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7904 | // potentially evaluated. |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7905 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7906 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7907 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7908 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7909 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7910 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7911 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7912 | if (!getDerived().AlwaysRebuild() && |
| 7913 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7914 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7915 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7916 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7917 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7918 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7919 | E->getLocEnd()); |
| 7920 | } |
| 7921 | |
| 7922 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7923 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7924 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7925 | if (E->isTypeOperand()) { |
| 7926 | TypeSourceInfo *TInfo |
| 7927 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7928 | if (!TInfo) |
| 7929 | return ExprError(); |
| 7930 | |
| 7931 | if (!getDerived().AlwaysRebuild() && |
| 7932 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7933 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7934 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7935 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7936 | E->getLocStart(), |
| 7937 | TInfo, |
| 7938 | E->getLocEnd()); |
| 7939 | } |
| 7940 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7941 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7942 | |
| 7943 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7944 | if (SubExpr.isInvalid()) |
| 7945 | return ExprError(); |
| 7946 | |
| 7947 | if (!getDerived().AlwaysRebuild() && |
| 7948 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7949 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7950 | |
| 7951 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7952 | E->getLocStart(), |
| 7953 | SubExpr.get(), |
| 7954 | E->getLocEnd()); |
| 7955 | } |
| 7956 | |
| 7957 | template<typename Derived> |
| 7958 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7959 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7960 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7963 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7964 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7965 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7966 | CXXNullPtrLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7967 | return E; |
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>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 7973 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7974 | |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7975 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7976 | // Make sure that we capture 'this'. |
| 7977 | getSema().CheckCXXThisCapture(E->getLocStart()); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7978 | return E; |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7979 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7980 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7981 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7982 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7983 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7984 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7985 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7986 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7987 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7988 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7989 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7990 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7991 | if (!getDerived().AlwaysRebuild() && |
| 7992 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7993 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7994 | |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7995 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7996 | E->isThrownVariableInScope()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7998 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7999 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8000 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8001 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8002 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8003 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8004 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8005 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8006 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8007 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 8008 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8009 | Param == E->getParam()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8010 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8011 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 8012 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8013 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8014 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8015 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8016 | ExprResult |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8017 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 8018 | FieldDecl *Field |
| 8019 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8020 | E->getField())); |
| 8021 | if (!Field) |
| 8022 | return ExprError(); |
| 8023 | |
| 8024 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8025 | return E; |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8026 | |
| 8027 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 8028 | } |
| 8029 | |
| 8030 | template<typename Derived> |
| 8031 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8032 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 8033 | CXXScalarValueInitExpr *E) { |
| 8034 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8035 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8036 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8037 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8038 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8039 | T == E->getTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8040 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8041 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8042 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8043 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 8044 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8045 | } |
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 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8048 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8049 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8050 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8051 | TypeSourceInfo *AllocTypeInfo |
| 8052 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 8053 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8054 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8055 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8056 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8057 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8058 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8059 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8060 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8061 | // Transform the placement arguments (if any). |
| 8062 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8063 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8064 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8065 | E->getNumPlacementArgs(), true, |
| 8066 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8067 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8068 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8069 | // Transform the initializer (if any). |
| 8070 | Expr *OldInit = E->getInitializer(); |
| 8071 | ExprResult NewInit; |
| 8072 | if (OldInit) |
| 8073 | NewInit = getDerived().TransformExpr(OldInit); |
| 8074 | if (NewInit.isInvalid()) |
| 8075 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8076 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8077 | // Transform new operator and delete operator. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8078 | FunctionDecl *OperatorNew = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8079 | if (E->getOperatorNew()) { |
| 8080 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8081 | getDerived().TransformDecl(E->getLocStart(), |
| 8082 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8083 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8084 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8085 | } |
| 8086 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8087 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8088 | if (E->getOperatorDelete()) { |
| 8089 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8090 | getDerived().TransformDecl(E->getLocStart(), |
| 8091 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8092 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8093 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8094 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8095 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8096 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8097 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8098 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8099 | NewInit.get() == OldInit && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8100 | OperatorNew == E->getOperatorNew() && |
| 8101 | OperatorDelete == E->getOperatorDelete() && |
| 8102 | !ArgumentChanged) { |
| 8103 | // Mark any declarations we need as referenced. |
| 8104 | // FIXME: instantiation-specific. |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8105 | if (OperatorNew) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8106 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8107 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8108 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8109 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8110 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8111 | QualType ElementType |
| 8112 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 8113 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 8114 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 8115 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8116 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8117 | } |
| 8118 | } |
| 8119 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8120 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8121 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8122 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8123 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8124 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8125 | if (!ArraySize.get()) { |
| 8126 | // If no array size was specified, but the new expression was |
| 8127 | // instantiated with an array type (e.g., "new T" where T is |
| 8128 | // instantiated with "int[4]"), extract the outer bound from the |
| 8129 | // array type as our array size. We do this with constant and |
| 8130 | // dependently-sized array types. |
| 8131 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 8132 | if (!ArrayT) { |
| 8133 | // Do nothing |
| 8134 | } else if (const ConstantArrayType *ConsArrayT |
| 8135 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8136 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 8137 | SemaRef.Context.getSizeType(), |
| 8138 | /*FIXME:*/ E->getLocStart()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8139 | AllocType = ConsArrayT->getElementType(); |
| 8140 | } else if (const DependentSizedArrayType *DepArrayT |
| 8141 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 8142 | if (DepArrayT->getSizeExpr()) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8143 | ArraySize = DepArrayT->getSizeExpr(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8144 | AllocType = DepArrayT->getElementType(); |
| 8145 | } |
| 8146 | } |
| 8147 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8148 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8149 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 8150 | E->isGlobalNew(), |
| 8151 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8152 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8153 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 8154 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8155 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8156 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8157 | ArraySize.get(), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8158 | E->getDirectInitRange(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8159 | NewInit.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8160 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8161 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8162 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8163 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8164 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8165 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8166 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8167 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8168 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8169 | // Transform the delete operator, if known. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8170 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8171 | if (E->getOperatorDelete()) { |
| 8172 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8173 | getDerived().TransformDecl(E->getLocStart(), |
| 8174 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8175 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8176 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8177 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8178 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8179 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8180 | Operand.get() == E->getArgument() && |
| 8181 | OperatorDelete == E->getOperatorDelete()) { |
| 8182 | // Mark any declarations we need as referenced. |
| 8183 | // FIXME: instantiation-specific. |
| 8184 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8185 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8186 | |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8187 | if (!E->getArgument()->isTypeDependent()) { |
| 8188 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 8189 | E->getDestroyedType()); |
| 8190 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 8191 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8192 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8193 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8194 | } |
| 8195 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8196 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8197 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8199 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8200 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 8201 | E->isGlobalDelete(), |
| 8202 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8203 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8204 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8206 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8207 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8208 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8209 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8210 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8211 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8212 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8213 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8214 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8215 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8216 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8217 | E->getOperatorLoc(), |
| 8218 | E->isArrow()? tok::arrow : tok::period, |
| 8219 | ObjectTypePtr, |
| 8220 | MayBePseudoDestructor); |
| 8221 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8222 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8223 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8224 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8225 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 8226 | if (QualifierLoc) { |
| 8227 | QualifierLoc |
| 8228 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 8229 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8230 | return ExprError(); |
| 8231 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8232 | CXXScopeSpec SS; |
| 8233 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8234 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8235 | PseudoDestructorTypeStorage Destroyed; |
| 8236 | if (E->getDestroyedTypeInfo()) { |
| 8237 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8238 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8239 | ObjectType, nullptr, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8240 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8241 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8242 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 8243 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8244 | // We aren't likely to be able to resolve the identifier down to a type |
| 8245 | // now anyway, so just retain the identifier. |
| 8246 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 8247 | E->getDestroyedTypeLoc()); |
| 8248 | } else { |
| 8249 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8250 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8251 | *E->getDestroyedTypeIdentifier(), |
| 8252 | E->getDestroyedTypeLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8253 | /*Scope=*/nullptr, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8254 | SS, ObjectTypePtr, |
| 8255 | false); |
| 8256 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8257 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8258 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8259 | Destroyed |
| 8260 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 8261 | E->getDestroyedTypeLoc()); |
| 8262 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8263 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8264 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8265 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 8266 | CXXScopeSpec EmptySS; |
| 8267 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8268 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8269 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8270 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8271 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8272 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8273 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8274 | E->getOperatorLoc(), |
| 8275 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8276 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8277 | ScopeTypeInfo, |
| 8278 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8279 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8280 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8281 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8282 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8283 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8284 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8285 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8286 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8287 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 8288 | Sema::LookupOrdinaryName); |
| 8289 | |
| 8290 | // Transform all the decls. |
| 8291 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 8292 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8293 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8294 | getDerived().TransformDecl(Old->getNameLoc(), |
| 8295 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8296 | if (!InstD) { |
| 8297 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8298 | // This can happen because of dependent hiding. |
| 8299 | if (isa<UsingShadowDecl>(*I)) |
| 8300 | continue; |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8301 | else { |
| 8302 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8303 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8304 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8305 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8306 | |
| 8307 | // Expand using declarations. |
| 8308 | if (isa<UsingDecl>(InstD)) { |
| 8309 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 8310 | for (auto *I : UD->shadows()) |
| 8311 | R.addDecl(I); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8312 | continue; |
| 8313 | } |
| 8314 | |
| 8315 | R.addDecl(InstD); |
| 8316 | } |
| 8317 | |
| 8318 | // Resolve a kind, but don't do any further analysis. If it's |
| 8319 | // ambiguous, the callee needs to deal with it. |
| 8320 | R.resolveKind(); |
| 8321 | |
| 8322 | // Rebuild the nested-name qualifier, if present. |
| 8323 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8324 | if (Old->getQualifierLoc()) { |
| 8325 | NestedNameSpecifierLoc QualifierLoc |
| 8326 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8327 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8328 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8329 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8330 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8331 | } |
| 8332 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8333 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8334 | CXXRecordDecl *NamingClass |
| 8335 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 8336 | Old->getNameLoc(), |
| 8337 | Old->getNamingClass())); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8338 | if (!NamingClass) { |
| 8339 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8340 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8341 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8342 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8343 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8344 | } |
| 8345 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8346 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8347 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 8348 | // If we have neither explicit template arguments, nor the template keyword, |
| 8349 | // it's a normal declaration name. |
| 8350 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8351 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 8352 | |
| 8353 | // If we have template arguments, rebuild them, then rebuild the |
| 8354 | // templateid expression. |
| 8355 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 8356 | if (Old->hasExplicitTemplateArgs() && |
| 8357 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8358 | Old->getNumTemplateArgs(), |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8359 | TransArgs)) { |
| 8360 | R.clear(); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8361 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8362 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8363 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8364 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 8365 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8367 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8368 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8369 | ExprResult |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8370 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 8371 | bool ArgChanged = false; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8372 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8373 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 8374 | TypeSourceInfo *From = E->getArg(I); |
| 8375 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 8376 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8377 | TypeLocBuilder TLB; |
| 8378 | TLB.reserve(FromTL.getFullDataSize()); |
| 8379 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 8380 | if (To.isNull()) |
| 8381 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8382 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8383 | if (To == From->getType()) |
| 8384 | Args.push_back(From); |
| 8385 | else { |
| 8386 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8387 | ArgChanged = true; |
| 8388 | } |
| 8389 | continue; |
| 8390 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8391 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8392 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8393 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8394 | // We have a pack expansion. Instantiate it. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 8395 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8396 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 8397 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8398 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
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 | // Determine whether the set of unexpanded parameter packs can and should |
| 8401 | // be expanded. |
| 8402 | bool Expand = true; |
| 8403 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8404 | Optional<unsigned> OrigNumExpansions = |
| 8405 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 8406 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8407 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 8408 | PatternTL.getSourceRange(), |
| 8409 | Unexpanded, |
| 8410 | Expand, RetainExpansion, |
| 8411 | NumExpansions)) |
| 8412 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8413 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8414 | if (!Expand) { |
| 8415 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8416 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8417 | // expansion. |
| 8418 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
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 | TypeLocBuilder TLB; |
| 8421 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 8422 | |
| 8423 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8424 | if (To.isNull()) |
| 8425 | return ExprError(); |
| 8426 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8427 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8428 | PatternTL.getSourceRange(), |
| 8429 | ExpansionTL.getEllipsisLoc(), |
| 8430 | NumExpansions); |
| 8431 | if (To.isNull()) |
| 8432 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8433 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8434 | PackExpansionTypeLoc ToExpansionTL |
| 8435 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8436 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8437 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8438 | continue; |
| 8439 | } |
| 8440 | |
| 8441 | // Expand the pack expansion by substituting for each argument in the |
| 8442 | // pack(s). |
| 8443 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8444 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 8445 | TypeLocBuilder TLB; |
| 8446 | TLB.reserve(PatternTL.getFullDataSize()); |
| 8447 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8448 | if (To.isNull()) |
| 8449 | return ExprError(); |
| 8450 | |
Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 8451 | if (To->containsUnexpandedParameterPack()) { |
| 8452 | To = getDerived().RebuildPackExpansionType(To, |
| 8453 | PatternTL.getSourceRange(), |
| 8454 | ExpansionTL.getEllipsisLoc(), |
| 8455 | NumExpansions); |
| 8456 | if (To.isNull()) |
| 8457 | return ExprError(); |
| 8458 | |
| 8459 | PackExpansionTypeLoc ToExpansionTL |
| 8460 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8461 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8462 | } |
| 8463 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8464 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8465 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8466 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8467 | if (!RetainExpansion) |
| 8468 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8469 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8470 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 8471 | // forgetting the partially-substituted parameter pack. |
| 8472 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 8473 | |
| 8474 | TypeLocBuilder TLB; |
| 8475 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8476 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8477 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8478 | if (To.isNull()) |
| 8479 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8480 | |
| 8481 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8482 | PatternTL.getSourceRange(), |
| 8483 | ExpansionTL.getEllipsisLoc(), |
| 8484 | NumExpansions); |
| 8485 | if (To.isNull()) |
| 8486 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8487 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8488 | PackExpansionTypeLoc ToExpansionTL |
| 8489 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8490 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8491 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8492 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8493 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8494 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8495 | return E; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8496 | |
| 8497 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 8498 | E->getLocStart(), |
| 8499 | Args, |
| 8500 | E->getLocEnd()); |
| 8501 | } |
| 8502 | |
| 8503 | template<typename Derived> |
| 8504 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8505 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 8506 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 8507 | if (!T) |
| 8508 | return ExprError(); |
| 8509 | |
| 8510 | if (!getDerived().AlwaysRebuild() && |
| 8511 | T == E->getQueriedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8512 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8513 | |
| 8514 | ExprResult SubExpr; |
| 8515 | { |
| 8516 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8517 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 8518 | if (SubExpr.isInvalid()) |
| 8519 | return ExprError(); |
| 8520 | |
| 8521 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8522 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8523 | } |
| 8524 | |
| 8525 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 8526 | E->getLocStart(), |
| 8527 | T, |
| 8528 | SubExpr.get(), |
| 8529 | E->getLocEnd()); |
| 8530 | } |
| 8531 | |
| 8532 | template<typename Derived> |
| 8533 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8534 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 8535 | ExprResult SubExpr; |
| 8536 | { |
| 8537 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8538 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 8539 | if (SubExpr.isInvalid()) |
| 8540 | return ExprError(); |
| 8541 | |
| 8542 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8543 | return E; |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8544 | } |
| 8545 | |
| 8546 | return getDerived().RebuildExpressionTrait( |
| 8547 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 8548 | } |
| 8549 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8550 | template <typename Derived> |
| 8551 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 8552 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 8553 | TypeSourceInfo **RecoveryTSI) { |
| 8554 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 8555 | DRE, AddrTaken, RecoveryTSI); |
| 8556 | |
| 8557 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 8558 | if (!NewDRE.isUsable()) |
| 8559 | return NewDRE; |
| 8560 | |
| 8561 | // We got an expr, wrap it up in parens. |
| 8562 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 8563 | return PE; |
| 8564 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 8565 | PE->getRParen()); |
| 8566 | } |
| 8567 | |
| 8568 | template <typename Derived> |
| 8569 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8570 | DependentScopeDeclRefExpr *E) { |
| 8571 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 8572 | nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8573 | } |
| 8574 | |
| 8575 | template<typename Derived> |
| 8576 | ExprResult |
| 8577 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8578 | DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8579 | bool IsAddressOfOperand, |
| 8580 | TypeSourceInfo **RecoveryTSI) { |
Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 8581 | assert(E->getQualifierLoc()); |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8582 | NestedNameSpecifierLoc QualifierLoc |
| 8583 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8584 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8585 | return ExprError(); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8586 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8587 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8588 | // TODO: If this is a conversion-function-id, verify that the |
| 8589 | // destination type name (if present) resolves the same way after |
| 8590 | // instantiation as it did in the local scope. |
| 8591 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8592 | DeclarationNameInfo NameInfo |
| 8593 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 8594 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8595 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8596 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8597 | if (!E->hasExplicitTemplateArgs()) { |
| 8598 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8599 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8600 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 8601 | // if name has not changed, DNLoc has not changed either. |
| 8602 | NameInfo.getName() == E->getDeclName()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8603 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8604 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8605 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 8606 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 8607 | IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 8608 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8609 | |
| 8610 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8611 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8612 | E->getNumTemplateArgs(), |
| 8613 | TransArgs)) |
| 8614 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8615 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8616 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 8617 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 8618 | RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8619 | } |
| 8620 | |
| 8621 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8622 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8623 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8624 | // CXXConstructExprs other than for list-initialization and |
| 8625 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 8626 | // a 1-argument construction we just transform that argument. |
Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 8627 | if ((E->getNumArgs() == 1 || |
| 8628 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8629 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 8630 | !E->isListInitialization()) |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 8631 | return getDerived().TransformExpr(E->getArg(0)); |
| 8632 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8633 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 8634 | |
| 8635 | QualType T = getDerived().TransformType(E->getType()); |
| 8636 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8637 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8638 | |
| 8639 | CXXConstructorDecl *Constructor |
| 8640 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8641 | getDerived().TransformDecl(E->getLocStart(), |
| 8642 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8643 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8644 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8646 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8647 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8648 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8649 | &ArgumentChanged)) |
| 8650 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8651 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8652 | if (!getDerived().AlwaysRebuild() && |
| 8653 | T == E->getType() && |
| 8654 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8655 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8656 | // Mark the constructor as referenced. |
| 8657 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8658 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8659 | return E; |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8660 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8661 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 8662 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 8663 | Constructor, E->isElidable(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8664 | Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 8665 | E->hadMultipleCandidates(), |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8666 | E->isListInitialization(), |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 8667 | E->isStdInitListInitialization(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 8668 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 8669 | E->getConstructionKind(), |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 8670 | E->getParenOrBraceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8671 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8672 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8673 | /// \brief Transform a C++ temporary-binding expression. |
| 8674 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8675 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 8676 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8677 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8678 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8679 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8680 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8682 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8683 | /// \brief Transform a C++ expression that contains cleanups that should |
| 8684 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8685 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8686 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8687 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8688 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8689 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8690 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8691 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8692 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8693 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8694 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8695 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8696 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8697 | CXXTemporaryObjectExpr *E) { |
| 8698 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8699 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 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 | CXXConstructorDecl *Constructor |
| 8703 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8704 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8705 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8706 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8707 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8708 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8709 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8710 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8711 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8712 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8713 | &ArgumentChanged)) |
| 8714 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8715 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8716 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8717 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8718 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8719 | !ArgumentChanged) { |
| 8720 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8721 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8722 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8723 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8724 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8725 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8726 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 8727 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8728 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8729 | E->getLocEnd()); |
| 8730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8731 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8732 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8733 | ExprResult |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8734 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8735 | |
| 8736 | // Transform any init-capture expressions before entering the scope of the |
| 8737 | // lambda body, because they are not semantically within that scope. |
| 8738 | SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes; |
| 8739 | InitCaptureExprsAndTypes.resize(E->explicit_capture_end() - |
| 8740 | E->explicit_capture_begin()); |
| 8741 | |
| 8742 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 8743 | CEnd = E->capture_end(); |
| 8744 | C != CEnd; ++C) { |
| 8745 | if (!C->isInitCapture()) |
| 8746 | continue; |
| 8747 | EnterExpressionEvaluationContext EEEC(getSema(), |
| 8748 | Sema::PotentiallyEvaluated); |
| 8749 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 8750 | C->getCapturedVar()->getInit(), |
| 8751 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
| 8752 | |
| 8753 | if (NewExprInitResult.isInvalid()) |
| 8754 | return ExprError(); |
| 8755 | Expr *NewExprInit = NewExprInitResult.get(); |
| 8756 | |
| 8757 | VarDecl *OldVD = C->getCapturedVar(); |
| 8758 | QualType NewInitCaptureType = |
| 8759 | getSema().performLambdaInitCaptureInitialization(C->getLocation(), |
| 8760 | OldVD->getType()->isReferenceType(), OldVD->getIdentifier(), |
| 8761 | NewExprInit); |
| 8762 | NewExprInitResult = NewExprInit; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8763 | InitCaptureExprsAndTypes[C - E->capture_begin()] = |
| 8764 | std::make_pair(NewExprInitResult, NewInitCaptureType); |
| 8765 | |
| 8766 | } |
| 8767 | |
Faisal Vali | 524ca28 | 2013-11-12 01:40:44 +0000 | [diff] [blame] | 8768 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8769 | // Transform the template parameters, and add them to the current |
| 8770 | // instantiation scope. The null case is handled correctly. |
| 8771 | LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList( |
| 8772 | E->getTemplateParameterList()); |
| 8773 | |
| 8774 | // Check to see if the TypeSourceInfo of the call operator needs to |
| 8775 | // be transformed, and if so do the transformation in the |
| 8776 | // CurrentInstantiationScope. |
| 8777 | |
| 8778 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 8779 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 8780 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8781 | TypeSourceInfo *NewCallOpTSI = nullptr; |
| 8782 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8783 | const bool CallOpWasAlreadyTransformed = |
| 8784 | getDerived().AlreadyTransformed(OldCallOpTSI->getType()); |
| 8785 | |
| 8786 | // Use the Old Call Operator's TypeSourceInfo if it is already transformed. |
| 8787 | if (CallOpWasAlreadyTransformed) |
| 8788 | NewCallOpTSI = OldCallOpTSI; |
| 8789 | else { |
| 8790 | // Transform the TypeSourceInfo of the Original Lambda's Call Operator. |
| 8791 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 8792 | // it introduces a mapping of the original to the newly created |
| 8793 | // transformed parameters. |
| 8794 | |
| 8795 | TypeLocBuilder NewCallOpTLBuilder; |
| 8796 | QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder, |
| 8797 | OldCallOpFPTL, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8798 | nullptr, 0); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8799 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 8800 | NewCallOpType); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8801 | } |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8802 | // Extract the ParmVarDecls from the NewCallOpTSI and add them to |
| 8803 | // the vector below - this will be used to synthesize the |
| 8804 | // NewCallOperator. Additionally, add the parameters of the untransformed |
| 8805 | // lambda call operator to the CurrentInstantiationScope. |
| 8806 | SmallVector<ParmVarDecl *, 4> Params; |
| 8807 | { |
| 8808 | FunctionProtoTypeLoc NewCallOpFPTL = |
| 8809 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>(); |
| 8810 | ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray(); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 8811 | const unsigned NewNumArgs = NewCallOpFPTL.getNumParams(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8812 | |
| 8813 | for (unsigned I = 0; I < NewNumArgs; ++I) { |
| 8814 | // If this call operator's type does not require transformation, |
| 8815 | // the parameters do not get added to the current instantiation scope, |
| 8816 | // - so ADD them! This allows the following to compile when the enclosing |
| 8817 | // template is specialized and the entire lambda expression has to be |
| 8818 | // transformed. |
| 8819 | // template<class T> void foo(T t) { |
| 8820 | // auto L = [](auto a) { |
| 8821 | // auto M = [](char b) { <-- note: non-generic lambda |
| 8822 | // auto N = [](auto c) { |
| 8823 | // int x = sizeof(a); |
| 8824 | // x = sizeof(b); <-- specifically this line |
| 8825 | // x = sizeof(c); |
| 8826 | // }; |
| 8827 | // }; |
| 8828 | // }; |
| 8829 | // } |
| 8830 | // foo('a') |
| 8831 | if (CallOpWasAlreadyTransformed) |
| 8832 | getDerived().transformedLocalDecl(NewParamDeclArray[I], |
| 8833 | NewParamDeclArray[I]); |
| 8834 | // Add to Params array, so these parameters can be used to create |
| 8835 | // the newly transformed call operator. |
| 8836 | Params.push_back(NewParamDeclArray[I]); |
| 8837 | } |
| 8838 | } |
| 8839 | |
| 8840 | if (!NewCallOpTSI) |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8841 | return ExprError(); |
| 8842 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8843 | // Create the local class that will describe the lambda. |
| 8844 | CXXRecordDecl *Class |
| 8845 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8846 | NewCallOpTSI, |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 8847 | /*KnownDependent=*/false, |
| 8848 | E->getCaptureDefault()); |
| 8849 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8850 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 8851 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8852 | // Build the call operator. |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8853 | CXXMethodDecl *NewCallOperator |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8854 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8855 | NewCallOpTSI, |
Douglas Gregor | adb376e | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8856 | E->getCallOperator()->getLocEnd(), |
Richard Smith | 505df23 | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8857 | Params); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8858 | LSI->CallOperator = NewCallOperator; |
Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 8859 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8860 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| 8861 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8862 | return getDerived().TransformLambdaScope(E, NewCallOperator, |
| 8863 | InitCaptureExprsAndTypes); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8864 | } |
| 8865 | |
| 8866 | template<typename Derived> |
| 8867 | ExprResult |
| 8868 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8869 | CXXMethodDecl *CallOperator, |
| 8870 | ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8871 | bool Invalid = false; |
| 8872 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8873 | // Introduce the context of the call operator. |
Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 8874 | Sema::ContextRAII SavedContext(getSema(), CallOperator, |
| 8875 | /*NewThisContext*/false); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8876 | |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8877 | LambdaScopeInfo *const LSI = getSema().getCurLambda(); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8878 | // Enter the scope of the lambda. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8879 | getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8880 | E->getCaptureDefault(), |
James Dennett | ddd36ff | 2013-08-09 23:08:25 +0000 | [diff] [blame] | 8881 | E->getCaptureDefaultLoc(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8882 | E->hasExplicitParameters(), |
| 8883 | E->hasExplicitResultType(), |
| 8884 | E->isMutable()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8885 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8886 | // Transform captures. |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8887 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8888 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8889 | CEnd = E->capture_end(); |
| 8890 | C != CEnd; ++C) { |
| 8891 | // When we hit the first implicit capture, tell Sema that we've finished |
| 8892 | // the list of explicit captures. |
| 8893 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 8894 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8895 | FinishedExplicitCaptures = true; |
| 8896 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8897 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8898 | // Capturing 'this' is trivial. |
| 8899 | if (C->capturesThis()) { |
| 8900 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 8901 | continue; |
| 8902 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8903 | |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8904 | // Rebuild init-captures, including the implied field declaration. |
| 8905 | if (C->isInitCapture()) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8906 | |
| 8907 | InitCaptureInfoTy InitExprTypePair = |
| 8908 | InitCaptureExprsAndTypes[C - E->capture_begin()]; |
| 8909 | ExprResult Init = InitExprTypePair.first; |
| 8910 | QualType InitQualType = InitExprTypePair.second; |
| 8911 | if (Init.isInvalid() || InitQualType.isNull()) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8912 | Invalid = true; |
| 8913 | continue; |
| 8914 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8915 | VarDecl *OldVD = C->getCapturedVar(); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8916 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 8917 | OldVD->getLocation(), InitExprTypePair.second, |
| 8918 | OldVD->getIdentifier(), Init.get()); |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8919 | if (!NewVD) |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8920 | Invalid = true; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8921 | else { |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8922 | getDerived().transformedLocalDecl(OldVD, NewVD); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8923 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8924 | getSema().buildInitCaptureField(LSI, NewVD); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8925 | continue; |
| 8926 | } |
| 8927 | |
| 8928 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 8929 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8930 | // Determine the capture kind for Sema. |
| 8931 | Sema::TryCaptureKind Kind |
| 8932 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 8933 | : C->getCaptureKind() == LCK_ByCopy |
| 8934 | ? Sema::TryCapture_ExplicitByVal |
| 8935 | : Sema::TryCapture_ExplicitByRef; |
| 8936 | SourceLocation EllipsisLoc; |
| 8937 | if (C->isPackExpansion()) { |
| 8938 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 8939 | bool ShouldExpand = false; |
| 8940 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8941 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8942 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 8943 | C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8944 | Unexpanded, |
| 8945 | ShouldExpand, RetainExpansion, |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8946 | NumExpansions)) { |
| 8947 | Invalid = true; |
| 8948 | continue; |
| 8949 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8950 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8951 | if (ShouldExpand) { |
| 8952 | // The transform has determined that we should perform an expansion; |
| 8953 | // transform and capture each of the arguments. |
| 8954 | // expansion of the pattern. Do so. |
| 8955 | VarDecl *Pack = C->getCapturedVar(); |
| 8956 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8957 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8958 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8959 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8960 | Pack)); |
| 8961 | if (!CapturedVar) { |
| 8962 | Invalid = true; |
| 8963 | continue; |
| 8964 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8965 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8966 | // Capture the transformed variable. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8967 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 8968 | } |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 8969 | |
| 8970 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 8971 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8972 | continue; |
| 8973 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8974 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8975 | EllipsisLoc = C->getEllipsisLoc(); |
| 8976 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8977 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8978 | // Transform the captured variable. |
| 8979 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8980 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8981 | C->getCapturedVar())); |
| 8982 | if (!CapturedVar) { |
| 8983 | Invalid = true; |
| 8984 | continue; |
| 8985 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8986 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8987 | // Capture the transformed variable. |
Douglas Gregor | fdf598e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 8988 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8989 | } |
| 8990 | if (!FinishedExplicitCaptures) |
| 8991 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8992 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8993 | |
| 8994 | // Enter a new evaluation context to insulate the lambda from any |
| 8995 | // cleanups from the enclosing full-expression. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8996 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8997 | |
| 8998 | if (Invalid) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8999 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9000 | /*IsInstantiation=*/true); |
| 9001 | return ExprError(); |
| 9002 | } |
| 9003 | |
| 9004 | // Instantiate the body of the lambda expression. |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9005 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 9006 | if (Body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9007 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9008 | /*IsInstantiation=*/true); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9009 | return ExprError(); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9010 | } |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 9011 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9012 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9013 | /*CurScope=*/nullptr, |
| 9014 | /*IsInstantiation=*/true); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 9015 | } |
| 9016 | |
| 9017 | template<typename Derived> |
| 9018 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9019 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9020 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9021 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9022 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9023 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9024 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9025 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9026 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9027 | Args.reserve(E->arg_size()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9028 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9029 | &ArgumentChanged)) |
| 9030 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9031 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9032 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9033 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9034 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9035 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9037 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9038 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9039 | E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9040 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9041 | E->getRParenLoc()); |
| 9042 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9043 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9044 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9045 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 9046 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9047 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9048 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9049 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9050 | Expr *OldBase; |
| 9051 | QualType BaseType; |
| 9052 | QualType ObjectType; |
| 9053 | if (!E->isImplicitAccess()) { |
| 9054 | OldBase = E->getBase(); |
| 9055 | Base = getDerived().TransformExpr(OldBase); |
| 9056 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9057 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9058 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9059 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9060 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9061 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9062 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9063 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9064 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9065 | ObjectTy, |
| 9066 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9067 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9068 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9069 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9070 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9071 | BaseType = ((Expr*) Base.get())->getType(); |
| 9072 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9073 | OldBase = nullptr; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9074 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 9075 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 9076 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9077 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9078 | // Transform the first part of the nested-name-specifier that qualifies |
| 9079 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 9080 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9081 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9082 | E->getFirstQualifierFoundInScope(), |
| 9083 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9084 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9085 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9086 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9087 | QualifierLoc |
| 9088 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 9089 | ObjectType, |
| 9090 | FirstQualifierInScope); |
| 9091 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9092 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9094 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9095 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 9096 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9097 | // TODO: If this is a conversion-function-id, verify that the |
| 9098 | // destination type name (if present) resolves the same way after |
| 9099 | // instantiation as it did in the local scope. |
| 9100 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9101 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9102 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9103 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9104 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9105 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9106 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9107 | // This is a reference to a member without an explicitly-specified |
| 9108 | // template argument list. Optimize for this common case. |
| 9109 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9110 | Base.get() == OldBase && |
| 9111 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9112 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9113 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9114 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9115 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9116 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9117 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9118 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9119 | E->isArrow(), |
| 9120 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9121 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9122 | TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9123 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9124 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9125 | /*TemplateArgs*/nullptr); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9126 | } |
| 9127 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9128 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9129 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9130 | E->getNumTemplateArgs(), |
| 9131 | TransArgs)) |
| 9132 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9133 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9134 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9135 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9136 | E->isArrow(), |
| 9137 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9138 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9139 | TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9140 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9141 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9142 | &TransArgs); |
| 9143 | } |
| 9144 | |
| 9145 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9146 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9147 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9148 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9149 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9150 | QualType BaseType; |
| 9151 | if (!Old->isImplicitAccess()) { |
| 9152 | Base = getDerived().TransformExpr(Old->getBase()); |
| 9153 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9154 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9155 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 9156 | Old->isArrow()); |
| 9157 | if (Base.isInvalid()) |
| 9158 | return ExprError(); |
| 9159 | BaseType = Base.get()->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9160 | } else { |
| 9161 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 9162 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9163 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9164 | NestedNameSpecifierLoc QualifierLoc; |
| 9165 | if (Old->getQualifierLoc()) { |
| 9166 | QualifierLoc |
| 9167 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 9168 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9169 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9170 | } |
| 9171 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9172 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 9173 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9174 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9175 | Sema::LookupOrdinaryName); |
| 9176 | |
| 9177 | // Transform all the decls. |
| 9178 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 9179 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9180 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 9181 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 9182 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9183 | if (!InstD) { |
| 9184 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 9185 | // This can happen because of dependent hiding. |
| 9186 | if (isa<UsingShadowDecl>(*I)) |
| 9187 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9188 | else { |
| 9189 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9190 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9191 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9192 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9193 | |
| 9194 | // Expand using declarations. |
| 9195 | if (isa<UsingDecl>(InstD)) { |
| 9196 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 9197 | for (auto *I : UD->shadows()) |
| 9198 | R.addDecl(I); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9199 | continue; |
| 9200 | } |
| 9201 | |
| 9202 | R.addDecl(InstD); |
| 9203 | } |
| 9204 | |
| 9205 | R.resolveKind(); |
| 9206 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9207 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 9208 | if (Old->getNamingClass()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9209 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9210 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9211 | Old->getMemberLoc(), |
| 9212 | Old->getNamingClass())); |
| 9213 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9214 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9215 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9216 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9217 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9218 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9219 | TemplateArgumentListInfo TransArgs; |
| 9220 | if (Old->hasExplicitTemplateArgs()) { |
| 9221 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 9222 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9223 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 9224 | Old->getNumTemplateArgs(), |
| 9225 | TransArgs)) |
| 9226 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9227 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9228 | |
| 9229 | // FIXME: to do this check properly, we will need to preserve the |
| 9230 | // first-qualifier-in-scope here, just in case we had a dependent |
| 9231 | // base (and therefore couldn't do the check) and a |
| 9232 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9233 | NamedDecl *FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9234 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9235 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9236 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9237 | Old->getOperatorLoc(), |
| 9238 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9239 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9240 | TemplateKWLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9241 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9242 | R, |
| 9243 | (Old->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9244 | ? &TransArgs : nullptr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9245 | } |
| 9246 | |
| 9247 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9248 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9249 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Alexis Hunt | 414e3e3 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 9250 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9251 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 9252 | if (SubExpr.isInvalid()) |
| 9253 | return ExprError(); |
| 9254 | |
| 9255 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9256 | return E; |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9257 | |
| 9258 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 9259 | } |
| 9260 | |
| 9261 | template<typename Derived> |
| 9262 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9263 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9264 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 9265 | if (Pattern.isInvalid()) |
| 9266 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9267 | |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9268 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9269 | return E; |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9270 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 9271 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 9272 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9273 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9274 | |
| 9275 | template<typename Derived> |
| 9276 | ExprResult |
| 9277 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 9278 | // If E is not value-dependent, then nothing will change when we transform it. |
| 9279 | // Note: This is an instantiation-centric view. |
| 9280 | if (!E->isValueDependent()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9281 | return E; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9282 | |
| 9283 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 9284 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9285 | // so |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9286 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 9287 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 9288 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9289 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9290 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 9291 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 9292 | ShouldExpand, RetainExpansion, |
| 9293 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9294 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9295 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9296 | if (RetainExpansion) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9297 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9298 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9299 | NamedDecl *Pack = E->getPack(); |
| 9300 | if (!ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9301 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9302 | Pack)); |
| 9303 | if (!Pack) |
| 9304 | return ExprError(); |
| 9305 | } |
| 9306 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9307 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9308 | // We now know the length of the parameter pack, so build a new expression |
| 9309 | // that stores that length. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9310 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 9311 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9312 | NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9313 | } |
| 9314 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9315 | template<typename Derived> |
| 9316 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 9317 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 9318 | SubstNonTypeTemplateParmPackExpr *E) { |
| 9319 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9320 | return E; |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 9321 | } |
| 9322 | |
| 9323 | template<typename Derived> |
| 9324 | ExprResult |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 9325 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 9326 | SubstNonTypeTemplateParmExpr *E) { |
| 9327 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9328 | return E; |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 9329 | } |
| 9330 | |
| 9331 | template<typename Derived> |
| 9332 | ExprResult |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 9333 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 9334 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9335 | return E; |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 9336 | } |
| 9337 | |
| 9338 | template<typename Derived> |
| 9339 | ExprResult |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 9340 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 9341 | MaterializeTemporaryExpr *E) { |
| 9342 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 9343 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9344 | |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 9345 | template<typename Derived> |
| 9346 | ExprResult |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 9347 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 9348 | CXXStdInitializerListExpr *E) { |
| 9349 | return getDerived().TransformExpr(E->getSubExpr()); |
| 9350 | } |
| 9351 | |
| 9352 | template<typename Derived> |
| 9353 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9354 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9355 | return SemaRef.MaybeBindToTemporary(E); |
| 9356 | } |
| 9357 | |
| 9358 | template<typename Derived> |
| 9359 | ExprResult |
| 9360 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9361 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9362 | } |
| 9363 | |
| 9364 | template<typename Derived> |
| 9365 | ExprResult |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 9366 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 9367 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 9368 | if (SubExpr.isInvalid()) |
| 9369 | return ExprError(); |
| 9370 | |
| 9371 | if (!getDerived().AlwaysRebuild() && |
| 9372 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9373 | return E; |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 9374 | |
| 9375 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9376 | } |
| 9377 | |
| 9378 | template<typename Derived> |
| 9379 | ExprResult |
| 9380 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 9381 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9382 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9383 | bool ArgChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9384 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9385 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 9386 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9387 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9388 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 9389 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9390 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9391 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 9392 | Elements.data(), |
| 9393 | Elements.size()); |
| 9394 | } |
| 9395 | |
| 9396 | template<typename Derived> |
| 9397 | ExprResult |
| 9398 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9399 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9400 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9401 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9402 | bool ArgChanged = false; |
| 9403 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 9404 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9405 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9406 | if (OrigElement.isPackExpansion()) { |
| 9407 | // This key/value element is a pack expansion. |
| 9408 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 9409 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 9410 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 9411 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 9412 | |
| 9413 | // Determine whether the set of unexpanded parameter packs can |
| 9414 | // and should be expanded. |
| 9415 | bool Expand = true; |
| 9416 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9417 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 9418 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9419 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 9420 | OrigElement.Value->getLocEnd()); |
| 9421 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 9422 | PatternRange, |
| 9423 | Unexpanded, |
| 9424 | Expand, RetainExpansion, |
| 9425 | NumExpansions)) |
| 9426 | return ExprError(); |
| 9427 | |
| 9428 | if (!Expand) { |
| 9429 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9430 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9431 | // expansion. |
| 9432 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 9433 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9434 | if (Key.isInvalid()) |
| 9435 | return ExprError(); |
| 9436 | |
| 9437 | if (Key.get() != OrigElement.Key) |
| 9438 | ArgChanged = true; |
| 9439 | |
| 9440 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 9441 | if (Value.isInvalid()) |
| 9442 | return ExprError(); |
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 | if (Value.get() != OrigElement.Value) |
| 9445 | ArgChanged = true; |
| 9446 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9447 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9448 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 9449 | }; |
| 9450 | Elements.push_back(Expansion); |
| 9451 | continue; |
| 9452 | } |
| 9453 | |
| 9454 | // Record right away that the argument was changed. This needs |
| 9455 | // to happen even if the array expands to nothing. |
| 9456 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9457 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9458 | // The transform has determined that we should perform an elementwise |
| 9459 | // expansion of the pattern. Do so. |
| 9460 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9461 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 9462 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9463 | if (Key.isInvalid()) |
| 9464 | return ExprError(); |
| 9465 | |
| 9466 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 9467 | if (Value.isInvalid()) |
| 9468 | return ExprError(); |
| 9469 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9470 | ObjCDictionaryElement Element = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9471 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 9472 | }; |
| 9473 | |
| 9474 | // If any unexpanded parameter packs remain, we still have a |
| 9475 | // pack expansion. |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9476 | // FIXME: Can this really happen? |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9477 | if (Key.get()->containsUnexpandedParameterPack() || |
| 9478 | Value.get()->containsUnexpandedParameterPack()) |
| 9479 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
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 | Elements.push_back(Element); |
| 9482 | } |
| 9483 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9484 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 9485 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9486 | // We've finished with this pack expansion. |
| 9487 | continue; |
| 9488 | } |
| 9489 | |
| 9490 | // Transform and check key. |
| 9491 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9492 | if (Key.isInvalid()) |
| 9493 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9494 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9495 | if (Key.get() != OrigElement.Key) |
| 9496 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9497 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9498 | // Transform and check value. |
| 9499 | ExprResult Value |
| 9500 | = getDerived().TransformExpr(OrigElement.Value); |
| 9501 | if (Value.isInvalid()) |
| 9502 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9503 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9504 | if (Value.get() != OrigElement.Value) |
| 9505 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9506 | |
| 9507 | ObjCDictionaryElement Element = { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 9508 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9509 | }; |
| 9510 | Elements.push_back(Element); |
| 9511 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9512 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9513 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 9514 | return SemaRef.MaybeBindToTemporary(E); |
| 9515 | |
| 9516 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 9517 | Elements.data(), |
| 9518 | Elements.size()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9519 | } |
| 9520 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9521 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9522 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9523 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9524 | TypeSourceInfo *EncodedTypeInfo |
| 9525 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 9526 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9527 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9528 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9529 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9530 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9531 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9532 | |
| 9533 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9534 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9535 | E->getRParenLoc()); |
| 9536 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9537 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9538 | template<typename Derived> |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9539 | ExprResult TreeTransform<Derived>:: |
| 9540 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 9541 | // This is a kind of implicit conversion, and it needs to get dropped |
| 9542 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 9543 | // do, as well a more specific one: this expression is only valid when |
| 9544 | // it appears *immediately* as an argument expression. |
| 9545 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9546 | } |
| 9547 | |
| 9548 | template<typename Derived> |
| 9549 | ExprResult TreeTransform<Derived>:: |
| 9550 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9551 | TypeSourceInfo *TSInfo |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9552 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9553 | if (!TSInfo) |
| 9554 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9555 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9556 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9557 | if (Result.isInvalid()) |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9558 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9559 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9560 | if (!getDerived().AlwaysRebuild() && |
| 9561 | TSInfo == E->getTypeInfoAsWritten() && |
| 9562 | Result.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9563 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9564 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9565 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9566 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9567 | Result.get()); |
| 9568 | } |
| 9569 | |
| 9570 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9571 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9572 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9573 | // Transform arguments. |
| 9574 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9575 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9576 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9577 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9578 | &ArgChanged)) |
| 9579 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9580 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9581 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 9582 | // Class message: transform the receiver type. |
| 9583 | TypeSourceInfo *ReceiverTypeInfo |
| 9584 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 9585 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9586 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9587 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9588 | // If nothing changed, just retain the existing message send. |
| 9589 | if (!getDerived().AlwaysRebuild() && |
| 9590 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9591 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9592 | |
| 9593 | // Build a new class message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9594 | SmallVector<SourceLocation, 16> SelLocs; |
| 9595 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9596 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 9597 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9598 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9599 | E->getMethodDecl(), |
| 9600 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9601 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9602 | E->getRightLoc()); |
| 9603 | } |
| 9604 | |
| 9605 | // Instance message: transform the receiver |
| 9606 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 9607 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9608 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9609 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 9610 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9611 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9612 | |
| 9613 | // If nothing changed, just retain the existing message send. |
| 9614 | if (!getDerived().AlwaysRebuild() && |
| 9615 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9616 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9617 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9618 | // Build a new instance message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9619 | SmallVector<SourceLocation, 16> SelLocs; |
| 9620 | E->getSelectorLocs(SelLocs); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9621 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9622 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9623 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9624 | E->getMethodDecl(), |
| 9625 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9626 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9627 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9628 | } |
| 9629 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9630 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9631 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9632 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9633 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9634 | } |
| 9635 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9636 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9637 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9638 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9639 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9640 | } |
| 9641 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9642 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9643 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9644 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9645 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9646 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9647 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9648 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9649 | |
| 9650 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9651 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9652 | // If nothing changed, just retain the existing expression. |
| 9653 | if (!getDerived().AlwaysRebuild() && |
| 9654 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9655 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9656 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9657 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9658 | E->getLocation(), |
| 9659 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9660 | } |
| 9661 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9662 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9663 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9664 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9665 | // 'super' and types never change. Property never changes. Just |
| 9666 | // retain the existing expression. |
| 9667 | if (!E->isObjectReceiver()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9668 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9669 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9670 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9671 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9672 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9673 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9674 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9675 | // We don't need to transform the property; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9676 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9677 | // If nothing changed, just retain the existing expression. |
| 9678 | if (!getDerived().AlwaysRebuild() && |
| 9679 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9680 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9681 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9682 | if (E->isExplicitProperty()) |
| 9683 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 9684 | E->getExplicitProperty(), |
| 9685 | E->getLocation()); |
| 9686 | |
| 9687 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 9688 | SemaRef.Context.PseudoObjectTy, |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9689 | E->getImplicitPropertyGetter(), |
| 9690 | E->getImplicitPropertySetter(), |
| 9691 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9692 | } |
| 9693 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9694 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9695 | ExprResult |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9696 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 9697 | // Transform the base expression. |
| 9698 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 9699 | if (Base.isInvalid()) |
| 9700 | return ExprError(); |
| 9701 | |
| 9702 | // Transform the key expression. |
| 9703 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 9704 | if (Key.isInvalid()) |
| 9705 | return ExprError(); |
| 9706 | |
| 9707 | // If nothing changed, just retain the existing expression. |
| 9708 | if (!getDerived().AlwaysRebuild() && |
| 9709 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9710 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9711 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9712 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9713 | Base.get(), Key.get(), |
| 9714 | E->getAtIndexMethodDecl(), |
| 9715 | E->setAtIndexMethodDecl()); |
| 9716 | } |
| 9717 | |
| 9718 | template<typename Derived> |
| 9719 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9720 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9721 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9722 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9723 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9724 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9725 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9726 | // If nothing changed, just retain the existing expression. |
| 9727 | if (!getDerived().AlwaysRebuild() && |
| 9728 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9729 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9730 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9731 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 9732 | E->getOpLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9733 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9734 | } |
| 9735 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9736 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9737 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9738 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9739 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9740 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9741 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9742 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9743 | SubExprs, &ArgumentChanged)) |
| 9744 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9745 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9746 | if (!getDerived().AlwaysRebuild() && |
| 9747 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9748 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9749 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9750 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9751 | SubExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9752 | E->getRParenLoc()); |
| 9753 | } |
| 9754 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9755 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9756 | ExprResult |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 9757 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 9758 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 9759 | if (SrcExpr.isInvalid()) |
| 9760 | return ExprError(); |
| 9761 | |
| 9762 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9763 | if (!Type) |
| 9764 | return ExprError(); |
| 9765 | |
| 9766 | if (!getDerived().AlwaysRebuild() && |
| 9767 | Type == E->getTypeSourceInfo() && |
| 9768 | SrcExpr.get() == E->getSrcExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9769 | return E; |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 9770 | |
| 9771 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 9772 | SrcExpr.get(), Type, |
| 9773 | E->getRParenLoc()); |
| 9774 | } |
| 9775 | |
| 9776 | template<typename Derived> |
| 9777 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9778 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9779 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9780 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9781 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9782 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 9783 | |
| 9784 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 9785 | blockScope->TheDecl->setBlockMissingReturnType( |
| 9786 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9787 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9788 | SmallVector<ParmVarDecl*, 4> params; |
| 9789 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9790 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 9791 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9792 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 9793 | oldBlock->param_begin(), |
| 9794 | oldBlock->param_size(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9795 | nullptr, paramTypes, ¶ms)) { |
| 9796 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9797 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9798 | } |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9799 | |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9800 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9801 | QualType exprResultType = |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 9802 | getDerived().TransformType(exprFunctionType->getReturnType()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 9803 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9804 | QualType functionType = |
| 9805 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9806 | exprFunctionType->getExtProtoInfo()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9807 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9808 | |
| 9809 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9810 | if (!params.empty()) |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 9811 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9812 | |
| 9813 | if (!oldBlock->blockMissingReturnType()) { |
| 9814 | blockScope->HasImplicitReturnType = false; |
| 9815 | blockScope->ReturnType = exprResultType; |
| 9816 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9817 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9818 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9819 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9820 | if (body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9821 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9822 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9823 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9824 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9825 | #ifndef NDEBUG |
| 9826 | // In builds with assertions, make sure that we captured everything we |
| 9827 | // captured before. |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9828 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 9829 | for (const auto &I : oldBlock->captures()) { |
| 9830 | VarDecl *oldCapture = I.getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9831 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9832 | // Ignore parameter packs. |
| 9833 | if (isa<ParmVarDecl>(oldCapture) && |
| 9834 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 9835 | continue; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9836 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9837 | VarDecl *newCapture = |
| 9838 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 9839 | oldCapture)); |
| 9840 | assert(blockScope->CaptureMap.count(newCapture)); |
| 9841 | } |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 9842 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9843 | } |
| 9844 | #endif |
| 9845 | |
| 9846 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9847 | /*Scope=*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9848 | } |
| 9849 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9850 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9851 | ExprResult |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9852 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 9853 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9854 | } |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9855 | |
| 9856 | template<typename Derived> |
| 9857 | ExprResult |
| 9858 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9859 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 9860 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9861 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9862 | SubExprs.reserve(E->getNumSubExprs()); |
| 9863 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 9864 | SubExprs, &ArgumentChanged)) |
| 9865 | return ExprError(); |
| 9866 | |
| 9867 | if (!getDerived().AlwaysRebuild() && |
| 9868 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9869 | return E; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9870 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9871 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9872 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9873 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9874 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9875 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9876 | // Type reconstruction |
| 9877 | //===----------------------------------------------------------------------===// |
| 9878 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9879 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9880 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 9881 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9882 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9883 | getDerived().getBaseEntity()); |
| 9884 | } |
| 9885 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9886 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9887 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 9888 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9889 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9890 | getDerived().getBaseEntity()); |
| 9891 | } |
| 9892 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9893 | template<typename Derived> |
| 9894 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9895 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 9896 | bool WrittenAsLValue, |
| 9897 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9898 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9899 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9900 | } |
| 9901 | |
| 9902 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9903 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9904 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 9905 | QualType ClassType, |
| 9906 | SourceLocation Sigil) { |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 9907 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 9908 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9909 | } |
| 9910 | |
| 9911 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9912 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9913 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 9914 | ArrayType::ArraySizeModifier SizeMod, |
| 9915 | const llvm::APInt *Size, |
| 9916 | Expr *SizeExpr, |
| 9917 | unsigned IndexTypeQuals, |
| 9918 | SourceRange BracketsRange) { |
| 9919 | if (SizeExpr || !Size) |
| 9920 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 9921 | IndexTypeQuals, BracketsRange, |
| 9922 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9923 | |
| 9924 | QualType Types[] = { |
| 9925 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 9926 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 9927 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9928 | }; |
Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 9929 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9930 | QualType SizeType; |
| 9931 | for (unsigned I = 0; I != NumTypes; ++I) |
| 9932 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 9933 | SizeType = Types[I]; |
| 9934 | break; |
| 9935 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9936 | |
Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 9937 | // Note that we can return a VariableArrayType here in the case where |
| 9938 | // the element type was a dependent VariableArrayType. |
| 9939 | IntegerLiteral *ArraySize |
| 9940 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 9941 | /*FIXME*/BracketsRange.getBegin()); |
| 9942 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9943 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9944 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9945 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9946 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9947 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9948 | QualType |
| 9949 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9950 | ArrayType::ArraySizeModifier SizeMod, |
| 9951 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9952 | unsigned IndexTypeQuals, |
| 9953 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9954 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9955 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9956 | } |
| 9957 | |
| 9958 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9959 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9960 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9961 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9962 | unsigned IndexTypeQuals, |
| 9963 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9964 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9965 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9966 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9967 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9968 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9969 | QualType |
| 9970 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9971 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9972 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9973 | unsigned IndexTypeQuals, |
| 9974 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9975 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9976 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9977 | IndexTypeQuals, BracketsRange); |
| 9978 | } |
| 9979 | |
| 9980 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9981 | QualType |
| 9982 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9983 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9984 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9985 | unsigned IndexTypeQuals, |
| 9986 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9987 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9988 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9989 | IndexTypeQuals, BracketsRange); |
| 9990 | } |
| 9991 | |
| 9992 | template<typename Derived> |
| 9993 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9994 | unsigned NumElements, |
| 9995 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9996 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9997 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9998 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9999 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10000 | template<typename Derived> |
| 10001 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 10002 | unsigned NumElements, |
| 10003 | SourceLocation AttributeLoc) { |
| 10004 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 10005 | NumElements, true); |
| 10006 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 10007 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 10008 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10009 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10010 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10011 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10012 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10013 | QualType |
| 10014 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10015 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10016 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10017 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10018 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10019 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10020 | template<typename Derived> |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 10021 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 10022 | QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 10023 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10024 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 10025 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10026 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 10027 | getDerived().getBaseEntity(), |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10028 | EPI); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10029 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10030 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10031 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 10032 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 10033 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 10034 | } |
| 10035 | |
| 10036 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10037 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 10038 | assert(D && "no decl found"); |
| 10039 | if (D->isInvalidDecl()) return QualType(); |
| 10040 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10041 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10042 | TypeDecl *Ty; |
| 10043 | if (isa<UsingDecl>(D)) { |
| 10044 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 10045 | assert(Using->hasTypename() && |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10046 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 10047 | |
| 10048 | // A valid resolved using typename decl points to exactly one type decl. |
| 10049 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 10050 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10051 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10052 | } else { |
| 10053 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 10054 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 10055 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 10056 | } |
| 10057 | |
| 10058 | return SemaRef.Context.getTypeDeclType(Ty); |
| 10059 | } |
| 10060 | |
| 10061 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 10062 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 10063 | SourceLocation Loc) { |
| 10064 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10065 | } |
| 10066 | |
| 10067 | template<typename Derived> |
| 10068 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 10069 | return SemaRef.Context.getTypeOfType(Underlying); |
| 10070 | } |
| 10071 | |
| 10072 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 10073 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 10074 | SourceLocation Loc) { |
| 10075 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10076 | } |
| 10077 | |
| 10078 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 10079 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 10080 | UnaryTransformType::UTTKind UKind, |
| 10081 | SourceLocation Loc) { |
| 10082 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 10083 | } |
| 10084 | |
| 10085 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10086 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 10087 | TemplateName Template, |
| 10088 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 10089 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 10090 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10091 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10092 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 10093 | template<typename Derived> |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 10094 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 10095 | SourceLocation KWLoc) { |
| 10096 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 10097 | } |
| 10098 | |
| 10099 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10100 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10101 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10102 | bool TemplateKW, |
| 10103 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10104 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10105 | Template); |
| 10106 | } |
| 10107 | |
| 10108 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10109 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10110 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 10111 | const IdentifierInfo &Name, |
| 10112 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10113 | QualType ObjectType, |
| 10114 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10115 | UnqualifiedId TemplateName; |
| 10116 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10117 | Sema::TemplateTy Template; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10118 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10119 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10120 | SS, TemplateKWLoc, TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10121 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10122 | /*EnteringContext=*/false, |
| 10123 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10124 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10126 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10127 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10128 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10129 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10130 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10131 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10132 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10133 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10134 | // FIXME: Bogus location information. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10135 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10136 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10137 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10138 | Sema::TemplateTy Template; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10139 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10140 | SS, TemplateKWLoc, Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10141 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10142 | /*EnteringContext=*/false, |
| 10143 | Template); |
Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 10144 | return Template.get(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10145 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10146 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10147 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10148 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10149 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 10150 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10151 | Expr *OrigCallee, |
| 10152 | Expr *First, |
| 10153 | Expr *Second) { |
| 10154 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 10155 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10156 | |
Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 10157 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 10158 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 10159 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 10160 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 10161 | First, Second); |
| 10162 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 10163 | if (Result.isInvalid()) |
| 10164 | return ExprError(); |
| 10165 | First = Result.get(); |
| 10166 | } |
| 10167 | |
| 10168 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 10169 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 10170 | if (Result.isInvalid()) |
| 10171 | return ExprError(); |
| 10172 | Second = Result.get(); |
| 10173 | } |
| 10174 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10175 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 10176 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10177 | if (!First->getType()->isOverloadableType() && |
| 10178 | !Second->getType()->isOverloadableType()) |
| 10179 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 10180 | Callee->getLocStart(), |
| 10181 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 10182 | } else if (Op == OO_Arrow) { |
| 10183 | // -> is never a builtin operation. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10184 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 10185 | } else if (Second == nullptr || isPostIncDec) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10186 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10187 | // The argument is not of overloadable type, so try to create a |
| 10188 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10189 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10190 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10191 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10192 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10193 | } |
| 10194 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10195 | if (!First->getType()->isOverloadableType() && |
| 10196 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10197 | // Neither of the arguments is an overloadable type, so try to |
| 10198 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10199 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10200 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10201 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10202 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10203 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10204 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10205 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10206 | } |
| 10207 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10208 | |
| 10209 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10210 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 10211 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10212 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10213 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10214 | assert(ULE->requiresADL()); |
Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 10215 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10216 | } else { |
Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 10217 | // If we've resolved this to a particular non-member function, just call |
| 10218 | // that function. If we resolved it to a member function, |
| 10219 | // CreateOverloaded* will find that function for us. |
| 10220 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 10221 | if (!isa<CXXMethodDecl>(ND)) |
| 10222 | Functions.addDecl(ND); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10223 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10224 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10225 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10226 | Expr *Args[2] = { First, Second }; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10227 | unsigned NumArgs = 1 + (Second != nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10228 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10229 | // Create the overloaded operator invocation for unary operators. |
| 10230 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10231 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10232 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10233 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10234 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10235 | |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 10236 | if (Op == OO_Subscript) { |
| 10237 | SourceLocation LBrace; |
| 10238 | SourceLocation RBrace; |
| 10239 | |
| 10240 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 10241 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 10242 | LBrace = SourceLocation::getFromRawEncoding( |
| 10243 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 10244 | RBrace = SourceLocation::getFromRawEncoding( |
| 10245 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 10246 | } else { |
| 10247 | LBrace = Callee->getLocStart(); |
| 10248 | RBrace = OpLoc; |
| 10249 | } |
| 10250 | |
| 10251 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 10252 | First, Second); |
| 10253 | } |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 10254 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10255 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10256 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10257 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10258 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 10259 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10260 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10261 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10262 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10264 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10265 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10266 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10267 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10268 | SourceLocation OperatorLoc, |
| 10269 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10270 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10271 | TypeSourceInfo *ScopeType, |
| 10272 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10273 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10274 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10275 | QualType BaseType = Base->getType(); |
| 10276 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10277 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10278 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 10279 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 10280 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10281 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10282 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10283 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10284 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10285 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10286 | /*FIXME?*/true); |
| 10287 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10288 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10289 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10290 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 10291 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 10292 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 10293 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 10294 | |
Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 10295 | // The scope type is now known to be a valid nested name specifier |
| 10296 | // component. Tack it on to the end of the nested name specifier. |
| 10297 | if (ScopeType) |
| 10298 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 10299 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10300 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10301 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10302 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10303 | OperatorLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10304 | SS, TemplateKWLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10305 | /*FIXME: FirstQualifier*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10306 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10307 | /*TemplateArgs*/ nullptr); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10308 | } |
| 10309 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 10310 | template<typename Derived> |
| 10311 | StmtResult |
| 10312 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 10313 | SourceLocation Loc = S->getLocStart(); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 10314 | CapturedDecl *CD = S->getCapturedDecl(); |
| 10315 | unsigned NumParams = CD->getNumParams(); |
| 10316 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 10317 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 10318 | for (unsigned I = 0; I < NumParams; ++I) { |
| 10319 | if (I != ContextParamPos) { |
| 10320 | Params.push_back( |
| 10321 | std::make_pair( |
| 10322 | CD->getParam(I)->getName(), |
| 10323 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 10324 | } else { |
| 10325 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 10326 | } |
| 10327 | } |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10328 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 10329 | S->getCapturedRegionKind(), Params); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10330 | StmtResult Body; |
| 10331 | { |
| 10332 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 10333 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 10334 | } |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 10335 | |
| 10336 | if (Body.isInvalid()) { |
| 10337 | getSema().ActOnCapturedRegionError(); |
| 10338 | return StmtError(); |
| 10339 | } |
| 10340 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 10341 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 10342 | } |
| 10343 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10344 | } // end namespace clang |
| 10345 | |
| 10346 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |