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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 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 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 330 | /// \brief Transform the given attribute. |
| 331 | /// |
| 332 | /// By default, this routine transforms a statement by delegating to the |
| 333 | /// appropriate TransformXXXAttr function to transform a specific kind |
| 334 | /// of attribute. Subclasses may override this function to transform |
| 335 | /// attributed statements using some other mechanism. |
| 336 | /// |
| 337 | /// \returns the transformed attribute |
| 338 | const Attr *TransformAttr(const Attr *S); |
| 339 | |
| 340 | /// \brief Transform the specified attribute. |
| 341 | /// |
| 342 | /// Subclasses should override the transformation of attributes with a pragma |
| 343 | /// spelling to transform expressions stored within the attribute. |
| 344 | /// |
| 345 | /// \returns the transformed attribute. |
| 346 | #define ATTR(X) |
| 347 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 348 | const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } |
| 349 | #include "clang/Basic/AttrList.inc" |
| 350 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 351 | /// \brief Transform the given expression. |
| 352 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 353 | /// By default, this routine transforms an expression by delegating to the |
| 354 | /// appropriate TransformXXXExpr function to build a new expression. |
| 355 | /// Subclasses may override this function to transform expressions using some |
| 356 | /// other mechanism. |
| 357 | /// |
| 358 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 359 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 361 | /// \brief Transform the given initializer. |
| 362 | /// |
| 363 | /// By default, this routine transforms an initializer by stripping off the |
| 364 | /// semantic nodes added by initialization, then passing the result to |
| 365 | /// TransformExpr or TransformExprs. |
| 366 | /// |
| 367 | /// \returns the transformed initializer. |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 368 | ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 369 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 370 | /// \brief Transform the given list of expressions. |
| 371 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 372 | /// This routine transforms a list of expressions by invoking |
| 373 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 374 | /// support for variadic templates by expanding any pack expansions (if the |
| 375 | /// derived class permits such expansion) along the way. When pack expansions |
| 376 | /// are present, the number of outputs may not equal the number of inputs. |
| 377 | /// |
| 378 | /// \param Inputs The set of expressions to be transformed. |
| 379 | /// |
| 380 | /// \param NumInputs The number of expressions in \c Inputs. |
| 381 | /// |
| 382 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 383 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 384 | /// be. |
| 385 | /// |
| 386 | /// \param Outputs The transformed input expressions will be added to this |
| 387 | /// vector. |
| 388 | /// |
| 389 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 390 | /// due to transformation. |
| 391 | /// |
| 392 | /// \returns true if an error occurred, false otherwise. |
| 393 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 394 | SmallVectorImpl<Expr *> &Outputs, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 395 | bool *ArgChanged = nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 396 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 397 | /// \brief Transform the given declaration, which is referenced from a type |
| 398 | /// or expression. |
| 399 | /// |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 400 | /// By default, acts as the identity function on declarations, unless the |
| 401 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 402 | /// may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 403 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 404 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 405 | = TransformedLocalDecls.find(D); |
| 406 | if (Known != TransformedLocalDecls.end()) |
| 407 | return Known->second; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 408 | |
| 409 | return D; |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 410 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 411 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 412 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 413 | /// place them on the new declaration. |
| 414 | /// |
| 415 | /// By default, this operation does nothing. Subclasses may override this |
| 416 | /// behavior to transform attributes. |
| 417 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 418 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 419 | /// \brief Note that a local declaration has been transformed by this |
| 420 | /// transformer. |
| 421 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 422 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 423 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 424 | /// the transformer itself has to transform the declarations. This routine |
| 425 | /// can be overridden by a subclass that keeps track of such mappings. |
| 426 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 427 | TransformedLocalDecls[Old] = New; |
| 428 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 429 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 430 | /// \brief Transform the definition of the given declaration. |
| 431 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 433 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 434 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 435 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 438 | /// \brief Transform the given declaration, which was the first part of a |
| 439 | /// nested-name-specifier in a member access expression. |
| 440 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 441 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 442 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 443 | /// the \c T in \c x->T::member |
| 444 | /// |
| 445 | /// By default, invokes TransformDecl() to transform the declaration. |
| 446 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 447 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 448 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 449 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 451 | /// \brief Transform the given nested-name-specifier with source-location |
| 452 | /// information. |
| 453 | /// |
| 454 | /// By default, transforms all of the types and declarations within the |
| 455 | /// nested-name-specifier. Subclasses may override this function to provide |
| 456 | /// alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 457 | NestedNameSpecifierLoc |
| 458 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 459 | QualType ObjectType = QualType(), |
| 460 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 461 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 462 | /// \brief Transform the given declaration name. |
| 463 | /// |
| 464 | /// By default, transforms the types of conversion function, constructor, |
| 465 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 466 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 467 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 468 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 469 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 470 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 471 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | /// |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 473 | /// \param SS The nested-name-specifier that qualifies the template |
| 474 | /// name. This nested-name-specifier must already have been transformed. |
| 475 | /// |
| 476 | /// \param Name The template name to transform. |
| 477 | /// |
| 478 | /// \param NameLoc The source location of the template name. |
| 479 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 480 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 481 | /// access expression, this is the type of the object whose member template |
| 482 | /// is being referenced. |
| 483 | /// |
| 484 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 485 | /// also refers to a name within the current (lexical) scope, this is the |
| 486 | /// declaration it refers to. |
| 487 | /// |
| 488 | /// By default, transforms the template name by transforming the declarations |
| 489 | /// and nested-name-specifiers that occur within the template name. |
| 490 | /// Subclasses may override this function to provide alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 491 | TemplateName |
| 492 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 493 | SourceLocation NameLoc, |
| 494 | QualType ObjectType = QualType(), |
| 495 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 496 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 497 | /// \brief Transform the given template argument. |
| 498 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | /// By default, this operation transforms the type, expression, or |
| 500 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 501 | /// new template argument from the transformed result. Subclasses may |
| 502 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 503 | /// |
| 504 | /// Returns true if there was an error. |
| 505 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 506 | TemplateArgumentLoc &Output); |
| 507 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 508 | /// \brief Transform the given set of template arguments. |
| 509 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 510 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 511 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 512 | /// the transformed arguments to the output list. |
| 513 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 514 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 515 | /// a convenience function. Subclasses that wish to override this behavior |
| 516 | /// should override the iterator-based member template version. |
| 517 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 518 | /// \param Inputs The set of template arguments to be transformed. |
| 519 | /// |
| 520 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 521 | /// |
| 522 | /// \param Outputs The set of transformed template arguments output by this |
| 523 | /// routine. |
| 524 | /// |
| 525 | /// Returns true if an error occurred. |
| 526 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 527 | unsigned NumInputs, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 528 | TemplateArgumentListInfo &Outputs) { |
| 529 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 530 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 531 | |
| 532 | /// \brief Transform the given set of template arguments. |
| 533 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 534 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 535 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 536 | /// the transformed arguments to the output list. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 537 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 538 | /// \param First An iterator to the first template argument. |
| 539 | /// |
| 540 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 541 | /// |
| 542 | /// \param Outputs The set of transformed template arguments output by this |
| 543 | /// routine. |
| 544 | /// |
| 545 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 546 | template<typename InputIterator> |
| 547 | bool TransformTemplateArguments(InputIterator First, |
| 548 | InputIterator Last, |
| 549 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 550 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 551 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 552 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 553 | TemplateArgumentLoc &ArgLoc); |
| 554 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 555 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 556 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 557 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 558 | getDerived().getBaseLocation()); |
| 559 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 560 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 561 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 562 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 563 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 564 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 565 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 566 | template<typename Fn> |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 567 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 568 | FunctionProtoTypeLoc TL, |
| 569 | CXXRecordDecl *ThisContext, |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 570 | unsigned ThisTypeQuals, |
| 571 | Fn TransformExceptionSpec); |
| 572 | |
| 573 | bool TransformExceptionSpec(SourceLocation Loc, |
| 574 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 575 | SmallVectorImpl<QualType> &Exceptions, |
| 576 | bool &Changed); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 577 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 578 | StmtResult TransformSEHHandler(Stmt *Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 579 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 580 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 581 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 582 | TemplateSpecializationTypeLoc TL, |
| 583 | TemplateName Template); |
| 584 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 585 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 586 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 587 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 588 | TemplateName Template, |
| 589 | CXXScopeSpec &SS); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 590 | |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 591 | QualType TransformDependentTemplateSpecializationType( |
| 592 | TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, |
| 593 | NestedNameSpecifierLoc QualifierLoc); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 594 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 595 | /// \brief Transforms the parameters of a function type into the |
| 596 | /// given vectors. |
| 597 | /// |
| 598 | /// The result vectors should be kept in sync; null entries in the |
| 599 | /// variables vector are acceptable. |
| 600 | /// |
| 601 | /// Return true on error. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 602 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 603 | ParmVarDecl **Params, unsigned NumParams, |
| 604 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 605 | SmallVectorImpl<QualType> &PTypes, |
| 606 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 607 | |
| 608 | /// \brief Transforms a single function-type parameter. Return null |
| 609 | /// on error. |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 610 | /// |
| 611 | /// \param indexAdjustment - A number to add to the parameter's |
| 612 | /// scope index; can be negative |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 613 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 614 | int indexAdjustment, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 615 | Optional<unsigned> NumExpansions, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 616 | bool ExpectParameterPack); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 617 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 618 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 619 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 620 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 621 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 622 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 623 | TemplateParameterList *TransformTemplateParameterList( |
| 624 | TemplateParameterList *TPL) { |
| 625 | return TPL; |
| 626 | } |
| 627 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 628 | ExprResult TransformAddressOfOperand(Expr *E); |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 629 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 630 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 631 | bool IsAddressOfOperand, |
| 632 | TypeSourceInfo **RecoveryTSI); |
| 633 | |
| 634 | ExprResult TransformParenDependentScopeDeclRefExpr( |
| 635 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 636 | TypeSourceInfo **RecoveryTSI); |
| 637 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 638 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 639 | |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 640 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 641 | // amount of stack usage with clang. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 642 | #define STMT(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 643 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 644 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 645 | #define EXPR(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 646 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 647 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 648 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 649 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 651 | #define OPENMP_CLAUSE(Name, Class) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 652 | LLVM_ATTRIBUTE_NOINLINE \ |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 653 | OMPClause *Transform ## Class(Class *S); |
| 654 | #include "clang/Basic/OpenMPKinds.def" |
| 655 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 656 | /// \brief Build a new pointer type given its pointee type. |
| 657 | /// |
| 658 | /// By default, performs semantic analysis when building the pointer type. |
| 659 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 660 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 661 | |
| 662 | /// \brief Build a new block pointer type given its pointee type. |
| 663 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 665 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 666 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 667 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 668 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 669 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 670 | /// By default, performs semantic analysis when building the |
| 671 | /// reference type. Subclasses may override this routine to provide |
| 672 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 673 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 674 | /// \param LValue whether the type was written with an lvalue sigil |
| 675 | /// or an rvalue sigil. |
| 676 | QualType RebuildReferenceType(QualType ReferentType, |
| 677 | bool LValue, |
| 678 | SourceLocation Sigil); |
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 member pointer type given the pointee type and the |
| 681 | /// class type it refers into. |
| 682 | /// |
| 683 | /// By default, performs semantic analysis when building the member pointer |
| 684 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 685 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 686 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 688 | /// \brief Build an Objective-C object type. |
| 689 | /// |
| 690 | /// By default, performs semantic analysis when building the object type. |
| 691 | /// Subclasses may override this routine to provide different behavior. |
| 692 | QualType RebuildObjCObjectType(QualType BaseType, |
| 693 | SourceLocation Loc, |
| 694 | SourceLocation TypeArgsLAngleLoc, |
| 695 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 696 | SourceLocation TypeArgsRAngleLoc, |
| 697 | SourceLocation ProtocolLAngleLoc, |
| 698 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 699 | ArrayRef<SourceLocation> ProtocolLocs, |
| 700 | SourceLocation ProtocolRAngleLoc); |
| 701 | |
| 702 | /// \brief Build a new Objective-C object pointer type given the pointee type. |
| 703 | /// |
| 704 | /// By default, directly builds the pointer type, with no additional semantic |
| 705 | /// analysis. |
| 706 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 707 | SourceLocation Star); |
| 708 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 709 | /// \brief Build a new array type given the element type, size |
| 710 | /// modifier, size of the array (if known), size expression, and index type |
| 711 | /// qualifiers. |
| 712 | /// |
| 713 | /// By default, performs semantic analysis when building the array type. |
| 714 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 716 | QualType RebuildArrayType(QualType ElementType, |
| 717 | ArrayType::ArraySizeModifier SizeMod, |
| 718 | const llvm::APInt *Size, |
| 719 | Expr *SizeExpr, |
| 720 | unsigned IndexTypeQuals, |
| 721 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 723 | /// \brief Build a new constant array type given the element type, size |
| 724 | /// modifier, (known) size of the array, and index type qualifiers. |
| 725 | /// |
| 726 | /// By default, performs semantic analysis when building the array type. |
| 727 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 729 | ArrayType::ArraySizeModifier SizeMod, |
| 730 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 731 | unsigned IndexTypeQuals, |
| 732 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 733 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 734 | /// \brief Build a new incomplete array type given the element type, size |
| 735 | /// modifier, and index type qualifiers. |
| 736 | /// |
| 737 | /// By default, performs semantic analysis when building the array type. |
| 738 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 740 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 741 | unsigned IndexTypeQuals, |
| 742 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 743 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 744 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 745 | /// size modifier, size expression, and index type qualifiers. |
| 746 | /// |
| 747 | /// By default, performs semantic analysis when building the array type. |
| 748 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 750 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 751 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 752 | unsigned IndexTypeQuals, |
| 753 | SourceRange BracketsRange); |
| 754 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 755 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 756 | /// size modifier, size expression, and index type qualifiers. |
| 757 | /// |
| 758 | /// By default, performs semantic analysis when building the array type. |
| 759 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 761 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 762 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 763 | unsigned IndexTypeQuals, |
| 764 | SourceRange BracketsRange); |
| 765 | |
| 766 | /// \brief Build a new vector type given the element type and |
| 767 | /// number of elements. |
| 768 | /// |
| 769 | /// By default, performs semantic analysis when building the vector type. |
| 770 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 771 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 772 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 773 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 774 | /// \brief Build a new extended vector type given the element type and |
| 775 | /// number of elements. |
| 776 | /// |
| 777 | /// By default, performs semantic analysis when building the vector type. |
| 778 | /// Subclasses may override this routine to provide different behavior. |
| 779 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 780 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 781 | |
| 782 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 783 | /// given the element type and number of elements. |
| 784 | /// |
| 785 | /// By default, performs semantic analysis when building the vector type. |
| 786 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 787 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 788 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 789 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 791 | /// \brief Build a new function type. |
| 792 | /// |
| 793 | /// By default, performs semantic analysis when building the function type. |
| 794 | /// Subclasses may override this routine to provide different behavior. |
| 795 | QualType RebuildFunctionProtoType(QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 796 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 797 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 799 | /// \brief Build a new unprototyped function type. |
| 800 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 801 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 802 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 803 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 804 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 805 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 806 | /// \brief Build a new typedef type. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 807 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 808 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 809 | } |
| 810 | |
| 811 | /// \brief Build a new class/struct/union type. |
| 812 | QualType RebuildRecordType(RecordDecl *Record) { |
| 813 | return SemaRef.Context.getTypeDeclType(Record); |
| 814 | } |
| 815 | |
| 816 | /// \brief Build a new Enum type. |
| 817 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 818 | return SemaRef.Context.getTypeDeclType(Enum); |
| 819 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 820 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 821 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 822 | /// |
| 823 | /// By default, performs semantic analysis when building the typeof type. |
| 824 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 825 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 826 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 828 | /// |
| 829 | /// By default, builds a new TypeOfType with the given underlying type. |
| 830 | QualType RebuildTypeOfType(QualType Underlying); |
| 831 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 832 | /// \brief Build a new unary transform type. |
| 833 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 834 | UnaryTransformType::UTTKind UKind, |
| 835 | SourceLocation Loc); |
| 836 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 837 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 838 | /// |
| 839 | /// By default, performs semantic analysis when building the decltype type. |
| 840 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 841 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 843 | /// \brief Build a new C++11 auto type. |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 844 | /// |
| 845 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 846 | QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) { |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 847 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 848 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 849 | // that we'll retry deduction after the transformation. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 850 | return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto, |
| 851 | /*IsDependent*/ false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 854 | /// \brief Build a new template specialization type. |
| 855 | /// |
| 856 | /// By default, performs semantic analysis when building the template |
| 857 | /// specialization type. Subclasses may override this routine to provide |
| 858 | /// different behavior. |
| 859 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 860 | SourceLocation TemplateLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 861 | TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 863 | /// \brief Build a new parenthesized type. |
| 864 | /// |
| 865 | /// By default, builds a new ParenType type from the inner type. |
| 866 | /// Subclasses may override this routine to provide different behavior. |
| 867 | QualType RebuildParenType(QualType InnerType) { |
| 868 | return SemaRef.Context.getParenType(InnerType); |
| 869 | } |
| 870 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 871 | /// \brief Build a new qualified name type. |
| 872 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 873 | /// By default, builds a new ElaboratedType type from the keyword, |
| 874 | /// the nested-name-specifier and the named type. |
| 875 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 876 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 877 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 878 | NestedNameSpecifierLoc QualifierLoc, |
| 879 | QualType Named) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 880 | return SemaRef.Context.getElaboratedType(Keyword, |
| 881 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 882 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 883 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 884 | |
| 885 | /// \brief Build a new typename type that refers to a template-id. |
| 886 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 887 | /// By default, builds a new DependentNameType type from the |
| 888 | /// nested-name-specifier and the given type. Subclasses may override |
| 889 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 890 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 891 | ElaboratedTypeKeyword Keyword, |
| 892 | NestedNameSpecifierLoc QualifierLoc, |
| 893 | const IdentifierInfo *Name, |
| 894 | SourceLocation NameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 895 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 896 | // Rebuild the template name. |
| 897 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 898 | CXXScopeSpec SS; |
| 899 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 900 | TemplateName InstName |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 901 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), |
| 902 | nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 903 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 904 | if (InstName.isNull()) |
| 905 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 906 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 907 | // If it's still dependent, make a dependent specialization. |
| 908 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 909 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 910 | QualifierLoc.getNestedNameSpecifier(), |
| 911 | Name, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 912 | Args); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 913 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 914 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 915 | // specialization. |
| 916 | QualType T = |
| 917 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 918 | if (T.isNull()) return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 919 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 920 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 921 | return T; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 922 | |
| 923 | return SemaRef.Context.getElaboratedType(Keyword, |
| 924 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 925 | T); |
| 926 | } |
| 927 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 928 | /// \brief Build a new typename type that refers to an identifier. |
| 929 | /// |
| 930 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 931 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 932 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 933 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 934 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 935 | NestedNameSpecifierLoc QualifierLoc, |
| 936 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 937 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 938 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 939 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 940 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 941 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 942 | // If the name is still dependent, just build a new dependent name type. |
| 943 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 944 | return SemaRef.Context.getDependentNameType(Keyword, |
| 945 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 946 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 947 | } |
| 948 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 949 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 950 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 951 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 952 | |
| 953 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 954 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 955 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 956 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 957 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 958 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 959 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 960 | if (!DC) |
| 961 | return QualType(); |
| 962 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 963 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 964 | return QualType(); |
| 965 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 966 | TagDecl *Tag = nullptr; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 967 | SemaRef.LookupQualifiedName(Result, DC); |
| 968 | switch (Result.getResultKind()) { |
| 969 | case LookupResult::NotFound: |
| 970 | case LookupResult::NotFoundInCurrentInstantiation: |
| 971 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 972 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 973 | case LookupResult::Found: |
| 974 | Tag = Result.getAsSingle<TagDecl>(); |
| 975 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 976 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 977 | case LookupResult::FoundOverloaded: |
| 978 | case LookupResult::FoundUnresolvedValue: |
| 979 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 980 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 981 | case LookupResult::Ambiguous: |
| 982 | // Let the LookupResult structure handle ambiguities. |
| 983 | return QualType(); |
| 984 | } |
| 985 | |
| 986 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 987 | // Check where the name exists but isn't a tag type and use that to emit |
| 988 | // better diagnostics. |
| 989 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 990 | SemaRef.LookupQualifiedName(Result, DC); |
| 991 | switch (Result.getResultKind()) { |
| 992 | case LookupResult::Found: |
| 993 | case LookupResult::FoundOverloaded: |
| 994 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 995 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 996 | unsigned Kind = 0; |
| 997 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 998 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 999 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1000 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 1001 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 1002 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1003 | } |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1004 | default: |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1005 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Stephan Tolksdorf | eb7708d | 2014-03-13 20:34:03 +0000 | [diff] [blame] | 1006 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1007 | break; |
| 1008 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1009 | return QualType(); |
| 1010 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1011 | |
Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 1012 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
Justin Bogner | c6ecb7c | 2015-07-10 23:05:47 +0000 | [diff] [blame] | 1013 | IdLoc, Id)) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1014 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1015 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 1016 | return QualType(); |
| 1017 | } |
| 1018 | |
| 1019 | // Build the elaborated-type-specifier type. |
| 1020 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1021 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1022 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1023 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1024 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1025 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1026 | /// \brief Build a new pack expansion type. |
| 1027 | /// |
| 1028 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 1029 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1030 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1031 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1032 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1033 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1034 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 1035 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1038 | /// \brief Build a new atomic type given its value type. |
| 1039 | /// |
| 1040 | /// By default, performs semantic analysis when building the atomic type. |
| 1041 | /// Subclasses may override this routine to provide different behavior. |
| 1042 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1043 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1044 | /// \brief Build a new template name given a nested name specifier, a flag |
| 1045 | /// indicating whether the "template" keyword was provided, and the template |
| 1046 | /// that the template name refers to. |
| 1047 | /// |
| 1048 | /// By default, builds the new template name directly. Subclasses may override |
| 1049 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1050 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1051 | bool TemplateKW, |
| 1052 | TemplateDecl *Template); |
| 1053 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1054 | /// \brief Build a new template name given a nested name specifier and the |
| 1055 | /// name that is referred to as a template. |
| 1056 | /// |
| 1057 | /// By default, performs semantic analysis to determine whether the name can |
| 1058 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1059 | /// template name. Subclasses may override this routine to provide different |
| 1060 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1061 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1062 | const IdentifierInfo &Name, |
| 1063 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1064 | QualType ObjectType, |
| 1065 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1067 | /// \brief Build a new template name given a nested name specifier and the |
| 1068 | /// overloaded operator name that is referred to as a template. |
| 1069 | /// |
| 1070 | /// By default, performs semantic analysis to determine whether the name can |
| 1071 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1072 | /// template name. Subclasses may override this routine to provide different |
| 1073 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1074 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1075 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1076 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1077 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1078 | |
| 1079 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1080 | /// and the |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1081 | /// |
| 1082 | /// By default, performs semantic analysis to determine whether the name can |
| 1083 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1084 | /// template name. Subclasses may override this routine to provide different |
| 1085 | /// behavior. |
| 1086 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1087 | const TemplateArgument &ArgPack) { |
| 1088 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1089 | } |
| 1090 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1091 | /// \brief Build a new compound statement. |
| 1092 | /// |
| 1093 | /// By default, performs semantic analysis to build the new statement. |
| 1094 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1095 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1096 | MultiStmtArg Statements, |
| 1097 | SourceLocation RBraceLoc, |
| 1098 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1099 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1100 | IsStmtExpr); |
| 1101 | } |
| 1102 | |
| 1103 | /// \brief Build a new case statement. |
| 1104 | /// |
| 1105 | /// By default, performs semantic analysis to build the new statement. |
| 1106 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1107 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1108 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1109 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1110 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1111 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1112 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1113 | ColonLoc); |
| 1114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1116 | /// \brief Attach the body to a new case statement. |
| 1117 | /// |
| 1118 | /// By default, performs semantic analysis to build the new statement. |
| 1119 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1120 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1121 | getSema().ActOnCaseStmtBody(S, Body); |
| 1122 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1123 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1125 | /// \brief Build a new default statement. |
| 1126 | /// |
| 1127 | /// By default, performs semantic analysis to build the new statement. |
| 1128 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1129 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1130 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1131 | Stmt *SubStmt) { |
| 1132 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1133 | /*CurScope=*/nullptr); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1136 | /// \brief Build a new label statement. |
| 1137 | /// |
| 1138 | /// By default, performs semantic analysis to build the new statement. |
| 1139 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1140 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1141 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1142 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1143 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1145 | /// \brief Build a new label statement. |
| 1146 | /// |
| 1147 | /// By default, performs semantic analysis to build the new statement. |
| 1148 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1149 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1150 | ArrayRef<const Attr*> Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1151 | Stmt *SubStmt) { |
| 1152 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1153 | } |
| 1154 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1155 | /// \brief Build a new "if" statement. |
| 1156 | /// |
| 1157 | /// By default, performs semantic analysis to build the new statement. |
| 1158 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1159 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1160 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1161 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1162 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1165 | /// \brief Start building a new switch statement. |
| 1166 | /// |
| 1167 | /// By default, performs semantic analysis to build the new statement. |
| 1168 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1169 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1170 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1171 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1172 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1173 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1174 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1175 | /// \brief Attach the body to the switch statement. |
| 1176 | /// |
| 1177 | /// By default, performs semantic analysis to build the new statement. |
| 1178 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1179 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1180 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1181 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /// \brief Build a new while statement. |
| 1185 | /// |
| 1186 | /// By default, performs semantic analysis to build the new statement. |
| 1187 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1188 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1189 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1190 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1191 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1193 | /// \brief Build a new do-while statement. |
| 1194 | /// |
| 1195 | /// By default, performs semantic analysis to build the new statement. |
| 1196 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1197 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1198 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1199 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1200 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1201 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /// \brief Build a new for statement. |
| 1205 | /// |
| 1206 | /// By default, performs semantic analysis to build the new statement. |
| 1207 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1208 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1209 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1210 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1211 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1212 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1213 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1214 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1216 | /// \brief Build a new goto statement. |
| 1217 | /// |
| 1218 | /// By default, performs semantic analysis to build the new statement. |
| 1219 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1220 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1221 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1222 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | /// \brief Build a new indirect goto statement. |
| 1226 | /// |
| 1227 | /// By default, performs semantic analysis to build the new statement. |
| 1228 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1229 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1230 | SourceLocation StarLoc, |
| 1231 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1232 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1233 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1234 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1235 | /// \brief Build a new return statement. |
| 1236 | /// |
| 1237 | /// By default, performs semantic analysis to build the new statement. |
| 1238 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1239 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
Nick Lewycky | d78f92f | 2014-05-03 00:41:18 +0000 | [diff] [blame] | 1240 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1241 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1243 | /// \brief Build a new declaration statement. |
| 1244 | /// |
| 1245 | /// By default, performs semantic analysis to build the new statement. |
| 1246 | /// Subclasses may override this routine to provide different behavior. |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 1247 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1248 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1249 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1250 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1251 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1252 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1253 | /// \brief Build a new inline asm statement. |
| 1254 | /// |
| 1255 | /// By default, performs semantic analysis to build the new statement. |
| 1256 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1257 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1258 | bool IsVolatile, unsigned NumOutputs, |
| 1259 | unsigned NumInputs, IdentifierInfo **Names, |
| 1260 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1261 | Expr *AsmString, MultiExprArg Clobbers, |
| 1262 | SourceLocation RParenLoc) { |
| 1263 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1264 | NumInputs, Names, Constraints, Exprs, |
| 1265 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1266 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1267 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1268 | /// \brief Build a new MS style inline asm statement. |
| 1269 | /// |
| 1270 | /// By default, performs semantic analysis to build the new statement. |
| 1271 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1272 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1273 | ArrayRef<Token> AsmToks, |
| 1274 | StringRef AsmString, |
| 1275 | unsigned NumOutputs, unsigned NumInputs, |
| 1276 | ArrayRef<StringRef> Constraints, |
| 1277 | ArrayRef<StringRef> Clobbers, |
| 1278 | ArrayRef<Expr*> Exprs, |
| 1279 | SourceLocation EndLoc) { |
| 1280 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1281 | NumOutputs, NumInputs, |
| 1282 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1285 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1286 | /// |
| 1287 | /// By default, performs semantic analysis to build the new statement. |
| 1288 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1289 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1290 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1291 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1292 | Stmt *Finally) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1293 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1294 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1297 | /// \brief Rebuild an Objective-C exception declaration. |
| 1298 | /// |
| 1299 | /// By default, performs semantic analysis to build the new declaration. |
| 1300 | /// Subclasses may override this routine to provide different behavior. |
| 1301 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1302 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1303 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1304 | ExceptionDecl->getInnerLocStart(), |
| 1305 | ExceptionDecl->getLocation(), |
| 1306 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1307 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1308 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1309 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1310 | /// |
| 1311 | /// By default, performs semantic analysis to build the new statement. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1313 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1314 | SourceLocation RParenLoc, |
| 1315 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1316 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1317 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1318 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1319 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1320 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1321 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1322 | /// |
| 1323 | /// By default, performs semantic analysis to build the new statement. |
| 1324 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1325 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1326 | Stmt *Body) { |
| 1327 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1328 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1329 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1330 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1331 | /// |
| 1332 | /// By default, performs semantic analysis to build the new statement. |
| 1333 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1334 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1335 | Expr *Operand) { |
| 1336 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1337 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1338 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1339 | /// \brief Build a new OpenMP executable directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1340 | /// |
| 1341 | /// By default, performs semantic analysis to build the new statement. |
| 1342 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1343 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1344 | DeclarationNameInfo DirName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1345 | OpenMPDirectiveKind CancelRegion, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1346 | ArrayRef<OMPClause *> Clauses, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1347 | Stmt *AStmt, SourceLocation StartLoc, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1348 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1349 | return getSema().ActOnOpenMPExecutableDirective( |
| 1350 | Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1353 | /// \brief Build a new OpenMP 'if' clause. |
| 1354 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1355 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1356 | /// Subclasses may override this routine to provide different behavior. |
| 1357 | OMPClause *RebuildOMPIfClause(Expr *Condition, |
| 1358 | SourceLocation StartLoc, |
| 1359 | SourceLocation LParenLoc, |
| 1360 | SourceLocation EndLoc) { |
| 1361 | return getSema().ActOnOpenMPIfClause(Condition, StartLoc, |
| 1362 | LParenLoc, EndLoc); |
| 1363 | } |
| 1364 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1365 | /// \brief Build a new OpenMP 'final' clause. |
| 1366 | /// |
| 1367 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1368 | /// Subclasses may override this routine to provide different behavior. |
| 1369 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1370 | SourceLocation LParenLoc, |
| 1371 | SourceLocation EndLoc) { |
| 1372 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
| 1373 | EndLoc); |
| 1374 | } |
| 1375 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1376 | /// \brief Build a new OpenMP 'num_threads' clause. |
| 1377 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1378 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1379 | /// Subclasses may override this routine to provide different behavior. |
| 1380 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
| 1381 | SourceLocation StartLoc, |
| 1382 | SourceLocation LParenLoc, |
| 1383 | SourceLocation EndLoc) { |
| 1384 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
| 1385 | LParenLoc, EndLoc); |
| 1386 | } |
| 1387 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1388 | /// \brief Build a new OpenMP 'safelen' clause. |
| 1389 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1390 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1391 | /// Subclasses may override this routine to provide different behavior. |
| 1392 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1393 | SourceLocation LParenLoc, |
| 1394 | SourceLocation EndLoc) { |
| 1395 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1396 | } |
| 1397 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1398 | /// \brief Build a new OpenMP 'collapse' clause. |
| 1399 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1400 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1401 | /// Subclasses may override this routine to provide different behavior. |
| 1402 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1403 | SourceLocation LParenLoc, |
| 1404 | SourceLocation EndLoc) { |
| 1405 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
| 1406 | EndLoc); |
| 1407 | } |
| 1408 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1409 | /// \brief Build a new OpenMP 'default' clause. |
| 1410 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1411 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1412 | /// Subclasses may override this routine to provide different behavior. |
| 1413 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1414 | SourceLocation KindKwLoc, |
| 1415 | SourceLocation StartLoc, |
| 1416 | SourceLocation LParenLoc, |
| 1417 | SourceLocation EndLoc) { |
| 1418 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1419 | StartLoc, LParenLoc, EndLoc); |
| 1420 | } |
| 1421 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1422 | /// \brief Build a new OpenMP 'proc_bind' clause. |
| 1423 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1424 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1425 | /// Subclasses may override this routine to provide different behavior. |
| 1426 | OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 1427 | SourceLocation KindKwLoc, |
| 1428 | SourceLocation StartLoc, |
| 1429 | SourceLocation LParenLoc, |
| 1430 | SourceLocation EndLoc) { |
| 1431 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
| 1432 | StartLoc, LParenLoc, EndLoc); |
| 1433 | } |
| 1434 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1435 | /// \brief Build a new OpenMP 'schedule' clause. |
| 1436 | /// |
| 1437 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1438 | /// Subclasses may override this routine to provide different behavior. |
| 1439 | OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind, |
| 1440 | Expr *ChunkSize, |
| 1441 | SourceLocation StartLoc, |
| 1442 | SourceLocation LParenLoc, |
| 1443 | SourceLocation KindLoc, |
| 1444 | SourceLocation CommaLoc, |
| 1445 | SourceLocation EndLoc) { |
| 1446 | return getSema().ActOnOpenMPScheduleClause( |
| 1447 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 1448 | } |
| 1449 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1450 | /// \brief Build a new OpenMP 'ordered' clause. |
| 1451 | /// |
| 1452 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1453 | /// Subclasses may override this routine to provide different behavior. |
| 1454 | OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, |
| 1455 | SourceLocation EndLoc, |
| 1456 | SourceLocation LParenLoc, Expr *Num) { |
| 1457 | return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); |
| 1458 | } |
| 1459 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1460 | /// \brief Build a new OpenMP 'private' clause. |
| 1461 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1462 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1463 | /// Subclasses may override this routine to provide different behavior. |
| 1464 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1465 | SourceLocation StartLoc, |
| 1466 | SourceLocation LParenLoc, |
| 1467 | SourceLocation EndLoc) { |
| 1468 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1469 | EndLoc); |
| 1470 | } |
| 1471 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1472 | /// \brief Build a new OpenMP 'firstprivate' clause. |
| 1473 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1474 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1475 | /// Subclasses may override this routine to provide different behavior. |
| 1476 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1477 | SourceLocation StartLoc, |
| 1478 | SourceLocation LParenLoc, |
| 1479 | SourceLocation EndLoc) { |
| 1480 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1481 | EndLoc); |
| 1482 | } |
| 1483 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1484 | /// \brief Build a new OpenMP 'lastprivate' clause. |
| 1485 | /// |
| 1486 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1487 | /// Subclasses may override this routine to provide different behavior. |
| 1488 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1489 | SourceLocation StartLoc, |
| 1490 | SourceLocation LParenLoc, |
| 1491 | SourceLocation EndLoc) { |
| 1492 | return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, |
| 1493 | EndLoc); |
| 1494 | } |
| 1495 | |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1496 | /// \brief Build a new OpenMP 'shared' 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 | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1499 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1500 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1501 | SourceLocation StartLoc, |
| 1502 | SourceLocation LParenLoc, |
| 1503 | SourceLocation EndLoc) { |
| 1504 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1505 | EndLoc); |
| 1506 | } |
| 1507 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1508 | /// \brief Build a new OpenMP 'reduction' clause. |
| 1509 | /// |
| 1510 | /// By default, performs semantic analysis to build the new statement. |
| 1511 | /// Subclasses may override this routine to provide different behavior. |
| 1512 | OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList, |
| 1513 | SourceLocation StartLoc, |
| 1514 | SourceLocation LParenLoc, |
| 1515 | SourceLocation ColonLoc, |
| 1516 | SourceLocation EndLoc, |
| 1517 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1518 | const DeclarationNameInfo &ReductionId) { |
| 1519 | return getSema().ActOnOpenMPReductionClause( |
| 1520 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1521 | ReductionId); |
| 1522 | } |
| 1523 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1524 | /// \brief Build a new OpenMP 'linear' clause. |
| 1525 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1526 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1527 | /// Subclasses may override this routine to provide different behavior. |
| 1528 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1529 | SourceLocation StartLoc, |
| 1530 | SourceLocation LParenLoc, |
| 1531 | SourceLocation ColonLoc, |
| 1532 | SourceLocation EndLoc) { |
| 1533 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
| 1534 | ColonLoc, EndLoc); |
| 1535 | } |
| 1536 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1537 | /// \brief Build a new OpenMP 'aligned' clause. |
| 1538 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1539 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1540 | /// Subclasses may override this routine to provide different behavior. |
| 1541 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 1542 | SourceLocation StartLoc, |
| 1543 | SourceLocation LParenLoc, |
| 1544 | SourceLocation ColonLoc, |
| 1545 | SourceLocation EndLoc) { |
| 1546 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
| 1547 | LParenLoc, ColonLoc, EndLoc); |
| 1548 | } |
| 1549 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1550 | /// \brief Build a new OpenMP 'copyin' clause. |
| 1551 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1552 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1553 | /// Subclasses may override this routine to provide different behavior. |
| 1554 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1555 | SourceLocation StartLoc, |
| 1556 | SourceLocation LParenLoc, |
| 1557 | SourceLocation EndLoc) { |
| 1558 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
| 1559 | EndLoc); |
| 1560 | } |
| 1561 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1562 | /// \brief Build a new OpenMP 'copyprivate' clause. |
| 1563 | /// |
| 1564 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1565 | /// Subclasses may override this routine to provide different behavior. |
| 1566 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 1567 | SourceLocation StartLoc, |
| 1568 | SourceLocation LParenLoc, |
| 1569 | SourceLocation EndLoc) { |
| 1570 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
| 1571 | EndLoc); |
| 1572 | } |
| 1573 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1574 | /// \brief Build a new OpenMP 'flush' pseudo clause. |
| 1575 | /// |
| 1576 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1577 | /// Subclasses may override this routine to provide different behavior. |
| 1578 | OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
| 1579 | SourceLocation StartLoc, |
| 1580 | SourceLocation LParenLoc, |
| 1581 | SourceLocation EndLoc) { |
| 1582 | return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, |
| 1583 | EndLoc); |
| 1584 | } |
| 1585 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1586 | /// \brief Build a new OpenMP 'depend' pseudo clause. |
| 1587 | /// |
| 1588 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1589 | /// Subclasses may override this routine to provide different behavior. |
| 1590 | OMPClause * |
| 1591 | RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc, |
| 1592 | SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 1593 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1594 | SourceLocation EndLoc) { |
| 1595 | return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList, |
| 1596 | StartLoc, LParenLoc, EndLoc); |
| 1597 | } |
| 1598 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame^] | 1599 | /// \brief Build a new OpenMP 'device' clause. |
| 1600 | /// |
| 1601 | /// By default, performs semantic analysis to build the new statement. |
| 1602 | /// Subclasses may override this routine to provide different behavior. |
| 1603 | OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 1604 | SourceLocation LParenLoc, |
| 1605 | SourceLocation EndLoc) { |
| 1606 | return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc, |
| 1607 | EndLoc); |
| 1608 | } |
| 1609 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1610 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1611 | /// |
| 1612 | /// By default, performs semantic analysis to build the new statement. |
| 1613 | /// Subclasses may override this routine to provide different behavior. |
| 1614 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1615 | Expr *object) { |
| 1616 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1617 | } |
| 1618 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1619 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1620 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1621 | /// By default, performs semantic analysis to build the new statement. |
| 1622 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1623 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1624 | Expr *Object, Stmt *Body) { |
| 1625 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1626 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1627 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1628 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1629 | /// |
| 1630 | /// By default, performs semantic analysis to build the new statement. |
| 1631 | /// Subclasses may override this routine to provide different behavior. |
| 1632 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1633 | Stmt *Body) { |
| 1634 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1635 | } |
John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1636 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1637 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1638 | /// |
| 1639 | /// By default, performs semantic analysis to build the new statement. |
| 1640 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1641 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1642 | Stmt *Element, |
| 1643 | Expr *Collection, |
| 1644 | SourceLocation RParenLoc, |
| 1645 | Stmt *Body) { |
Sam Panzer | 2c4ca0f | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1646 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1647 | Element, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1648 | Collection, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1649 | RParenLoc); |
| 1650 | if (ForEachStmt.isInvalid()) |
| 1651 | return StmtError(); |
| 1652 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1653 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1654 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1655 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1656 | /// \brief Build a new C++ exception declaration. |
| 1657 | /// |
| 1658 | /// By default, performs semantic analysis to build the new decaration. |
| 1659 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1660 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1661 | TypeSourceInfo *Declarator, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1662 | SourceLocation StartLoc, |
| 1663 | SourceLocation IdLoc, |
| 1664 | IdentifierInfo *Id) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1665 | VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1666 | StartLoc, IdLoc, Id); |
| 1667 | if (Var) |
| 1668 | getSema().CurContext->addDecl(Var); |
| 1669 | return Var; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | /// \brief Build a new C++ catch statement. |
| 1673 | /// |
| 1674 | /// By default, performs semantic analysis to build the new statement. |
| 1675 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1676 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1677 | VarDecl *ExceptionDecl, |
| 1678 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1679 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1680 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1683 | /// \brief Build a new C++ try statement. |
| 1684 | /// |
| 1685 | /// By default, performs semantic analysis to build the new statement. |
| 1686 | /// Subclasses may override this routine to provide different behavior. |
Robert Wilhelm | cafda82 | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 1687 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 1688 | ArrayRef<Stmt *> Handlers) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1689 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1690 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1691 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1692 | /// \brief Build a new C++0x range-based for statement. |
| 1693 | /// |
| 1694 | /// By default, performs semantic analysis to build the new statement. |
| 1695 | /// Subclasses may override this routine to provide different behavior. |
| 1696 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1697 | SourceLocation ColonLoc, |
| 1698 | Stmt *Range, Stmt *BeginEnd, |
| 1699 | Expr *Cond, Expr *Inc, |
| 1700 | Stmt *LoopVar, |
| 1701 | SourceLocation RParenLoc) { |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1702 | // If we've just learned that the range is actually an Objective-C |
| 1703 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1704 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1705 | if (RangeStmt->isSingleDecl()) { |
| 1706 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1707 | if (RangeVar->isInvalidDecl()) |
| 1708 | return StmtError(); |
| 1709 | |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1710 | Expr *RangeExpr = RangeVar->getInit(); |
| 1711 | if (!RangeExpr->isTypeDependent() && |
| 1712 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1713 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1714 | RParenLoc); |
| 1715 | } |
| 1716 | } |
| 1717 | } |
| 1718 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1719 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | a05b3b5 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1720 | Cond, Inc, LoopVar, RParenLoc, |
| 1721 | Sema::BFRK_Rebuild); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1722 | } |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1723 | |
| 1724 | /// \brief Build a new C++0x range-based for statement. |
| 1725 | /// |
| 1726 | /// By default, performs semantic analysis to build the new statement. |
| 1727 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1728 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1729 | bool IsIfExists, |
| 1730 | NestedNameSpecifierLoc QualifierLoc, |
| 1731 | DeclarationNameInfo NameInfo, |
| 1732 | Stmt *Nested) { |
| 1733 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1734 | QualifierLoc, NameInfo, Nested); |
| 1735 | } |
| 1736 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1737 | /// \brief Attach body to a C++0x range-based for statement. |
| 1738 | /// |
| 1739 | /// By default, performs semantic analysis to finish the new statement. |
| 1740 | /// Subclasses may override this routine to provide different behavior. |
| 1741 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1742 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1743 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1744 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1745 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1746 | Stmt *TryBlock, Stmt *Handler) { |
| 1747 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1750 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1751 | Stmt *Block) { |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1752 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1755 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
Nico Weber | d64657f | 2015-03-09 02:47:59 +0000 | [diff] [blame] | 1756 | return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 1759 | /// \brief Build a new predefined expression. |
| 1760 | /// |
| 1761 | /// By default, performs semantic analysis to build the new expression. |
| 1762 | /// Subclasses may override this routine to provide different behavior. |
| 1763 | ExprResult RebuildPredefinedExpr(SourceLocation Loc, |
| 1764 | PredefinedExpr::IdentType IT) { |
| 1765 | return getSema().BuildPredefinedExpr(Loc, IT); |
| 1766 | } |
| 1767 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1768 | /// \brief Build a new expression that references a declaration. |
| 1769 | /// |
| 1770 | /// By default, performs semantic analysis to build the new expression. |
| 1771 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1772 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1773 | LookupResult &R, |
| 1774 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1775 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1776 | } |
| 1777 | |
| 1778 | |
| 1779 | /// \brief Build a new expression that references a declaration. |
| 1780 | /// |
| 1781 | /// By default, performs semantic analysis to build the new expression. |
| 1782 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1783 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1784 | ValueDecl *VD, |
| 1785 | const DeclarationNameInfo &NameInfo, |
| 1786 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1787 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1788 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1789 | |
| 1790 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1791 | |
| 1792 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1793 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1794 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | /// By default, performs semantic analysis to build the new expression. |
| 1798 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1799 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1800 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1801 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1804 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1805 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1806 | /// By default, performs semantic analysis to build the new expression. |
| 1807 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1808 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1809 | SourceLocation OperatorLoc, |
| 1810 | bool isArrow, |
| 1811 | CXXScopeSpec &SS, |
| 1812 | TypeSourceInfo *ScopeType, |
| 1813 | SourceLocation CCLoc, |
| 1814 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1815 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1816 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1817 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1818 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1819 | /// By default, performs semantic analysis to build the new expression. |
| 1820 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1821 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1822 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1823 | Expr *SubExpr) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1824 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1825 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1826 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1827 | /// \brief Build a new builtin offsetof expression. |
| 1828 | /// |
| 1829 | /// By default, performs semantic analysis to build the new expression. |
| 1830 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1831 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1832 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1833 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1834 | unsigned NumComponents, |
| 1835 | SourceLocation RParenLoc) { |
| 1836 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1837 | NumComponents, RParenLoc); |
| 1838 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1839 | |
| 1840 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1841 | /// type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1843 | /// By default, performs semantic analysis to build the new expression. |
| 1844 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1845 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1846 | SourceLocation OpLoc, |
| 1847 | UnaryExprOrTypeTrait ExprKind, |
| 1848 | SourceRange R) { |
| 1849 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1852 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1853 | /// expression argument. |
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. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1857 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1858 | UnaryExprOrTypeTrait ExprKind, |
| 1859 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1860 | ExprResult Result |
Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1861 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1862 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1863 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1865 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1868 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1869 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1870 | /// By default, performs semantic analysis to build the new expression. |
| 1871 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1872 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1873 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1874 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1875 | SourceLocation RBracketLoc) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1876 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1877 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1878 | RBracketLoc); |
| 1879 | } |
| 1880 | |
| 1881 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1882 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1883 | /// By default, performs semantic analysis to build the new expression. |
| 1884 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1885 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1886 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1887 | SourceLocation RParenLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1888 | Expr *ExecConfig = nullptr) { |
| 1889 | return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1890 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1894 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1895 | /// By default, performs semantic analysis to build the new expression. |
| 1896 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1897 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1898 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1899 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1900 | SourceLocation TemplateKWLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1901 | const DeclarationNameInfo &MemberNameInfo, |
| 1902 | ValueDecl *Member, |
| 1903 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1904 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1905 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1906 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1907 | isArrow); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1908 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1909 | // We have a reference to an unnamed field. This is always the |
| 1910 | // base of an anonymous struct/union member access, i.e. the |
| 1911 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1912 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1913 | assert(Member->getType()->isRecordType() && |
| 1914 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1915 | |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1916 | BaseResult = |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1917 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1918 | QualifierLoc.getNestedNameSpecifier(), |
| 1919 | FoundDecl, Member); |
| 1920 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1921 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1922 | Base = BaseResult.get(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1923 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Aaron Ballman | f4cb2be | 2015-03-24 15:07:53 +0000 | [diff] [blame] | 1924 | MemberExpr *ME = new (getSema().Context) |
| 1925 | MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo, |
| 1926 | cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1927 | return ME; |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1928 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1929 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1930 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1931 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1932 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1933 | Base = BaseResult.get(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1934 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1935 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1936 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1937 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1938 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1939 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1940 | R.resolveKind(); |
| 1941 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1942 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1943 | SS, TemplateKWLoc, |
| 1944 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1945 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1946 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1947 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1948 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1950 | /// By default, performs semantic analysis to build the new expression. |
| 1951 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1952 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1953 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1954 | Expr *LHS, Expr *RHS) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1955 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1959 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1960 | /// By default, performs semantic analysis to build the new expression. |
| 1961 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1962 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1963 | SourceLocation QuestionLoc, |
| 1964 | Expr *LHS, |
| 1965 | SourceLocation ColonLoc, |
| 1966 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1967 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1968 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1971 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1973 | /// By default, performs semantic analysis to build the new expression. |
| 1974 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1975 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1976 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1977 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1978 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1979 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1980 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1981 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1982 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1983 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1984 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1985 | /// By default, performs semantic analysis to build the new expression. |
| 1986 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1987 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1988 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1989 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1990 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1991 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1992 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1994 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1995 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1997 | /// By default, performs semantic analysis to build the new expression. |
| 1998 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1999 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2000 | SourceLocation OpLoc, |
| 2001 | SourceLocation AccessorLoc, |
| 2002 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2003 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2004 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2005 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2006 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2007 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2008 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2009 | /*FirstQualifierInScope*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2010 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2011 | /* TemplateArgs */ nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2012 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2013 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2015 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2016 | /// By default, performs semantic analysis to build the new expression. |
| 2017 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2018 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2019 | MultiExprArg Inits, |
| 2020 | SourceLocation RBraceLoc, |
| 2021 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2022 | ExprResult Result |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2023 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 2024 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2025 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2026 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 2027 | // Patch in the result type we were given, which may have been computed |
| 2028 | // when the initial InitListExpr was built. |
| 2029 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 2030 | ILE->setType(ResultTy); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2031 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2032 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2034 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2035 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2036 | /// By default, performs semantic analysis to build the new expression. |
| 2037 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2038 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2039 | MultiExprArg ArrayExprs, |
| 2040 | SourceLocation EqualOrColonLoc, |
| 2041 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2042 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2043 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2044 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2045 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2046 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2047 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2049 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2051 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2052 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2053 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2054 | /// By default, builds the implicit value initialization without performing |
| 2055 | /// any semantic analysis. Subclasses may override this routine to provide |
| 2056 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2057 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2058 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2059 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2060 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2061 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2062 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2063 | /// By default, performs semantic analysis to build the new expression. |
| 2064 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2065 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2066 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2067 | SourceLocation RParenLoc) { |
| 2068 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2069 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2070 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2074 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2075 | /// By default, performs semantic analysis to build the new expression. |
| 2076 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2077 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 2078 | MultiExprArg SubExprs, |
| 2079 | SourceLocation RParenLoc) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2080 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2081 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2082 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2083 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2084 | /// |
| 2085 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2086 | /// rather than attempting to map the label statement itself. |
| 2087 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2088 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 2089 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2090 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2091 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2092 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2093 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2095 | /// By default, performs semantic analysis to build the new expression. |
| 2096 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2097 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2098 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2099 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2100 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2101 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2102 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2103 | /// \brief Build a new __builtin_choose_expr expression. |
| 2104 | /// |
| 2105 | /// By default, performs semantic analysis to build the new expression. |
| 2106 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2107 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2108 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2109 | SourceLocation RParenLoc) { |
| 2110 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2111 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2112 | RParenLoc); |
| 2113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2114 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2115 | /// \brief Build a new generic selection expression. |
| 2116 | /// |
| 2117 | /// By default, performs semantic analysis to build the new expression. |
| 2118 | /// Subclasses may override this routine to provide different behavior. |
| 2119 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2120 | SourceLocation DefaultLoc, |
| 2121 | SourceLocation RParenLoc, |
| 2122 | Expr *ControllingExpr, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2123 | ArrayRef<TypeSourceInfo *> Types, |
| 2124 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2125 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2126 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2129 | /// \brief Build a new overloaded operator call expression. |
| 2130 | /// |
| 2131 | /// By default, performs semantic analysis to build the new expression. |
| 2132 | /// The semantic analysis provides the behavior of template instantiation, |
| 2133 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2134 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2135 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2136 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2137 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2138 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2139 | Expr *Callee, |
| 2140 | Expr *First, |
| 2141 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2142 | |
| 2143 | /// \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] | 2144 | /// reinterpret_cast. |
| 2145 | /// |
| 2146 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2148 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2149 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2150 | Stmt::StmtClass Class, |
| 2151 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2152 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2153 | SourceLocation RAngleLoc, |
| 2154 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2155 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2156 | SourceLocation RParenLoc) { |
| 2157 | switch (Class) { |
| 2158 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2159 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2161 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2162 | |
| 2163 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2164 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2165 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2166 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2168 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2169 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2170 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2171 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2172 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2173 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2174 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2175 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2177 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2178 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2179 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2180 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2181 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2182 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2183 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2184 | /// \brief Build a new C++ static_cast expression. |
| 2185 | /// |
| 2186 | /// By default, performs semantic analysis to build the new expression. |
| 2187 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2188 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2189 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2190 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2191 | SourceLocation RAngleLoc, |
| 2192 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2193 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2194 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2195 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2196 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2197 | SourceRange(LAngleLoc, RAngleLoc), |
| 2198 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | /// \brief Build a new C++ dynamic_cast expression. |
| 2202 | /// |
| 2203 | /// By default, performs semantic analysis to build the new expression. |
| 2204 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2205 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2206 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2207 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2208 | SourceLocation RAngleLoc, |
| 2209 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2210 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2211 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2212 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2213 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2214 | SourceRange(LAngleLoc, RAngleLoc), |
| 2215 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | /// \brief Build a new C++ reinterpret_cast expression. |
| 2219 | /// |
| 2220 | /// By default, performs semantic analysis to build the new expression. |
| 2221 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2222 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2223 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2224 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2225 | SourceLocation RAngleLoc, |
| 2226 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2227 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2228 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2229 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2230 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2231 | SourceRange(LAngleLoc, RAngleLoc), |
| 2232 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | /// \brief Build a new C++ const_cast expression. |
| 2236 | /// |
| 2237 | /// By default, performs semantic analysis to build the new expression. |
| 2238 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2239 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2240 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2241 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2242 | SourceLocation RAngleLoc, |
| 2243 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2244 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2245 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2246 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2247 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2248 | SourceRange(LAngleLoc, RAngleLoc), |
| 2249 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2250 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2251 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2252 | /// \brief Build a new C++ functional-style cast expression. |
| 2253 | /// |
| 2254 | /// By default, performs semantic analysis to build the new expression. |
| 2255 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2256 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2257 | SourceLocation LParenLoc, |
| 2258 | Expr *Sub, |
| 2259 | SourceLocation RParenLoc) { |
| 2260 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2261 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2262 | RParenLoc); |
| 2263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2264 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2265 | /// \brief Build a new C++ typeid(type) expression. |
| 2266 | /// |
| 2267 | /// By default, performs semantic analysis to build the new expression. |
| 2268 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2269 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2270 | SourceLocation TypeidLoc, |
| 2271 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2272 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2273 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2274 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2275 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2276 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2277 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2278 | /// \brief Build a new C++ typeid(expr) expression. |
| 2279 | /// |
| 2280 | /// By default, performs semantic analysis to build the new expression. |
| 2281 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2282 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2283 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2284 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2285 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2286 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2287 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2290 | /// \brief Build a new C++ __uuidof(type) expression. |
| 2291 | /// |
| 2292 | /// By default, performs semantic analysis to build the new expression. |
| 2293 | /// Subclasses may override this routine to provide different behavior. |
| 2294 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2295 | SourceLocation TypeidLoc, |
| 2296 | TypeSourceInfo *Operand, |
| 2297 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2298 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2299 | RParenLoc); |
| 2300 | } |
| 2301 | |
| 2302 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2303 | /// |
| 2304 | /// By default, performs semantic analysis to build the new expression. |
| 2305 | /// Subclasses may override this routine to provide different behavior. |
| 2306 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2307 | SourceLocation TypeidLoc, |
| 2308 | Expr *Operand, |
| 2309 | SourceLocation RParenLoc) { |
| 2310 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2311 | RParenLoc); |
| 2312 | } |
| 2313 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2314 | /// \brief Build a new C++ "this" expression. |
| 2315 | /// |
| 2316 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2317 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2318 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2319 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2320 | QualType ThisType, |
| 2321 | bool isImplicit) { |
Eli Friedman | 20139d3 | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2322 | getSema().CheckCXXThisCapture(ThisLoc); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2323 | return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | /// \brief Build a new C++ throw expression. |
| 2327 | /// |
| 2328 | /// By default, performs semantic analysis to build the new expression. |
| 2329 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2330 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2331 | bool IsThrownVariableInScope) { |
| 2332 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | /// \brief Build a new C++ default-argument expression. |
| 2336 | /// |
| 2337 | /// By default, builds a new default-argument expression, which does not |
| 2338 | /// require any semantic analysis. Subclasses may override this routine to |
| 2339 | /// provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2340 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2341 | ParmVarDecl *Param) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2342 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2345 | /// \brief Build a new C++11 default-initialization expression. |
| 2346 | /// |
| 2347 | /// By default, builds a new default field initialization expression, which |
| 2348 | /// does not require any semantic analysis. Subclasses may override this |
| 2349 | /// routine to provide different behavior. |
| 2350 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2351 | FieldDecl *Field) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2352 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field); |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2355 | /// \brief Build a new C++ zero-initialization expression. |
| 2356 | /// |
| 2357 | /// By default, performs semantic analysis to build the new expression. |
| 2358 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2359 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2360 | SourceLocation LParenLoc, |
| 2361 | SourceLocation RParenLoc) { |
| 2362 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2363 | None, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2365 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2366 | /// \brief Build a new C++ "new" expression. |
| 2367 | /// |
| 2368 | /// By default, performs semantic analysis to build the new expression. |
| 2369 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2370 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2371 | bool UseGlobal, |
| 2372 | SourceLocation PlacementLParen, |
| 2373 | MultiExprArg PlacementArgs, |
| 2374 | SourceLocation PlacementRParen, |
| 2375 | SourceRange TypeIdParens, |
| 2376 | QualType AllocatedType, |
| 2377 | TypeSourceInfo *AllocatedTypeInfo, |
| 2378 | Expr *ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2379 | SourceRange DirectInitRange, |
| 2380 | Expr *Initializer) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2381 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2382 | PlacementLParen, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2383 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2384 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2385 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2386 | AllocatedType, |
| 2387 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2388 | ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2389 | DirectInitRange, |
| 2390 | Initializer); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2392 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2393 | /// \brief Build a new C++ "delete" expression. |
| 2394 | /// |
| 2395 | /// By default, performs semantic analysis to build the new expression. |
| 2396 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2397 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2398 | bool IsGlobalDelete, |
| 2399 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2400 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2401 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2402 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2403 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2404 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2405 | /// \brief Build a new type trait expression. |
| 2406 | /// |
| 2407 | /// By default, performs semantic analysis to build the new expression. |
| 2408 | /// Subclasses may override this routine to provide different behavior. |
| 2409 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2410 | SourceLocation StartLoc, |
| 2411 | ArrayRef<TypeSourceInfo *> Args, |
| 2412 | SourceLocation RParenLoc) { |
| 2413 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2414 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2415 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2416 | /// \brief Build a new array type trait expression. |
| 2417 | /// |
| 2418 | /// By default, performs semantic analysis to build the new expression. |
| 2419 | /// Subclasses may override this routine to provide different behavior. |
| 2420 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2421 | SourceLocation StartLoc, |
| 2422 | TypeSourceInfo *TSInfo, |
| 2423 | Expr *DimExpr, |
| 2424 | SourceLocation RParenLoc) { |
| 2425 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2426 | } |
| 2427 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2428 | /// \brief Build a new expression trait expression. |
| 2429 | /// |
| 2430 | /// By default, performs semantic analysis to build the new expression. |
| 2431 | /// Subclasses may override this routine to provide different behavior. |
| 2432 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2433 | SourceLocation StartLoc, |
| 2434 | Expr *Queried, |
| 2435 | SourceLocation RParenLoc) { |
| 2436 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2437 | } |
| 2438 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2439 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2440 | /// expression. |
| 2441 | /// |
| 2442 | /// By default, performs semantic analysis to build the new expression. |
| 2443 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2444 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2445 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2446 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2447 | const DeclarationNameInfo &NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2448 | const TemplateArgumentListInfo *TemplateArgs, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2449 | bool IsAddressOfOperand, |
| 2450 | TypeSourceInfo **RecoveryTSI) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2451 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2452 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2453 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2454 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2455 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2456 | TemplateArgs); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2457 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2458 | return getSema().BuildQualifiedDeclarationNameExpr( |
| 2459 | SS, NameInfo, IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | /// \brief Build a new template-id expression. |
| 2463 | /// |
| 2464 | /// By default, performs semantic analysis to build the new expression. |
| 2465 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2466 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2467 | SourceLocation TemplateKWLoc, |
| 2468 | LookupResult &R, |
| 2469 | bool RequiresADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2470 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2471 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2472 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | /// \brief Build a new object-construction expression. |
| 2476 | /// |
| 2477 | /// By default, performs semantic analysis to build the new expression. |
| 2478 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2479 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2480 | SourceLocation Loc, |
| 2481 | CXXConstructorDecl *Constructor, |
| 2482 | bool IsElidable, |
| 2483 | MultiExprArg Args, |
| 2484 | bool HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2485 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2486 | bool StdInitListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2487 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2488 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2489 | SourceRange ParenRange) { |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2490 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2491 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2492 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2493 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2494 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2495 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2496 | ConvertedArgs, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2497 | HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2498 | ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2499 | StdInitListInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2500 | RequiresZeroInit, ConstructKind, |
| 2501 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | /// \brief Build a new object-construction expression. |
| 2505 | /// |
| 2506 | /// By default, performs semantic analysis to build the new expression. |
| 2507 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2508 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2509 | SourceLocation LParenLoc, |
| 2510 | MultiExprArg Args, |
| 2511 | SourceLocation RParenLoc) { |
| 2512 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2513 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2514 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2515 | RParenLoc); |
| 2516 | } |
| 2517 | |
| 2518 | /// \brief Build a new object-construction expression. |
| 2519 | /// |
| 2520 | /// By default, performs semantic analysis to build the new expression. |
| 2521 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2522 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2523 | SourceLocation LParenLoc, |
| 2524 | MultiExprArg Args, |
| 2525 | SourceLocation RParenLoc) { |
| 2526 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2527 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2528 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2529 | RParenLoc); |
| 2530 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2531 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2532 | /// \brief Build a new member reference expression. |
| 2533 | /// |
| 2534 | /// By default, performs semantic analysis to build the new expression. |
| 2535 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2536 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2537 | QualType BaseType, |
| 2538 | bool IsArrow, |
| 2539 | SourceLocation OperatorLoc, |
| 2540 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2541 | SourceLocation TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2542 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2543 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2544 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2545 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2546 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2547 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2548 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2549 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2550 | SS, TemplateKWLoc, |
| 2551 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2552 | MemberNameInfo, |
| 2553 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2556 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2557 | /// |
| 2558 | /// By default, performs semantic analysis to build the new expression. |
| 2559 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2560 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2561 | SourceLocation OperatorLoc, |
| 2562 | bool IsArrow, |
| 2563 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2564 | SourceLocation TemplateKWLoc, |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2565 | NamedDecl *FirstQualifierInScope, |
| 2566 | LookupResult &R, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2567 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2568 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2569 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2570 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2571 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2572 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2573 | SS, TemplateKWLoc, |
| 2574 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2575 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2576 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2577 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2578 | /// \brief Build a new noexcept expression. |
| 2579 | /// |
| 2580 | /// By default, performs semantic analysis to build the new expression. |
| 2581 | /// Subclasses may override this routine to provide different behavior. |
| 2582 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2583 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2584 | } |
| 2585 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2586 | /// \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] | 2587 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2588 | SourceLocation PackLoc, |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2589 | SourceLocation RParenLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2590 | Optional<unsigned> Length) { |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2591 | if (Length) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2592 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2593 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2594 | RParenLoc, *Length); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2595 | |
| 2596 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2597 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2598 | RParenLoc); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2599 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2600 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2601 | /// \brief Build a new Objective-C boxed expression. |
| 2602 | /// |
| 2603 | /// By default, performs semantic analysis to build the new expression. |
| 2604 | /// Subclasses may override this routine to provide different behavior. |
| 2605 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2606 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2607 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2608 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2609 | /// \brief Build a new Objective-C array literal. |
| 2610 | /// |
| 2611 | /// By default, performs semantic analysis to build the new expression. |
| 2612 | /// Subclasses may override this routine to provide different behavior. |
| 2613 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2614 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2615 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2616 | MultiExprArg(Elements, NumElements)); |
| 2617 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2618 | |
| 2619 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2620 | Expr *Base, Expr *Key, |
| 2621 | ObjCMethodDecl *getterMethod, |
| 2622 | ObjCMethodDecl *setterMethod) { |
| 2623 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2624 | getterMethod, setterMethod); |
| 2625 | } |
| 2626 | |
| 2627 | /// \brief Build a new Objective-C dictionary literal. |
| 2628 | /// |
| 2629 | /// By default, performs semantic analysis to build the new expression. |
| 2630 | /// Subclasses may override this routine to provide different behavior. |
| 2631 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2632 | ObjCDictionaryElement *Elements, |
| 2633 | unsigned NumElements) { |
| 2634 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2635 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2636 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2637 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2638 | /// |
| 2639 | /// By default, performs semantic analysis to build the new expression. |
| 2640 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2641 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2642 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2643 | SourceLocation RParenLoc) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2644 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2645 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2646 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2647 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2648 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2649 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2650 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2651 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2652 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2653 | MultiExprArg Args, |
| 2654 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2655 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2656 | ReceiverTypeInfo->getType(), |
| 2657 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2658 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2659 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2663 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2664 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2665 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2666 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2667 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2668 | MultiExprArg Args, |
| 2669 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2670 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2671 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2672 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2673 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2674 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2677 | /// \brief Build a new Objective-C instance/class message to 'super'. |
| 2678 | ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, |
| 2679 | Selector Sel, |
| 2680 | ArrayRef<SourceLocation> SelectorLocs, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2681 | QualType SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2682 | ObjCMethodDecl *Method, |
| 2683 | SourceLocation LBracLoc, |
| 2684 | MultiExprArg Args, |
| 2685 | SourceLocation RBracLoc) { |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2686 | return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2687 | SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2688 | SuperLoc, |
| 2689 | Sel, Method, LBracLoc, SelectorLocs, |
| 2690 | RBracLoc, Args) |
| 2691 | : SemaRef.BuildClassMessage(nullptr, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2692 | SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2693 | SuperLoc, |
| 2694 | Sel, Method, LBracLoc, SelectorLocs, |
| 2695 | RBracLoc, Args); |
| 2696 | |
| 2697 | |
| 2698 | } |
| 2699 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2700 | /// \brief Build a new Objective-C ivar reference expression. |
| 2701 | /// |
| 2702 | /// By default, performs semantic analysis to build the new expression. |
| 2703 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2704 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2705 | SourceLocation IvarLoc, |
| 2706 | bool IsArrow, bool IsFreeIvar) { |
| 2707 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2708 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2709 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| 2710 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2711 | /*FIXME:*/IvarLoc, IsArrow, |
| 2712 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2713 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2714 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2715 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2716 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2717 | |
| 2718 | /// \brief Build a new Objective-C property reference expression. |
| 2719 | /// |
| 2720 | /// By default, performs semantic analysis to build the new expression. |
| 2721 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2722 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2723 | ObjCPropertyDecl *Property, |
| 2724 | SourceLocation PropertyLoc) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2725 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2726 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 2727 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 2728 | /*FIXME:*/PropertyLoc, |
| 2729 | /*IsArrow=*/false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2730 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2731 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2732 | NameInfo, |
| 2733 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2734 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2735 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2736 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2737 | /// |
| 2738 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2739 | /// Subclasses may override this routine to provide different behavior. |
| 2740 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2741 | ObjCMethodDecl *Getter, |
| 2742 | ObjCMethodDecl *Setter, |
| 2743 | SourceLocation PropertyLoc) { |
| 2744 | // Since these expressions can only be value-dependent, we do not |
| 2745 | // need to perform semantic analysis again. |
| 2746 | return Owned( |
| 2747 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2748 | VK_LValue, OK_ObjCProperty, |
| 2749 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2752 | /// \brief Build a new Objective-C "isa" expression. |
| 2753 | /// |
| 2754 | /// By default, performs semantic analysis to build the new expression. |
| 2755 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2756 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2757 | SourceLocation OpLoc, bool IsArrow) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2758 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2759 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 2760 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2761 | OpLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2762 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2763 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2764 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2765 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2766 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2767 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2768 | /// \brief Build a new shuffle vector expression. |
| 2769 | /// |
| 2770 | /// By default, performs semantic analysis to build the new expression. |
| 2771 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2772 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2773 | MultiExprArg SubExprs, |
| 2774 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2775 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2777 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2778 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2779 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2780 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2781 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2782 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2783 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2784 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2785 | SemaRef.Context.BuiltinFnTy, |
| 2786 | VK_RValue, BuiltinLoc); |
| 2787 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2788 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2789 | CK_BuiltinFnToFnPtr).get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2790 | |
| 2791 | // Build the CallExpr |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2792 | ExprResult TheCall = new (SemaRef.Context) CallExpr( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2793 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2794 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2795 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2796 | // Type-check the __builtin_shufflevector expression. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2797 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2798 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2799 | |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 2800 | /// \brief Build a new convert vector expression. |
| 2801 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 2802 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 2803 | SourceLocation RParenLoc) { |
| 2804 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 2805 | BuiltinLoc, RParenLoc); |
| 2806 | } |
| 2807 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2808 | /// \brief Build a new template argument pack expansion. |
| 2809 | /// |
| 2810 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2811 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2812 | /// different behavior. |
| 2813 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2814 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2815 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2816 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2817 | case TemplateArgument::Expression: { |
| 2818 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2819 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2820 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2821 | if (Result.isInvalid()) |
| 2822 | return TemplateArgumentLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2823 | |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2824 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2825 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2826 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2827 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2828 | return TemplateArgumentLoc(TemplateArgument( |
| 2829 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2830 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2831 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2832 | Pattern.getTemplateNameLoc(), |
| 2833 | EllipsisLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2834 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2835 | case TemplateArgument::Null: |
| 2836 | case TemplateArgument::Integral: |
| 2837 | case TemplateArgument::Declaration: |
| 2838 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2839 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2840 | case TemplateArgument::NullPtr: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2841 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2842 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2843 | case TemplateArgument::Type: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2844 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2845 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2846 | EllipsisLoc, |
| 2847 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2848 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2849 | Expansion); |
| 2850 | break; |
| 2851 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2852 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2853 | return TemplateArgumentLoc(); |
| 2854 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2855 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2856 | /// \brief Build a new expression pack expansion. |
| 2857 | /// |
| 2858 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2859 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2860 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2861 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2862 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2863 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2864 | } |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2865 | |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 2866 | /// \brief Build a new C++1z fold-expression. |
| 2867 | /// |
| 2868 | /// By default, performs semantic analysis in order to build a new fold |
| 2869 | /// expression. |
| 2870 | ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, |
| 2871 | BinaryOperatorKind Operator, |
| 2872 | SourceLocation EllipsisLoc, Expr *RHS, |
| 2873 | SourceLocation RParenLoc) { |
| 2874 | return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc, |
| 2875 | RHS, RParenLoc); |
| 2876 | } |
| 2877 | |
| 2878 | /// \brief Build an empty C++1z fold-expression with the given operator. |
| 2879 | /// |
| 2880 | /// By default, produces the fallback value for the fold-expression, or |
| 2881 | /// produce an error if there is no fallback value. |
| 2882 | ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 2883 | BinaryOperatorKind Operator) { |
| 2884 | return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); |
| 2885 | } |
| 2886 | |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2887 | /// \brief Build a new atomic operation expression. |
| 2888 | /// |
| 2889 | /// By default, performs semantic analysis to build the new expression. |
| 2890 | /// Subclasses may override this routine to provide different behavior. |
| 2891 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2892 | MultiExprArg SubExprs, |
| 2893 | QualType RetTy, |
| 2894 | AtomicExpr::AtomicOp Op, |
| 2895 | SourceLocation RParenLoc) { |
| 2896 | // Just create the expression; there is not any interesting semantic |
| 2897 | // analysis here because we can't actually build an AtomicExpr until |
| 2898 | // we are sure it is semantically sound. |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2899 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2900 | RParenLoc); |
| 2901 | } |
| 2902 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2903 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2904 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2905 | QualType ObjectType, |
| 2906 | NamedDecl *FirstQualifierInScope, |
| 2907 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2908 | |
| 2909 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2910 | QualType ObjectType, |
| 2911 | NamedDecl *FirstQualifierInScope, |
| 2912 | CXXScopeSpec &SS); |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 2913 | |
| 2914 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 2915 | NamedDecl *FirstQualifierInScope, |
| 2916 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2917 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2918 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2919 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2920 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2921 | if (!S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2922 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2923 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2924 | switch (S->getStmtClass()) { |
| 2925 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2926 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2927 | // Transform individual statement nodes |
| 2928 | #define STMT(Node, Parent) \ |
| 2929 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2930 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2931 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2932 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2933 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2934 | // Transform expressions by calling TransformExpr. |
| 2935 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2936 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2937 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2938 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2939 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2940 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2941 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2942 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2943 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2944 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2945 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2948 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2950 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2951 | template<typename Derived> |
| 2952 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2953 | if (!S) |
| 2954 | return S; |
| 2955 | |
| 2956 | switch (S->getClauseKind()) { |
| 2957 | default: break; |
| 2958 | // Transform individual clause nodes |
| 2959 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2960 | case OMPC_ ## Name : \ |
| 2961 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2962 | #include "clang/Basic/OpenMPKinds.def" |
| 2963 | } |
| 2964 | |
| 2965 | return S; |
| 2966 | } |
| 2967 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2968 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2969 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2970 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2971 | if (!E) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2972 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2973 | |
| 2974 | switch (E->getStmtClass()) { |
| 2975 | case Stmt::NoStmtClass: break; |
| 2976 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2977 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2978 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2979 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2980 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2981 | } |
| 2982 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2983 | return E; |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | template<typename Derived> |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2987 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 2988 | bool NotCopyInit) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2989 | // Initializers are instantiated like expressions, except that various outer |
| 2990 | // layers are stripped. |
| 2991 | if (!Init) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2992 | return Init; |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2993 | |
| 2994 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2995 | Init = ExprTemp->getSubExpr(); |
| 2996 | |
Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 2997 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 2998 | Init = MTE->GetTemporaryExpr(); |
| 2999 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3000 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 3001 | Init = Binder->getSubExpr(); |
| 3002 | |
| 3003 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 3004 | Init = ICE->getSubExprAsWritten(); |
| 3005 | |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3006 | if (CXXStdInitializerListExpr *ILE = |
| 3007 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3008 | return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3009 | |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3010 | // If this is copy-initialization, we only need to reconstruct |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3011 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 3012 | // the initializer is already the right type. |
| 3013 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3014 | if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3015 | return getDerived().TransformExpr(Init); |
| 3016 | |
| 3017 | // Revert value-initialization back to empty parens. |
| 3018 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 3019 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3020 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3021 | Parens.getEnd()); |
| 3022 | } |
| 3023 | |
| 3024 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 3025 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3026 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3027 | SourceLocation()); |
| 3028 | |
| 3029 | // Revert initialization by constructor back to a parenthesized or braced list |
| 3030 | // of expressions. Any other form of initializer can just be reused directly. |
| 3031 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3032 | return getDerived().TransformExpr(Init); |
| 3033 | |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3034 | // If the initialization implicitly converted an initializer list to a |
| 3035 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 3036 | if (Construct && Construct->isStdInitListInitialization()) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3037 | return TransformInitializer(Construct->getArg(0), NotCopyInit); |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3038 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3039 | SmallVector<Expr*, 8> NewArgs; |
| 3040 | bool ArgChanged = false; |
| 3041 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3042 | /*IsCall*/true, NewArgs, &ArgChanged)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3043 | return ExprError(); |
| 3044 | |
| 3045 | // If this was list initialization, revert to list form. |
| 3046 | if (Construct->isListInitialization()) |
| 3047 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 3048 | Construct->getLocEnd(), |
| 3049 | Construct->getType()); |
| 3050 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3051 | // Build a ParenListExpr to represent anything else. |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 3052 | SourceRange Parens = Construct->getParenOrBraceRange(); |
Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 3053 | if (Parens.isInvalid()) { |
| 3054 | // This was a variable declaration's initialization for which no initializer |
| 3055 | // was specified. |
| 3056 | assert(NewArgs.empty() && |
| 3057 | "no parens or braces but have direct init with arguments?"); |
| 3058 | return ExprEmpty(); |
| 3059 | } |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3060 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 3061 | Parens.getEnd()); |
| 3062 | } |
| 3063 | |
| 3064 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3065 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 3066 | unsigned NumInputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3067 | bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3068 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3069 | bool *ArgChanged) { |
| 3070 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 3071 | // If requested, drop call arguments that need to be dropped. |
| 3072 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 3073 | if (ArgChanged) |
| 3074 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3075 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3076 | break; |
| 3077 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3078 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3079 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 3080 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3081 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3082 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3083 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3084 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3085 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3086 | // Determine whether the set of unexpanded parameter packs can and should |
| 3087 | // be expanded. |
| 3088 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3089 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3090 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 3091 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3092 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 3093 | Pattern->getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3094 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3095 | Expand, RetainExpansion, |
| 3096 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3097 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3098 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3099 | if (!Expand) { |
| 3100 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3101 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3102 | // expansion. |
| 3103 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3104 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 3105 | if (OutPattern.isInvalid()) |
| 3106 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3107 | |
| 3108 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3109 | Expansion->getEllipsisLoc(), |
| 3110 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3111 | if (Out.isInvalid()) |
| 3112 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3113 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3114 | if (ArgChanged) |
| 3115 | *ArgChanged = true; |
| 3116 | Outputs.push_back(Out.get()); |
| 3117 | continue; |
| 3118 | } |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 3119 | |
| 3120 | // Record right away that the argument was changed. This needs |
| 3121 | // to happen even if the array expands to nothing. |
| 3122 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3123 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3124 | // The transform has determined that we should perform an elementwise |
| 3125 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3126 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3127 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3128 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3129 | if (Out.isInvalid()) |
| 3130 | return true; |
| 3131 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3132 | // FIXME: Can this happen? We should not try to expand the pack |
| 3133 | // in this case. |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3134 | if (Out.get()->containsUnexpandedParameterPack()) { |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3135 | Out = getDerived().RebuildPackExpansion( |
| 3136 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3137 | if (Out.isInvalid()) |
| 3138 | return true; |
| 3139 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3140 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3141 | Outputs.push_back(Out.get()); |
| 3142 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3143 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3144 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3145 | // forgetting the partially-substituted parameter pack. |
| 3146 | if (RetainExpansion) { |
| 3147 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3148 | |
| 3149 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3150 | if (Out.isInvalid()) |
| 3151 | return true; |
| 3152 | |
| 3153 | Out = getDerived().RebuildPackExpansion( |
| 3154 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3155 | if (Out.isInvalid()) |
| 3156 | return true; |
| 3157 | |
| 3158 | Outputs.push_back(Out.get()); |
| 3159 | } |
| 3160 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3161 | continue; |
| 3162 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3163 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3164 | ExprResult Result = |
| 3165 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3166 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3167 | if (Result.isInvalid()) |
| 3168 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3169 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3170 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3171 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3172 | |
| 3173 | Outputs.push_back(Result.get()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3174 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3175 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3176 | return false; |
| 3177 | } |
| 3178 | |
| 3179 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3180 | NestedNameSpecifierLoc |
| 3181 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3182 | NestedNameSpecifierLoc NNS, |
| 3183 | QualType ObjectType, |
| 3184 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3185 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3186 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3187 | Qualifier = Qualifier.getPrefix()) |
| 3188 | Qualifiers.push_back(Qualifier); |
| 3189 | |
| 3190 | CXXScopeSpec SS; |
| 3191 | while (!Qualifiers.empty()) { |
| 3192 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3193 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3194 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3195 | switch (QNNS->getKind()) { |
| 3196 | case NestedNameSpecifier::Identifier: |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3197 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3198 | *QNNS->getAsIdentifier(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3199 | Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3200 | Q.getLocalEndLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3201 | ObjectType, false, SS, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3202 | FirstQualifierInScope, false)) |
| 3203 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3205 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3206 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3207 | case NestedNameSpecifier::Namespace: { |
| 3208 | NamespaceDecl *NS |
| 3209 | = cast_or_null<NamespaceDecl>( |
| 3210 | getDerived().TransformDecl( |
| 3211 | Q.getLocalBeginLoc(), |
| 3212 | QNNS->getAsNamespace())); |
| 3213 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3214 | break; |
| 3215 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3216 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3217 | case NestedNameSpecifier::NamespaceAlias: { |
| 3218 | NamespaceAliasDecl *Alias |
| 3219 | = cast_or_null<NamespaceAliasDecl>( |
| 3220 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3221 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3222 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3223 | Q.getLocalEndLoc()); |
| 3224 | break; |
| 3225 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3226 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3227 | case NestedNameSpecifier::Global: |
| 3228 | // There is no meaningful transformation that one could perform on the |
| 3229 | // global scope. |
| 3230 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3231 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3232 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 3233 | case NestedNameSpecifier::Super: { |
| 3234 | CXXRecordDecl *RD = |
| 3235 | cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 3236 | SourceLocation(), QNNS->getAsRecordDecl())); |
| 3237 | SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); |
| 3238 | break; |
| 3239 | } |
| 3240 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3241 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3242 | case NestedNameSpecifier::TypeSpec: { |
| 3243 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3244 | FirstQualifierInScope, SS); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3245 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3246 | if (!TL) |
| 3247 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3248 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3249 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3250 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3251 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3252 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3253 | "Can't get cv-qualifiers here"); |
Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3254 | if (TL.getType()->isEnumeralType()) |
| 3255 | SemaRef.Diag(TL.getBeginLoc(), |
| 3256 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3257 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3258 | Q.getLocalEndLoc()); |
| 3259 | break; |
| 3260 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3261 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3262 | // error because a previous error should have already been emitted. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3263 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3264 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3265 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3266 | << TL.getType() << SS.getRange(); |
| 3267 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3268 | return NestedNameSpecifierLoc(); |
| 3269 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3270 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3271 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3272 | // 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] | 3273 | FirstQualifierInScope = nullptr; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3274 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3275 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3276 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3277 | // 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] | 3278 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3279 | !getDerived().AlwaysRebuild()) |
| 3280 | return NNS; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3281 | |
| 3282 | // If we can re-use the source-location data from the original |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3283 | // nested-name-specifier, do so. |
| 3284 | if (SS.location_size() == NNS.getDataLength() && |
| 3285 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3286 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3287 | |
| 3288 | // Allocate new nested-name-specifier location information. |
| 3289 | return SS.getWithLocInContext(SemaRef.Context); |
| 3290 | } |
| 3291 | |
| 3292 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3293 | DeclarationNameInfo |
| 3294 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3295 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3296 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3297 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3298 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3299 | |
| 3300 | switch (Name.getNameKind()) { |
| 3301 | case DeclarationName::Identifier: |
| 3302 | case DeclarationName::ObjCZeroArgSelector: |
| 3303 | case DeclarationName::ObjCOneArgSelector: |
| 3304 | case DeclarationName::ObjCMultiArgSelector: |
| 3305 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3306 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3307 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3308 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3310 | case DeclarationName::CXXConstructorName: |
| 3311 | case DeclarationName::CXXDestructorName: |
| 3312 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3313 | TypeSourceInfo *NewTInfo; |
| 3314 | CanQualType NewCanTy; |
| 3315 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3316 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3317 | if (!NewTInfo) |
| 3318 | return DeclarationNameInfo(); |
| 3319 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3320 | } |
| 3321 | else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3322 | NewTInfo = nullptr; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3323 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3324 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3325 | if (NewT.isNull()) |
| 3326 | return DeclarationNameInfo(); |
| 3327 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3328 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3329 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3330 | DeclarationName NewName |
| 3331 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3332 | NewCanTy); |
| 3333 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3334 | NewNameInfo.setName(NewName); |
| 3335 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3336 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3337 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3338 | } |
| 3339 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3340 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3344 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3345 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3346 | TemplateName Name, |
| 3347 | SourceLocation NameLoc, |
| 3348 | QualType ObjectType, |
| 3349 | NamedDecl *FirstQualifierInScope) { |
| 3350 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3351 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3352 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3353 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3354 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3355 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3356 | Template)); |
| 3357 | if (!TransTemplate) |
| 3358 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3359 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3360 | if (!getDerived().AlwaysRebuild() && |
| 3361 | SS.getScopeRep() == QTN->getQualifier() && |
| 3362 | TransTemplate == Template) |
| 3363 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3364 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3365 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3366 | TransTemplate); |
| 3367 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3368 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3369 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3370 | if (SS.getScopeRep()) { |
| 3371 | // These apply to the scope specifier, not the template. |
| 3372 | ObjectType = QualType(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3373 | FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3376 | if (!getDerived().AlwaysRebuild() && |
| 3377 | SS.getScopeRep() == DTN->getQualifier() && |
| 3378 | ObjectType.isNull()) |
| 3379 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3380 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3381 | if (DTN->isIdentifier()) { |
| 3382 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3383 | *DTN->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3384 | NameLoc, |
| 3385 | ObjectType, |
| 3386 | FirstQualifierInScope); |
| 3387 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3388 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3389 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3390 | ObjectType); |
| 3391 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3392 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3393 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3394 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3395 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3396 | Template)); |
| 3397 | if (!TransTemplate) |
| 3398 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3399 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3400 | if (!getDerived().AlwaysRebuild() && |
| 3401 | TransTemplate == Template) |
| 3402 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3403 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3404 | return TemplateName(TransTemplate); |
| 3405 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3406 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3407 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3408 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3409 | TemplateTemplateParmDecl *TransParam |
| 3410 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3411 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3412 | if (!TransParam) |
| 3413 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3414 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3415 | if (!getDerived().AlwaysRebuild() && |
| 3416 | TransParam == SubstPack->getParameterPack()) |
| 3417 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3418 | |
| 3419 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3420 | SubstPack->getArgumentPack()); |
| 3421 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3422 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3423 | // These should be getting filtered out before they reach the AST. |
| 3424 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3428 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3429 | const TemplateArgument &Arg, |
| 3430 | TemplateArgumentLoc &Output) { |
| 3431 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3432 | switch (Arg.getKind()) { |
| 3433 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3434 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3435 | break; |
| 3436 | |
| 3437 | case TemplateArgument::Type: |
| 3438 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3439 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3440 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3441 | break; |
| 3442 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3443 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3444 | case TemplateArgument::TemplateExpansion: { |
| 3445 | NestedNameSpecifierLocBuilder Builder; |
| 3446 | TemplateName Template = Arg.getAsTemplate(); |
| 3447 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3448 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3449 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3450 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3451 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3452 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3453 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3454 | Builder.getWithLocInContext(SemaRef.Context), |
| 3455 | Loc); |
| 3456 | else |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3457 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3458 | Builder.getWithLocInContext(SemaRef.Context), |
| 3459 | Loc, Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3460 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3461 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3462 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3463 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3464 | case TemplateArgument::Expression: |
| 3465 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3466 | break; |
| 3467 | |
| 3468 | case TemplateArgument::Declaration: |
| 3469 | case TemplateArgument::Integral: |
| 3470 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3471 | case TemplateArgument::NullPtr: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3472 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3473 | break; |
| 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | template<typename Derived> |
| 3478 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3479 | const TemplateArgumentLoc &Input, |
| 3480 | TemplateArgumentLoc &Output) { |
| 3481 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3482 | switch (Arg.getKind()) { |
| 3483 | case TemplateArgument::Null: |
| 3484 | case TemplateArgument::Integral: |
Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3485 | case TemplateArgument::Pack: |
| 3486 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3487 | case TemplateArgument::NullPtr: |
| 3488 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3490 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3491 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3492 | if (!DI) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3493 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3494 | |
| 3495 | DI = getDerived().TransformType(DI); |
| 3496 | if (!DI) return true; |
| 3497 | |
| 3498 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3499 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3500 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3501 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3502 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3503 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3504 | if (QualifierLoc) { |
| 3505 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3506 | if (!QualifierLoc) |
| 3507 | return true; |
| 3508 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3509 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3510 | CXXScopeSpec SS; |
| 3511 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3512 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3513 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3514 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3515 | if (Template.isNull()) |
| 3516 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3517 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3518 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3519 | Input.getTemplateNameLoc()); |
| 3520 | return false; |
| 3521 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3522 | |
| 3523 | case TemplateArgument::TemplateExpansion: |
| 3524 | llvm_unreachable("Caller should expand pack expansions"); |
| 3525 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3526 | case TemplateArgument::Expression: { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3527 | // Template argument expressions are constant expressions. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3529 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3531 | Expr *InputExpr = Input.getSourceExpression(); |
| 3532 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3533 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3534 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3535 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3536 | if (E.isInvalid()) return true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3537 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3538 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3539 | } |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3540 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3542 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3543 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3544 | } |
| 3545 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3546 | /// \brief Iterator adaptor that invents template argument location information |
| 3547 | /// for each of the template arguments in its underlying iterator. |
| 3548 | template<typename Derived, typename InputIterator> |
| 3549 | class TemplateArgumentLocInventIterator { |
| 3550 | TreeTransform<Derived> &Self; |
| 3551 | InputIterator Iter; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3552 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3553 | public: |
| 3554 | typedef TemplateArgumentLoc value_type; |
| 3555 | typedef TemplateArgumentLoc reference; |
| 3556 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3557 | difference_type; |
| 3558 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3559 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3560 | class pointer { |
| 3561 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3562 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3563 | public: |
| 3564 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3565 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3566 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3567 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3568 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3569 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3570 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3571 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3572 | InputIterator Iter) |
| 3573 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3574 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3575 | TemplateArgumentLocInventIterator &operator++() { |
| 3576 | ++Iter; |
| 3577 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3578 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3579 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3580 | TemplateArgumentLocInventIterator operator++(int) { |
| 3581 | TemplateArgumentLocInventIterator Old(*this); |
| 3582 | ++(*this); |
| 3583 | return Old; |
| 3584 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3585 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3586 | reference operator*() const { |
| 3587 | TemplateArgumentLoc Result; |
| 3588 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3589 | return Result; |
| 3590 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3591 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3592 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3593 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3594 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3595 | const TemplateArgumentLocInventIterator &Y) { |
| 3596 | return X.Iter == Y.Iter; |
| 3597 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3598 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3599 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3600 | const TemplateArgumentLocInventIterator &Y) { |
| 3601 | return X.Iter != Y.Iter; |
| 3602 | } |
| 3603 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3604 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3605 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3606 | template<typename InputIterator> |
| 3607 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3608 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3609 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3610 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3611 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3612 | TemplateArgumentLoc In = *First; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3613 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3614 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3615 | // Unpack argument packs, which we translate them into separate |
| 3616 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3617 | // FIXME: We could do much better if we could guarantee that the |
| 3618 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3619 | // all of the template arguments in the argument pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3620 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3621 | TemplateArgument::pack_iterator> |
| 3622 | PackLocIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3623 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3624 | In.getArgument().pack_begin()), |
| 3625 | PackLocIterator(*this, |
| 3626 | In.getArgument().pack_end()), |
| 3627 | Outputs)) |
| 3628 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3629 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3630 | continue; |
| 3631 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3632 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3633 | if (In.getArgument().isPackExpansion()) { |
| 3634 | // We have a pack expansion, for which we will be substituting into |
| 3635 | // the pattern. |
| 3636 | SourceLocation Ellipsis; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3637 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3638 | TemplateArgumentLoc Pattern |
Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3639 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3640 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3641 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3642 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3643 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3644 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3645 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3646 | // Determine whether the set of unexpanded parameter packs can and should |
| 3647 | // be expanded. |
| 3648 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3649 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3650 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3651 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3652 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3653 | Unexpanded, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3654 | Expand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3655 | RetainExpansion, |
| 3656 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3657 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3658 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3659 | if (!Expand) { |
| 3660 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3661 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3662 | // expansion. |
| 3663 | TemplateArgumentLoc OutPattern; |
| 3664 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3665 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3666 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3667 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3668 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3669 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3670 | if (Out.getArgument().isNull()) |
| 3671 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3672 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3673 | Outputs.addArgument(Out); |
| 3674 | continue; |
| 3675 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3676 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3677 | // The transform has determined that we should perform an elementwise |
| 3678 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3679 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3680 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3681 | |
| 3682 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3683 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3684 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3685 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3686 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3687 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3688 | if (Out.getArgument().isNull()) |
| 3689 | return true; |
| 3690 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3691 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3692 | Outputs.addArgument(Out); |
| 3693 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3694 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3695 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3696 | // forgetting the partially-substituted parameter pack. |
| 3697 | if (RetainExpansion) { |
| 3698 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3700 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3701 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3702 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3703 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3704 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3705 | if (Out.getArgument().isNull()) |
| 3706 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3707 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3708 | Outputs.addArgument(Out); |
| 3709 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3710 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3711 | continue; |
| 3712 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3713 | |
| 3714 | // The simple case: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3715 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3716 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3717 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3718 | Outputs.addArgument(Out); |
| 3719 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3720 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3721 | return false; |
| 3722 | |
| 3723 | } |
| 3724 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3725 | //===----------------------------------------------------------------------===// |
| 3726 | // Type transformation |
| 3727 | //===----------------------------------------------------------------------===// |
| 3728 | |
| 3729 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3730 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3731 | if (getDerived().AlreadyTransformed(T)) |
| 3732 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3733 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3734 | // Temporary workaround. All of these transformations should |
| 3735 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3736 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3737 | getDerived().getBaseLocation()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3738 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3739 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3740 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3741 | if (!NewDI) |
| 3742 | return QualType(); |
| 3743 | |
| 3744 | return NewDI->getType(); |
| 3745 | } |
| 3746 | |
| 3747 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3748 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3749 | // Refine the base location to the type's location. |
| 3750 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3751 | getDerived().getBaseEntity()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3752 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3753 | return DI; |
| 3754 | |
| 3755 | TypeLocBuilder TLB; |
| 3756 | |
| 3757 | TypeLoc TL = DI->getTypeLoc(); |
| 3758 | TLB.reserve(TL.getFullDataSize()); |
| 3759 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3760 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3761 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3762 | return nullptr; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3763 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3764 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | template<typename Derived> |
| 3768 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3769 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3770 | switch (T.getTypeLocClass()) { |
| 3771 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3772 | #define TYPELOC(CLASS, PARENT) \ |
| 3773 | case TypeLoc::CLASS: \ |
| 3774 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3775 | T.castAs<CLASS##TypeLoc>()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3776 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3779 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3783 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3784 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3785 | /// types). This is the right thing for template instantiation, but |
| 3786 | /// probably not for other clients. |
| 3787 | template<typename Derived> |
| 3788 | QualType |
| 3789 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3790 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3791 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3792 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3793 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3794 | if (Result.isNull()) |
| 3795 | return QualType(); |
| 3796 | |
| 3797 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3798 | // FIXME: this is the right thing for template instantiation, but |
| 3799 | // probably not for other clients. |
| 3800 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3801 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3802 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3803 | // 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] | 3804 | // resulting type. |
| 3805 | if (Quals.hasObjCLifetime()) { |
| 3806 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3807 | Quals.removeObjCLifetime(); |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3808 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3809 | // Objective-C ARC: |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3810 | // A lifetime qualifier applied to a substituted template parameter |
| 3811 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3812 | const AutoType *AutoTy; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3813 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3814 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3815 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3816 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3817 | Qs.removeObjCLifetime(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3818 | Replacement |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3819 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3820 | Qs); |
| 3821 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3822 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3823 | Replacement); |
| 3824 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3825 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3826 | // 'auto' types behave the same way as template parameters. |
| 3827 | QualType Deduced = AutoTy->getDeducedType(); |
| 3828 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3829 | Qs.removeObjCLifetime(); |
| 3830 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3831 | Qs); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 3832 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(), |
| 3833 | AutoTy->isDependentType()); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3834 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3835 | } else { |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3836 | // Otherwise, complain about the addition of a qualifier to an |
| 3837 | // already-qualified type. |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3838 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3839 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3840 | << Result << R; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3841 | |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3842 | Quals.removeObjCLifetime(); |
| 3843 | } |
| 3844 | } |
| 3845 | } |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3846 | if (!Quals.empty()) { |
| 3847 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3848 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3849 | if (Result.hasLocalQualifiers()) |
| 3850 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3851 | // No location information to preserve. |
| 3852 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3853 | |
| 3854 | return Result; |
| 3855 | } |
| 3856 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3857 | template<typename Derived> |
| 3858 | TypeLoc |
| 3859 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3860 | QualType ObjectType, |
| 3861 | NamedDecl *UnqualLookup, |
| 3862 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3863 | if (getDerived().AlreadyTransformed(TL.getType())) |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3864 | return TL; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3865 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3866 | TypeSourceInfo *TSI = |
| 3867 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 3868 | if (TSI) |
| 3869 | return TSI->getTypeLoc(); |
| 3870 | return TypeLoc(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3873 | template<typename Derived> |
| 3874 | TypeSourceInfo * |
| 3875 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3876 | QualType ObjectType, |
| 3877 | NamedDecl *UnqualLookup, |
| 3878 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3879 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3880 | return TSInfo; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3881 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3882 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 3883 | UnqualLookup, SS); |
| 3884 | } |
| 3885 | |
| 3886 | template <typename Derived> |
| 3887 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 3888 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 3889 | CXXScopeSpec &SS) { |
| 3890 | QualType T = TL.getType(); |
| 3891 | assert(!getDerived().AlreadyTransformed(T)); |
| 3892 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3893 | TypeLocBuilder TLB; |
| 3894 | QualType Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3895 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3896 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3897 | TemplateSpecializationTypeLoc SpecTL = |
| 3898 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3899 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3900 | TemplateName Template |
| 3901 | = getDerived().TransformTemplateName(SS, |
| 3902 | SpecTL.getTypePtr()->getTemplateName(), |
| 3903 | SpecTL.getTemplateNameLoc(), |
| 3904 | ObjectType, UnqualLookup); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3905 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3906 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3907 | |
| 3908 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3909 | Template); |
| 3910 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3911 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3912 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3913 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3914 | TemplateName Template |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3915 | = getDerived().RebuildTemplateName(SS, |
| 3916 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3917 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3918 | ObjectType, UnqualLookup); |
| 3919 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3920 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3921 | |
| 3922 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3923 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3924 | Template, |
| 3925 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3926 | } else { |
| 3927 | // Nothing special needs to be done for these. |
| 3928 | Result = getDerived().TransformType(TLB, TL); |
| 3929 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3930 | |
| 3931 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3932 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3933 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3934 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3935 | } |
| 3936 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3937 | template <class TyLoc> static inline |
| 3938 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3939 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3940 | NewT.setNameLoc(T.getNameLoc()); |
| 3941 | return T.getType(); |
| 3942 | } |
| 3943 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3944 | template<typename Derived> |
| 3945 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3946 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3947 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3948 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3949 | if (T.needsExtraLocalData()) |
| 3950 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3951 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3952 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3953 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3954 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3955 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3956 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3957 | // FIXME: recurse? |
| 3958 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3959 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3961 | template <typename Derived> |
| 3962 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 3963 | AdjustedTypeLoc TL) { |
| 3964 | // Adjustments applied during transformation are handled elsewhere. |
| 3965 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3966 | } |
| 3967 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3968 | template<typename Derived> |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 3969 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 3970 | DecayedTypeLoc TL) { |
| 3971 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3972 | if (OriginalType.isNull()) |
| 3973 | return QualType(); |
| 3974 | |
| 3975 | QualType Result = TL.getType(); |
| 3976 | if (getDerived().AlwaysRebuild() || |
| 3977 | OriginalType != TL.getOriginalLoc().getType()) |
| 3978 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 3979 | TLB.push<DecayedTypeLoc>(Result); |
| 3980 | // Nothing to set for DecayedTypeLoc. |
| 3981 | return Result; |
| 3982 | } |
| 3983 | |
| 3984 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3985 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3986 | PointerTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3987 | QualType PointeeType |
| 3988 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3989 | if (PointeeType.isNull()) |
| 3990 | return QualType(); |
| 3991 | |
| 3992 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3993 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3994 | // A dependent pointer type 'T *' has is being transformed such |
| 3995 | // that an Objective-C class type is being replaced for 'T'. The |
| 3996 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3997 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3998 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3999 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4000 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 4001 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4002 | return Result; |
| 4003 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4004 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4005 | if (getDerived().AlwaysRebuild() || |
| 4006 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4007 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 4008 | if (Result.isNull()) |
| 4009 | return QualType(); |
| 4010 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4011 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4012 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4013 | // pointing to. |
| 4014 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4015 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4016 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 4017 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4018 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4019 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4020 | |
| 4021 | template<typename Derived> |
| 4022 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4023 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4024 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4025 | QualType PointeeType |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4026 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4027 | if (PointeeType.isNull()) |
| 4028 | return QualType(); |
| 4029 | |
| 4030 | QualType Result = TL.getType(); |
| 4031 | if (getDerived().AlwaysRebuild() || |
| 4032 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4033 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4034 | TL.getSigilLoc()); |
| 4035 | if (Result.isNull()) |
| 4036 | return QualType(); |
| 4037 | } |
| 4038 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 4039 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4040 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 4041 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4042 | } |
| 4043 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4044 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 4045 | /// don't care whether the type itself is an l-value type or an r-value |
| 4046 | /// type; we only care if the type was *written* as an l-value type |
| 4047 | /// or an r-value type. |
| 4048 | template<typename Derived> |
| 4049 | QualType |
| 4050 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4051 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4052 | const ReferenceType *T = TL.getTypePtr(); |
| 4053 | |
| 4054 | // Note that this works with the pointee-as-written. |
| 4055 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4056 | if (PointeeType.isNull()) |
| 4057 | return QualType(); |
| 4058 | |
| 4059 | QualType Result = TL.getType(); |
| 4060 | if (getDerived().AlwaysRebuild() || |
| 4061 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 4062 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 4063 | T->isSpelledAsLValue(), |
| 4064 | TL.getSigilLoc()); |
| 4065 | if (Result.isNull()) |
| 4066 | return QualType(); |
| 4067 | } |
| 4068 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4069 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4070 | // referring to. |
| 4071 | TLB.TypeWasModifiedSafely( |
| 4072 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 4073 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4074 | // r-value references can be rebuilt as l-value references. |
| 4075 | ReferenceTypeLoc NewTL; |
| 4076 | if (isa<LValueReferenceType>(Result)) |
| 4077 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 4078 | else |
| 4079 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 4080 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 4081 | |
| 4082 | return Result; |
| 4083 | } |
| 4084 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | template<typename Derived> |
| 4086 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4087 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4088 | LValueReferenceTypeLoc TL) { |
| 4089 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4090 | } |
| 4091 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | template<typename Derived> |
| 4093 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4094 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4095 | RValueReferenceTypeLoc TL) { |
| 4096 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4098 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4099 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4100 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4101 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4102 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4103 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4104 | if (PointeeType.isNull()) |
| 4105 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4106 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4107 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4108 | TypeSourceInfo *NewClsTInfo = nullptr; |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4109 | if (OldClsTInfo) { |
| 4110 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 4111 | if (!NewClsTInfo) |
| 4112 | return QualType(); |
| 4113 | } |
| 4114 | |
| 4115 | const MemberPointerType *T = TL.getTypePtr(); |
| 4116 | QualType OldClsType = QualType(T->getClass(), 0); |
| 4117 | QualType NewClsType; |
| 4118 | if (NewClsTInfo) |
| 4119 | NewClsType = NewClsTInfo->getType(); |
| 4120 | else { |
| 4121 | NewClsType = getDerived().TransformType(OldClsType); |
| 4122 | if (NewClsType.isNull()) |
| 4123 | return QualType(); |
| 4124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4126 | QualType Result = TL.getType(); |
| 4127 | if (getDerived().AlwaysRebuild() || |
| 4128 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4129 | NewClsType != OldClsType) { |
| 4130 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4131 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4132 | if (Result.isNull()) |
| 4133 | return QualType(); |
| 4134 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4135 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4136 | // If we had to adjust the pointee type when building a member pointer, make |
| 4137 | // sure to push TypeLoc info for it. |
| 4138 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 4139 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 4140 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 4141 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 4142 | } |
| 4143 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4144 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 4145 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4146 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4147 | |
| 4148 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4149 | } |
| 4150 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4151 | template<typename Derived> |
| 4152 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4153 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4154 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4155 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4156 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4157 | if (ElementType.isNull()) |
| 4158 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4159 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4160 | QualType Result = TL.getType(); |
| 4161 | if (getDerived().AlwaysRebuild() || |
| 4162 | ElementType != T->getElementType()) { |
| 4163 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4164 | T->getSizeModifier(), |
| 4165 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4166 | T->getIndexTypeCVRQualifiers(), |
| 4167 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4168 | if (Result.isNull()) |
| 4169 | return QualType(); |
| 4170 | } |
Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4171 | |
| 4172 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4173 | // a ConstantArrayType is allowed to have an element type which is a |
| 4174 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4175 | // types have the same location layout. |
| 4176 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4177 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4178 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
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 | Expr *Size = TL.getSizeExpr(); |
| 4181 | if (Size) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4182 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4183 | Sema::ConstantEvaluated); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4184 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4185 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4186 | } |
| 4187 | NewTL.setSizeExpr(Size); |
| 4188 | |
| 4189 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4192 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4193 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4194 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4195 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4196 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4197 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4198 | if (ElementType.isNull()) |
| 4199 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4200 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4201 | QualType Result = TL.getType(); |
| 4202 | if (getDerived().AlwaysRebuild() || |
| 4203 | ElementType != T->getElementType()) { |
| 4204 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4205 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4206 | T->getIndexTypeCVRQualifiers(), |
| 4207 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4208 | if (Result.isNull()) |
| 4209 | return QualType(); |
| 4210 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4211 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4212 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4213 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4214 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4215 | NewTL.setSizeExpr(nullptr); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4216 | |
| 4217 | return Result; |
| 4218 | } |
| 4219 | |
| 4220 | template<typename Derived> |
| 4221 | QualType |
| 4222 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4223 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4224 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4225 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4226 | if (ElementType.isNull()) |
| 4227 | return QualType(); |
| 4228 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4229 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4230 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 4231 | if (SizeResult.isInvalid()) |
| 4232 | return QualType(); |
| 4233 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4234 | Expr *Size = SizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4235 | |
| 4236 | QualType Result = TL.getType(); |
| 4237 | if (getDerived().AlwaysRebuild() || |
| 4238 | ElementType != T->getElementType() || |
| 4239 | Size != T->getSizeExpr()) { |
| 4240 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4241 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4242 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4243 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4244 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4245 | if (Result.isNull()) |
| 4246 | return QualType(); |
| 4247 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4248 | |
Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4249 | // We might have constant size array now, but fortunately it has the same |
| 4250 | // location layout. |
| 4251 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4252 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4253 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4254 | NewTL.setSizeExpr(Size); |
| 4255 | |
| 4256 | return Result; |
| 4257 | } |
| 4258 | |
| 4259 | template<typename Derived> |
| 4260 | QualType |
| 4261 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4262 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4263 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4264 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4265 | if (ElementType.isNull()) |
| 4266 | return QualType(); |
| 4267 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4268 | // Array bounds are constant expressions. |
| 4269 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4270 | Sema::ConstantEvaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4271 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4272 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4273 | Expr *origSize = TL.getSizeExpr(); |
| 4274 | if (!origSize) origSize = T->getSizeExpr(); |
| 4275 | |
| 4276 | ExprResult sizeResult |
| 4277 | = getDerived().TransformExpr(origSize); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4278 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4279 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4280 | return QualType(); |
| 4281 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4282 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4283 | |
| 4284 | QualType Result = TL.getType(); |
| 4285 | if (getDerived().AlwaysRebuild() || |
| 4286 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4287 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4288 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4289 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4290 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4291 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4292 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4293 | if (Result.isNull()) |
| 4294 | return QualType(); |
| 4295 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4296 | |
| 4297 | // We might have any sort of array type now, but fortunately they |
| 4298 | // all have the same location layout. |
| 4299 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4300 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4301 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4302 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4303 | |
| 4304 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4305 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4306 | |
| 4307 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4308 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4309 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4310 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4311 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4312 | |
| 4313 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4314 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4315 | if (ElementType.isNull()) |
| 4316 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4317 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4318 | // Vector sizes are constant expressions. |
| 4319 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4320 | Sema::ConstantEvaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4321 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4322 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4323 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4324 | if (Size.isInvalid()) |
| 4325 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4326 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4327 | QualType Result = TL.getType(); |
| 4328 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4329 | ElementType != T->getElementType() || |
| 4330 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4331 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4332 | Size.get(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4333 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4334 | if (Result.isNull()) |
| 4335 | return QualType(); |
| 4336 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4337 | |
| 4338 | // Result might be dependent or not. |
| 4339 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4340 | DependentSizedExtVectorTypeLoc NewTL |
| 4341 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4342 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4343 | } else { |
| 4344 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4345 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4346 | } |
| 4347 | |
| 4348 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4349 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4350 | |
| 4351 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4352 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4353 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4354 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4355 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4356 | if (ElementType.isNull()) |
| 4357 | return QualType(); |
| 4358 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4359 | QualType Result = TL.getType(); |
| 4360 | if (getDerived().AlwaysRebuild() || |
| 4361 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4362 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4363 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4364 | if (Result.isNull()) |
| 4365 | return QualType(); |
| 4366 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4367 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4368 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4369 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4370 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4371 | return Result; |
| 4372 | } |
| 4373 | |
| 4374 | template<typename Derived> |
| 4375 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4376 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4377 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4378 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4379 | if (ElementType.isNull()) |
| 4380 | return QualType(); |
| 4381 | |
| 4382 | QualType Result = TL.getType(); |
| 4383 | if (getDerived().AlwaysRebuild() || |
| 4384 | ElementType != T->getElementType()) { |
| 4385 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4386 | T->getNumElements(), |
| 4387 | /*FIXME*/ SourceLocation()); |
| 4388 | if (Result.isNull()) |
| 4389 | return QualType(); |
| 4390 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4391 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4392 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4393 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4394 | |
| 4395 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4396 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4398 | template <typename Derived> |
| 4399 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4400 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4401 | bool ExpectParameterPack) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4402 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4403 | TypeSourceInfo *NewDI = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4404 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4405 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4406 | // 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] | 4407 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4408 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4409 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4410 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4411 | TypeLocBuilder TLB; |
| 4412 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4413 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4414 | |
| 4415 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4416 | OldExpansionTL.getPatternLoc()); |
| 4417 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4418 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4419 | |
| 4420 | Result = RebuildPackExpansionType(Result, |
| 4421 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4422 | OldExpansionTL.getEllipsisLoc(), |
| 4423 | NumExpansions); |
| 4424 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4425 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4426 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4427 | PackExpansionTypeLoc NewExpansionTL |
| 4428 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4429 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4430 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4431 | } else |
| 4432 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4433 | if (!NewDI) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4434 | return nullptr; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4435 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4436 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4437 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4438 | |
| 4439 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4440 | OldParm->getDeclContext(), |
| 4441 | OldParm->getInnerLocStart(), |
| 4442 | OldParm->getLocation(), |
| 4443 | OldParm->getIdentifier(), |
| 4444 | NewDI->getType(), |
| 4445 | NewDI, |
| 4446 | OldParm->getStorageClass(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4447 | /* DefArg */ nullptr); |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4448 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4449 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4450 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | template<typename Derived> |
| 4454 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4455 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4456 | ParmVarDecl **Params, unsigned NumParams, |
| 4457 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4458 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4459 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4460 | int indexAdjustment = 0; |
| 4461 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4462 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4463 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4464 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4465 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4466 | Optional<unsigned> NumExpansions; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4467 | ParmVarDecl *NewParm = nullptr; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4468 | if (OldParm->isParameterPack()) { |
| 4469 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4470 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4472 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4473 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4474 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4475 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4476 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4477 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4478 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4479 | // Determine whether we should expand the parameter packs. |
| 4480 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4481 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4482 | Optional<unsigned> OrigNumExpansions = |
| 4483 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4484 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4485 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4486 | Pattern.getSourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4487 | Unexpanded, |
| 4488 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4489 | RetainExpansion, |
| 4490 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4491 | return true; |
| 4492 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4493 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4494 | if (ShouldExpand) { |
| 4495 | // Expand the function parameter pack into multiple, separate |
| 4496 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4497 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4498 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4499 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4500 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4501 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4502 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4503 | OrigNumExpansions, |
| 4504 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4505 | if (!NewParm) |
| 4506 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4507 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4508 | OutParamTypes.push_back(NewParm->getType()); |
| 4509 | if (PVars) |
| 4510 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4511 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4512 | |
| 4513 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4514 | // forgetting the partially-substituted parameter pack. |
| 4515 | if (RetainExpansion) { |
| 4516 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4517 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4518 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4519 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4520 | OrigNumExpansions, |
| 4521 | /*ExpectParameterPack=*/false); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4522 | if (!NewParm) |
| 4523 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4524 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4525 | OutParamTypes.push_back(NewParm->getType()); |
| 4526 | if (PVars) |
| 4527 | PVars->push_back(NewParm); |
| 4528 | } |
| 4529 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4530 | // The next parameter should have the same adjustment as the |
| 4531 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4532 | // on every push. Also, if we push nothing, the adjustment should |
| 4533 | // go down by one. |
| 4534 | indexAdjustment--; |
| 4535 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4536 | // We're done with the pack expansion. |
| 4537 | continue; |
| 4538 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4539 | |
| 4540 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4541 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4542 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4543 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4544 | indexAdjustment, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4545 | NumExpansions, |
| 4546 | /*ExpectParameterPack=*/true); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4547 | } else { |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4548 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4549 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4550 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4551 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4552 | if (!NewParm) |
| 4553 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4554 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4555 | OutParamTypes.push_back(NewParm->getType()); |
| 4556 | if (PVars) |
| 4557 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4558 | continue; |
| 4559 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4560 | |
| 4561 | // Deal with the possibility that we don't have a parameter |
| 4562 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4563 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4564 | bool IsPackExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4565 | Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4566 | QualType NewType; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4567 | if (const PackExpansionType *Expansion |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4568 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4569 | // We have a function parameter pack that may need to be expanded. |
| 4570 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4571 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4572 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4574 | // Determine whether we should expand the parameter packs. |
| 4575 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4576 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4577 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4578 | Unexpanded, |
| 4579 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4580 | RetainExpansion, |
| 4581 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4582 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4583 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4584 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4585 | if (ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4586 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4587 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4588 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4589 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4590 | QualType NewType = getDerived().TransformType(Pattern); |
| 4591 | if (NewType.isNull()) |
| 4592 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4593 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4594 | OutParamTypes.push_back(NewType); |
| 4595 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4596 | PVars->push_back(nullptr); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4597 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4598 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4599 | // We're done with the pack expansion. |
| 4600 | continue; |
| 4601 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4602 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4603 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4604 | // forgetting the partially-substituted parameter pack. |
| 4605 | if (RetainExpansion) { |
| 4606 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4607 | QualType NewType = getDerived().TransformType(Pattern); |
| 4608 | if (NewType.isNull()) |
| 4609 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4610 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4611 | OutParamTypes.push_back(NewType); |
| 4612 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4613 | PVars->push_back(nullptr); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4614 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4615 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4616 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4617 | // expansion. |
| 4618 | OldType = Expansion->getPattern(); |
| 4619 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4620 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4621 | NewType = getDerived().TransformType(OldType); |
| 4622 | } else { |
| 4623 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4624 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4625 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4626 | if (NewType.isNull()) |
| 4627 | return true; |
| 4628 | |
| 4629 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4630 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4631 | NumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4632 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4633 | OutParamTypes.push_back(NewType); |
| 4634 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4635 | PVars->push_back(nullptr); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4638 | #ifndef NDEBUG |
| 4639 | if (PVars) { |
| 4640 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4641 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4642 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4643 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4644 | #endif |
| 4645 | |
| 4646 | return false; |
| 4647 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4648 | |
| 4649 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4650 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4651 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4652 | FunctionProtoTypeLoc TL) { |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4653 | SmallVector<QualType, 4> ExceptionStorage; |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 4654 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4655 | return getDerived().TransformFunctionProtoType( |
| 4656 | TLB, TL, nullptr, 0, |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 4657 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 4658 | return This->TransformExceptionSpec(TL.getBeginLoc(), ESI, |
| 4659 | ExceptionStorage, Changed); |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4660 | }); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4661 | } |
| 4662 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4663 | template<typename Derived> template<typename Fn> |
| 4664 | QualType TreeTransform<Derived>::TransformFunctionProtoType( |
| 4665 | TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, |
| 4666 | unsigned ThisTypeQuals, Fn TransformExceptionSpec) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4667 | // Transform the parameters and return type. |
| 4668 | // |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4669 | // 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] | 4670 | // When the function has a trailing return type, we instantiate the |
| 4671 | // parameters before the return type, since the return type can then refer |
| 4672 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4673 | // |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4674 | SmallVector<QualType, 4> ParamTypes; |
| 4675 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4676 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4677 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4678 | QualType ResultType; |
| 4679 | |
Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4680 | if (T->hasTrailingReturn()) { |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4681 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4682 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4683 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4684 | return QualType(); |
| 4685 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4686 | { |
| 4687 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4688 | // If a declaration declares a member function or member function |
| 4689 | // 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] | 4690 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4691 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4692 | // declarator. |
| 4693 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4694 | |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4695 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4696 | if (ResultType.isNull()) |
| 4697 | return QualType(); |
| 4698 | } |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4699 | } |
| 4700 | else { |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4701 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4702 | if (ResultType.isNull()) |
| 4703 | return QualType(); |
| 4704 | |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4705 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4706 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4707 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4708 | return QualType(); |
| 4709 | } |
| 4710 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4711 | FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); |
| 4712 | |
| 4713 | bool EPIChanged = false; |
| 4714 | if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) |
| 4715 | return QualType(); |
| 4716 | |
| 4717 | // FIXME: Need to transform ConsumedParameters for variadic template |
| 4718 | // expansion. |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4719 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4720 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4721 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4722 | T->getNumParams() != ParamTypes.size() || |
| 4723 | !std::equal(T->param_type_begin(), T->param_type_end(), |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4724 | ParamTypes.begin()) || EPIChanged) { |
| 4725 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4726 | if (Result.isNull()) |
| 4727 | return QualType(); |
| 4728 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4729 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4730 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4731 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4732 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4733 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4734 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4735 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 4736 | NewTL.setParam(i, ParamDecls[i]); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4737 | |
| 4738 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4739 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4740 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4741 | template<typename Derived> |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4742 | bool TreeTransform<Derived>::TransformExceptionSpec( |
| 4743 | SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, |
| 4744 | SmallVectorImpl<QualType> &Exceptions, bool &Changed) { |
| 4745 | assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); |
| 4746 | |
| 4747 | // Instantiate a dynamic noexcept expression, if any. |
| 4748 | if (ESI.Type == EST_ComputedNoexcept) { |
| 4749 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 4750 | Sema::ConstantEvaluated); |
| 4751 | ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); |
| 4752 | if (NoexceptExpr.isInvalid()) |
| 4753 | return true; |
| 4754 | |
| 4755 | NoexceptExpr = getSema().CheckBooleanCondition( |
| 4756 | NoexceptExpr.get(), NoexceptExpr.get()->getLocStart()); |
| 4757 | if (NoexceptExpr.isInvalid()) |
| 4758 | return true; |
| 4759 | |
| 4760 | if (!NoexceptExpr.get()->isValueDependent()) { |
| 4761 | NoexceptExpr = getSema().VerifyIntegerConstantExpression( |
| 4762 | NoexceptExpr.get(), nullptr, |
| 4763 | diag::err_noexcept_needs_constant_expression, |
| 4764 | /*AllowFold*/false); |
| 4765 | if (NoexceptExpr.isInvalid()) |
| 4766 | return true; |
| 4767 | } |
| 4768 | |
| 4769 | if (ESI.NoexceptExpr != NoexceptExpr.get()) |
| 4770 | Changed = true; |
| 4771 | ESI.NoexceptExpr = NoexceptExpr.get(); |
| 4772 | } |
| 4773 | |
| 4774 | if (ESI.Type != EST_Dynamic) |
| 4775 | return false; |
| 4776 | |
| 4777 | // Instantiate a dynamic exception specification's type. |
| 4778 | for (QualType T : ESI.Exceptions) { |
| 4779 | if (const PackExpansionType *PackExpansion = |
| 4780 | T->getAs<PackExpansionType>()) { |
| 4781 | Changed = true; |
| 4782 | |
| 4783 | // We have a pack expansion. Instantiate it. |
| 4784 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 4785 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 4786 | Unexpanded); |
| 4787 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 4788 | |
| 4789 | // Determine whether the set of unexpanded parameter packs can and |
| 4790 | // should |
| 4791 | // be expanded. |
| 4792 | bool Expand = false; |
| 4793 | bool RetainExpansion = false; |
| 4794 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 4795 | // FIXME: Track the location of the ellipsis (and track source location |
| 4796 | // information for the types in the exception specification in general). |
| 4797 | if (getDerived().TryExpandParameterPacks( |
| 4798 | Loc, SourceRange(), Unexpanded, Expand, |
| 4799 | RetainExpansion, NumExpansions)) |
| 4800 | return true; |
| 4801 | |
| 4802 | if (!Expand) { |
| 4803 | // We can't expand this pack expansion into separate arguments yet; |
| 4804 | // just substitute into the pattern and create a new pack expansion |
| 4805 | // type. |
| 4806 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4807 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 4808 | if (U.isNull()) |
| 4809 | return true; |
| 4810 | |
| 4811 | U = SemaRef.Context.getPackExpansionType(U, NumExpansions); |
| 4812 | Exceptions.push_back(U); |
| 4813 | continue; |
| 4814 | } |
| 4815 | |
| 4816 | // Substitute into the pack expansion pattern for each slice of the |
| 4817 | // pack. |
| 4818 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 4819 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 4820 | |
| 4821 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 4822 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 4823 | return true; |
| 4824 | |
| 4825 | Exceptions.push_back(U); |
| 4826 | } |
| 4827 | } else { |
| 4828 | QualType U = getDerived().TransformType(T); |
| 4829 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 4830 | return true; |
| 4831 | if (T != U) |
| 4832 | Changed = true; |
| 4833 | |
| 4834 | Exceptions.push_back(U); |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | ESI.Exceptions = Exceptions; |
| 4839 | return false; |
| 4840 | } |
| 4841 | |
| 4842 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4843 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4844 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4845 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4846 | const FunctionNoProtoType *T = TL.getTypePtr(); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4847 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4848 | if (ResultType.isNull()) |
| 4849 | return QualType(); |
| 4850 | |
| 4851 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4852 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4853 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4854 | |
| 4855 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4856 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4857 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4858 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4859 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4860 | |
| 4861 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4862 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4863 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4864 | template<typename Derived> QualType |
| 4865 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4866 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4867 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4868 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4869 | if (!D) |
| 4870 | return QualType(); |
| 4871 | |
| 4872 | QualType Result = TL.getType(); |
| 4873 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4874 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4875 | if (Result.isNull()) |
| 4876 | return QualType(); |
| 4877 | } |
| 4878 | |
| 4879 | // We might get an arbitrary type spec type back. We should at |
| 4880 | // least always get a type spec type, though. |
| 4881 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4882 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4883 | |
| 4884 | return Result; |
| 4885 | } |
| 4886 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4887 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4888 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4889 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4890 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4891 | TypedefNameDecl *Typedef |
| 4892 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4893 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4894 | if (!Typedef) |
| 4895 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4896 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4897 | QualType Result = TL.getType(); |
| 4898 | if (getDerived().AlwaysRebuild() || |
| 4899 | Typedef != T->getDecl()) { |
| 4900 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4901 | if (Result.isNull()) |
| 4902 | return QualType(); |
| 4903 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4905 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4906 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4907 | |
| 4908 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4909 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4911 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4912 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4913 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4914 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4915 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4916 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4917 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4918 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4919 | if (E.isInvalid()) |
| 4920 | return QualType(); |
| 4921 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4922 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4923 | if (E.isInvalid()) |
| 4924 | return QualType(); |
| 4925 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4926 | QualType Result = TL.getType(); |
| 4927 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4928 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4929 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4930 | if (Result.isNull()) |
| 4931 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4932 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4933 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4934 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4935 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4936 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4937 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4938 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4939 | |
| 4940 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4941 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4942 | |
| 4943 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4944 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4945 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4946 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4947 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4948 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4949 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4951 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4952 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4953 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4954 | if (Result.isNull()) |
| 4955 | return QualType(); |
| 4956 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4957 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4958 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4959 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4960 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4961 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4962 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4963 | |
| 4964 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4965 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4966 | |
| 4967 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4968 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4969 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4970 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4971 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4972 | // decltype expressions are not potentially evaluated contexts |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4973 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4974 | nullptr, /*IsDecltype=*/ true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4975 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4976 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4977 | if (E.isInvalid()) |
| 4978 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4980 | E = getSema().ActOnDecltypeExpression(E.get()); |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4981 | if (E.isInvalid()) |
| 4982 | return QualType(); |
| 4983 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4984 | QualType Result = TL.getType(); |
| 4985 | if (getDerived().AlwaysRebuild() || |
| 4986 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4987 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4988 | if (Result.isNull()) |
| 4989 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4990 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4991 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4993 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4994 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4995 | |
| 4996 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
| 4999 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 5000 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 5001 | TypeLocBuilder &TLB, |
| 5002 | UnaryTransformTypeLoc TL) { |
| 5003 | QualType Result = TL.getType(); |
| 5004 | if (Result->isDependentType()) { |
| 5005 | const UnaryTransformType *T = TL.getTypePtr(); |
| 5006 | QualType NewBase = |
| 5007 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 5008 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 5009 | T->getUTTKind(), |
| 5010 | TL.getKWLoc()); |
| 5011 | if (Result.isNull()) |
| 5012 | return QualType(); |
| 5013 | } |
| 5014 | |
| 5015 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 5016 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5017 | NewTL.setParensRange(TL.getParensRange()); |
| 5018 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 5019 | return Result; |
| 5020 | } |
| 5021 | |
| 5022 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5023 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 5024 | AutoTypeLoc TL) { |
| 5025 | const AutoType *T = TL.getTypePtr(); |
| 5026 | QualType OldDeduced = T->getDeducedType(); |
| 5027 | QualType NewDeduced; |
| 5028 | if (!OldDeduced.isNull()) { |
| 5029 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5030 | if (NewDeduced.isNull()) |
| 5031 | return QualType(); |
| 5032 | } |
| 5033 | |
| 5034 | QualType Result = TL.getType(); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5035 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 5036 | T->isDependentType()) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 5037 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5038 | if (Result.isNull()) |
| 5039 | return QualType(); |
| 5040 | } |
| 5041 | |
| 5042 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 5043 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5044 | |
| 5045 | return Result; |
| 5046 | } |
| 5047 | |
| 5048 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5049 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5050 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5051 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5052 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5053 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5054 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5055 | if (!Record) |
| 5056 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5057 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5058 | QualType Result = TL.getType(); |
| 5059 | if (getDerived().AlwaysRebuild() || |
| 5060 | Record != T->getDecl()) { |
| 5061 | Result = getDerived().RebuildRecordType(Record); |
| 5062 | if (Result.isNull()) |
| 5063 | return QualType(); |
| 5064 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5065 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5066 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 5067 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5068 | |
| 5069 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5070 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5071 | |
| 5072 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5073 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5074 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5075 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5076 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5077 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5078 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5079 | if (!Enum) |
| 5080 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5081 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5082 | QualType Result = TL.getType(); |
| 5083 | if (getDerived().AlwaysRebuild() || |
| 5084 | Enum != T->getDecl()) { |
| 5085 | Result = getDerived().RebuildEnumType(Enum); |
| 5086 | if (Result.isNull()) |
| 5087 | return QualType(); |
| 5088 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5089 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5090 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 5091 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5092 | |
| 5093 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5094 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 5095 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5096 | template<typename Derived> |
| 5097 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 5098 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5099 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5100 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 5101 | TL.getTypePtr()->getDecl()); |
| 5102 | if (!D) return QualType(); |
| 5103 | |
| 5104 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 5105 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 5106 | return T; |
| 5107 | } |
| 5108 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5109 | template<typename Derived> |
| 5110 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5111 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5112 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5113 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5114 | } |
| 5115 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5116 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5117 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5118 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5119 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5120 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5121 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5122 | // Substitute into the replacement type, which itself might involve something |
| 5123 | // that needs to be transformed. This only tends to occur with default |
| 5124 | // template arguments of template template parameters. |
| 5125 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 5126 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 5127 | if (Replacement.isNull()) |
| 5128 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5129 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5130 | // Always canonicalize the replacement type. |
| 5131 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 5132 | QualType Result |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5133 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5134 | Replacement); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5135 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5136 | // Propagate type-source information. |
| 5137 | SubstTemplateTypeParmTypeLoc NewTL |
| 5138 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 5139 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5140 | return Result; |
| 5141 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 5145 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 5146 | TypeLocBuilder &TLB, |
| 5147 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 5148 | return TransformTypeSpecType(TLB, TL); |
| 5149 | } |
| 5150 | |
| 5151 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5152 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5153 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5154 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5155 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 5156 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5157 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 5158 | // because we can't have a dependent nested-name-specifier anyway. |
| 5159 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5160 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5161 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 5162 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5163 | if (Template.isNull()) |
| 5164 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5165 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5166 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 5167 | } |
| 5168 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 5169 | template<typename Derived> |
| 5170 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 5171 | AtomicTypeLoc TL) { |
| 5172 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5173 | if (ValueType.isNull()) |
| 5174 | return QualType(); |
| 5175 | |
| 5176 | QualType Result = TL.getType(); |
| 5177 | if (getDerived().AlwaysRebuild() || |
| 5178 | ValueType != TL.getValueLoc().getType()) { |
| 5179 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 5180 | if (Result.isNull()) |
| 5181 | return QualType(); |
| 5182 | } |
| 5183 | |
| 5184 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 5185 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5186 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5187 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5188 | |
| 5189 | return Result; |
| 5190 | } |
| 5191 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5192 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5193 | /// container that provides a \c getArgLoc() member function. |
| 5194 | /// |
| 5195 | /// This iterator is intended to be used with the iterator form of |
| 5196 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 5197 | template<typename ArgLocContainer> |
| 5198 | class TemplateArgumentLocContainerIterator { |
| 5199 | ArgLocContainer *Container; |
| 5200 | unsigned Index; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5201 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5202 | public: |
| 5203 | typedef TemplateArgumentLoc value_type; |
| 5204 | typedef TemplateArgumentLoc reference; |
| 5205 | typedef int difference_type; |
| 5206 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5207 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5208 | class pointer { |
| 5209 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5210 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5211 | public: |
| 5212 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5213 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5214 | const TemplateArgumentLoc *operator->() const { |
| 5215 | return &Arg; |
| 5216 | } |
| 5217 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5218 | |
| 5219 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5220 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5221 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5222 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 5223 | unsigned Index) |
| 5224 | : Container(&Container), Index(Index) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5225 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5226 | TemplateArgumentLocContainerIterator &operator++() { |
| 5227 | ++Index; |
| 5228 | return *this; |
| 5229 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5230 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5231 | TemplateArgumentLocContainerIterator operator++(int) { |
| 5232 | TemplateArgumentLocContainerIterator Old(*this); |
| 5233 | ++(*this); |
| 5234 | return Old; |
| 5235 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5236 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5237 | TemplateArgumentLoc operator*() const { |
| 5238 | return Container->getArgLoc(Index); |
| 5239 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5240 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5241 | pointer operator->() const { |
| 5242 | return pointer(Container->getArgLoc(Index)); |
| 5243 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5244 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5245 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5246 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5247 | return X.Container == Y.Container && X.Index == Y.Index; |
| 5248 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5249 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5250 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5251 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5252 | return !(X == Y); |
| 5253 | } |
| 5254 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5255 | |
| 5256 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5257 | template <typename Derived> |
| 5258 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 5259 | TypeLocBuilder &TLB, |
| 5260 | TemplateSpecializationTypeLoc TL, |
| 5261 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5262 | TemplateArgumentListInfo NewTemplateArgs; |
| 5263 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5264 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5265 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 5266 | ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5267 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5268 | ArgIterator(TL, TL.getNumArgs()), |
| 5269 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 5270 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5271 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5272 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 5273 | |
| 5274 | QualType Result = |
| 5275 | getDerived().RebuildTemplateSpecializationType(Template, |
| 5276 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5277 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5278 | |
| 5279 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5280 | // Specializations of template template parameters are represented as |
| 5281 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 5282 | // within a dependent context can transform them into |
| 5283 | // DependentTemplateSpecializationTypes. |
| 5284 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5285 | DependentTemplateSpecializationTypeLoc NewTL |
| 5286 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5287 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5288 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5289 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5290 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5291 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5292 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5293 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5294 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5295 | return Result; |
| 5296 | } |
| 5297 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5298 | TemplateSpecializationTypeLoc NewTL |
| 5299 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5300 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5301 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5302 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5303 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5304 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5305 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5306 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5307 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5308 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5310 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5311 | template <typename Derived> |
| 5312 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 5313 | TypeLocBuilder &TLB, |
| 5314 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 5315 | TemplateName Template, |
| 5316 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5317 | TemplateArgumentListInfo NewTemplateArgs; |
| 5318 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5319 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 5320 | typedef TemplateArgumentLocContainerIterator< |
| 5321 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5322 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5323 | ArgIterator(TL, TL.getNumArgs()), |
| 5324 | NewTemplateArgs)) |
| 5325 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5326 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5327 | // 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] | 5328 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5329 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 5330 | QualType Result |
| 5331 | = getSema().Context.getDependentTemplateSpecializationType( |
| 5332 | TL.getTypePtr()->getKeyword(), |
| 5333 | DTN->getQualifier(), |
| 5334 | DTN->getIdentifier(), |
| 5335 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5336 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5337 | DependentTemplateSpecializationTypeLoc NewTL |
| 5338 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5339 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5340 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5341 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5342 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5343 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5344 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5345 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5346 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5347 | return Result; |
| 5348 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5349 | |
| 5350 | QualType Result |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5351 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5352 | TL.getTemplateNameLoc(), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5353 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5354 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5355 | if (!Result.isNull()) { |
| 5356 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 5357 | TemplateSpecializationTypeLoc NewTL |
| 5358 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5359 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5360 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5361 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5362 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5363 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5364 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5365 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5366 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5367 | return Result; |
| 5368 | } |
| 5369 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5370 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5371 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5372 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5373 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5374 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5375 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5376 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5377 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5378 | if (TL.getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5379 | QualifierLoc |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5380 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5381 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5382 | return QualType(); |
| 5383 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5385 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 5386 | if (NamedT.isNull()) |
| 5387 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 5388 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5389 | // C++0x [dcl.type.elab]p2: |
| 5390 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 5391 | // resolves to an alias template specialization, the |
| 5392 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5393 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 5394 | if (const TemplateSpecializationType *TST = |
| 5395 | NamedT->getAs<TemplateSpecializationType>()) { |
| 5396 | TemplateName Template = TST->getTemplateName(); |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 5397 | if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( |
| 5398 | Template.getAsTemplateDecl())) { |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5399 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 5400 | diag::err_tag_reference_non_tag) << 4; |
| 5401 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 5402 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5403 | } |
| 5404 | } |
| 5405 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5406 | QualType Result = TL.getType(); |
| 5407 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5408 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5409 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5410 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5411 | T->getKeyword(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5412 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5413 | if (Result.isNull()) |
| 5414 | return QualType(); |
| 5415 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5416 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5417 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5418 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5419 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5420 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5421 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5422 | |
| 5423 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5424 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5425 | TypeLocBuilder &TLB, |
| 5426 | AttributedTypeLoc TL) { |
| 5427 | const AttributedType *oldType = TL.getTypePtr(); |
| 5428 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5429 | if (modifiedType.isNull()) |
| 5430 | return QualType(); |
| 5431 | |
| 5432 | QualType result = TL.getType(); |
| 5433 | |
| 5434 | // FIXME: dependent operand expressions? |
| 5435 | if (getDerived().AlwaysRebuild() || |
| 5436 | modifiedType != oldType->getModifiedType()) { |
| 5437 | // TODO: this is really lame; we should really be rebuilding the |
| 5438 | // equivalent type from first principles. |
| 5439 | QualType equivalentType |
| 5440 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5441 | if (equivalentType.isNull()) |
| 5442 | return QualType(); |
Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 5443 | |
| 5444 | // Check whether we can add nullability; it is only represented as |
| 5445 | // type sugar, and therefore cannot be diagnosed in any other way. |
| 5446 | if (auto nullability = oldType->getImmediateNullability()) { |
| 5447 | if (!modifiedType->canHaveNullability()) { |
| 5448 | SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer) |
Douglas Gregor | aea7afd | 2015-06-24 22:02:08 +0000 | [diff] [blame] | 5449 | << DiagNullabilityKind(*nullability, false) << modifiedType; |
Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 5450 | return QualType(); |
| 5451 | } |
| 5452 | } |
| 5453 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5454 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5455 | modifiedType, |
| 5456 | equivalentType); |
| 5457 | } |
| 5458 | |
| 5459 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5460 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5461 | if (TL.hasAttrOperand()) |
| 5462 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5463 | if (TL.hasAttrExprOperand()) |
| 5464 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5465 | else if (TL.hasAttrEnumOperand()) |
| 5466 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5467 | |
| 5468 | return result; |
| 5469 | } |
| 5470 | |
| 5471 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5472 | QualType |
| 5473 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5474 | ParenTypeLoc TL) { |
| 5475 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5476 | if (Inner.isNull()) |
| 5477 | return QualType(); |
| 5478 | |
| 5479 | QualType Result = TL.getType(); |
| 5480 | if (getDerived().AlwaysRebuild() || |
| 5481 | Inner != TL.getInnerLoc().getType()) { |
| 5482 | Result = getDerived().RebuildParenType(Inner); |
| 5483 | if (Result.isNull()) |
| 5484 | return QualType(); |
| 5485 | } |
| 5486 | |
| 5487 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5488 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5489 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5490 | return Result; |
| 5491 | } |
| 5492 | |
| 5493 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5494 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5495 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5496 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5497 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5498 | NestedNameSpecifierLoc QualifierLoc |
| 5499 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5500 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5501 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5502 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5503 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5504 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5505 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5506 | QualifierLoc, |
| 5507 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5508 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5509 | if (Result.isNull()) |
| 5510 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5511 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5512 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5513 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5514 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5515 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5516 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5517 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5518 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5519 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5520 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5521 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5522 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5523 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5524 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5525 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5526 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5527 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5528 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5529 | QualType TreeTransform<Derived>:: |
| 5530 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5531 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5532 | NestedNameSpecifierLoc QualifierLoc; |
| 5533 | if (TL.getQualifierLoc()) { |
| 5534 | QualifierLoc |
| 5535 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5536 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5537 | return QualType(); |
| 5538 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5539 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5540 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5541 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | template<typename Derived> |
| 5545 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5546 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5547 | DependentTemplateSpecializationTypeLoc TL, |
| 5548 | NestedNameSpecifierLoc QualifierLoc) { |
| 5549 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5550 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5551 | TemplateArgumentListInfo NewTemplateArgs; |
| 5552 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5553 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5554 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5555 | typedef TemplateArgumentLocContainerIterator< |
| 5556 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5557 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5558 | ArgIterator(TL, TL.getNumArgs()), |
| 5559 | NewTemplateArgs)) |
| 5560 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5561 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5562 | QualType Result |
| 5563 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5564 | QualifierLoc, |
| 5565 | T->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5566 | TL.getTemplateNameLoc(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5567 | NewTemplateArgs); |
| 5568 | if (Result.isNull()) |
| 5569 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5570 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5571 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5572 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5573 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5574 | // Copy information relevant to the template specialization. |
| 5575 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5576 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5577 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5578 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5579 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5580 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5581 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5582 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5583 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5584 | // Copy information relevant to the elaborated type. |
| 5585 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5586 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5587 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5588 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5589 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5590 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5591 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5592 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5593 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5594 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5595 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5596 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5597 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5598 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5599 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5600 | TemplateSpecializationTypeLoc SpecTL |
| 5601 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5602 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5603 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5604 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5605 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5606 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5607 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5608 | } |
| 5609 | return Result; |
| 5610 | } |
| 5611 | |
| 5612 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5613 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5614 | PackExpansionTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5615 | QualType Pattern |
| 5616 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5617 | if (Pattern.isNull()) |
| 5618 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5619 | |
| 5620 | QualType Result = TL.getType(); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5621 | if (getDerived().AlwaysRebuild() || |
| 5622 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5623 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5624 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5625 | TL.getEllipsisLoc(), |
| 5626 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5627 | if (Result.isNull()) |
| 5628 | return QualType(); |
| 5629 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5630 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5631 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5632 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5633 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5634 | } |
| 5635 | |
| 5636 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5637 | QualType |
| 5638 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5639 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5640 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5641 | TLB.pushFullCopy(TL); |
| 5642 | return TL.getType(); |
| 5643 | } |
| 5644 | |
| 5645 | template<typename Derived> |
| 5646 | QualType |
| 5647 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5648 | ObjCObjectTypeLoc TL) { |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 5649 | // Transform base type. |
| 5650 | QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); |
| 5651 | if (BaseType.isNull()) |
| 5652 | return QualType(); |
| 5653 | |
| 5654 | bool AnyChanged = BaseType != TL.getBaseLoc().getType(); |
| 5655 | |
| 5656 | // Transform type arguments. |
| 5657 | SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; |
| 5658 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { |
| 5659 | TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); |
| 5660 | TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); |
| 5661 | QualType TypeArg = TypeArgInfo->getType(); |
| 5662 | if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { |
| 5663 | AnyChanged = true; |
| 5664 | |
| 5665 | // We have a pack expansion. Instantiate it. |
| 5666 | const auto *PackExpansion = PackExpansionLoc.getType() |
| 5667 | ->castAs<PackExpansionType>(); |
| 5668 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5669 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 5670 | Unexpanded); |
| 5671 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 5672 | |
| 5673 | // Determine whether the set of unexpanded parameter packs can |
| 5674 | // and should be expanded. |
| 5675 | TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); |
| 5676 | bool Expand = false; |
| 5677 | bool RetainExpansion = false; |
| 5678 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 5679 | if (getDerived().TryExpandParameterPacks( |
| 5680 | PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), |
| 5681 | Unexpanded, Expand, RetainExpansion, NumExpansions)) |
| 5682 | return QualType(); |
| 5683 | |
| 5684 | if (!Expand) { |
| 5685 | // We can't expand this pack expansion into separate arguments yet; |
| 5686 | // just substitute into the pattern and create a new pack expansion |
| 5687 | // type. |
| 5688 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5689 | |
| 5690 | TypeLocBuilder TypeArgBuilder; |
| 5691 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 5692 | QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, |
| 5693 | PatternLoc); |
| 5694 | if (NewPatternType.isNull()) |
| 5695 | return QualType(); |
| 5696 | |
| 5697 | QualType NewExpansionType = SemaRef.Context.getPackExpansionType( |
| 5698 | NewPatternType, NumExpansions); |
| 5699 | auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); |
| 5700 | NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); |
| 5701 | NewTypeArgInfos.push_back( |
| 5702 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); |
| 5703 | continue; |
| 5704 | } |
| 5705 | |
| 5706 | // Substitute into the pack expansion pattern for each slice of the |
| 5707 | // pack. |
| 5708 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 5709 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 5710 | |
| 5711 | TypeLocBuilder TypeArgBuilder; |
| 5712 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 5713 | |
| 5714 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, |
| 5715 | PatternLoc); |
| 5716 | if (NewTypeArg.isNull()) |
| 5717 | return QualType(); |
| 5718 | |
| 5719 | NewTypeArgInfos.push_back( |
| 5720 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 5721 | } |
| 5722 | |
| 5723 | continue; |
| 5724 | } |
| 5725 | |
| 5726 | TypeLocBuilder TypeArgBuilder; |
| 5727 | TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); |
| 5728 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc); |
| 5729 | if (NewTypeArg.isNull()) |
| 5730 | return QualType(); |
| 5731 | |
| 5732 | // If nothing changed, just keep the old TypeSourceInfo. |
| 5733 | if (NewTypeArg == TypeArg) { |
| 5734 | NewTypeArgInfos.push_back(TypeArgInfo); |
| 5735 | continue; |
| 5736 | } |
| 5737 | |
| 5738 | NewTypeArgInfos.push_back( |
| 5739 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 5740 | AnyChanged = true; |
| 5741 | } |
| 5742 | |
| 5743 | QualType Result = TL.getType(); |
| 5744 | if (getDerived().AlwaysRebuild() || AnyChanged) { |
| 5745 | // Rebuild the type. |
| 5746 | Result = getDerived().RebuildObjCObjectType( |
| 5747 | BaseType, |
| 5748 | TL.getLocStart(), |
| 5749 | TL.getTypeArgsLAngleLoc(), |
| 5750 | NewTypeArgInfos, |
| 5751 | TL.getTypeArgsRAngleLoc(), |
| 5752 | TL.getProtocolLAngleLoc(), |
| 5753 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), |
| 5754 | TL.getNumProtocols()), |
| 5755 | TL.getProtocolLocs(), |
| 5756 | TL.getProtocolRAngleLoc()); |
| 5757 | |
| 5758 | if (Result.isNull()) |
| 5759 | return QualType(); |
| 5760 | } |
| 5761 | |
| 5762 | ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); |
| 5763 | assert(TL.hasBaseTypeAsWritten() && "Can't be dependent"); |
| 5764 | NewT.setHasBaseTypeAsWritten(true); |
| 5765 | NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); |
| 5766 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) |
| 5767 | NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); |
| 5768 | NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); |
| 5769 | NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 5770 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 5771 | NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 5772 | NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 5773 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5774 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5775 | |
| 5776 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5777 | QualType |
| 5778 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5779 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 5780 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 5781 | if (PointeeType.isNull()) |
| 5782 | return QualType(); |
| 5783 | |
| 5784 | QualType Result = TL.getType(); |
| 5785 | if (getDerived().AlwaysRebuild() || |
| 5786 | PointeeType != TL.getPointeeLoc().getType()) { |
| 5787 | Result = getDerived().RebuildObjCObjectPointerType(PointeeType, |
| 5788 | TL.getStarLoc()); |
| 5789 | if (Result.isNull()) |
| 5790 | return QualType(); |
| 5791 | } |
| 5792 | |
| 5793 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 5794 | NewT.setStarLoc(TL.getStarLoc()); |
| 5795 | return Result; |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5796 | } |
| 5797 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5798 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5799 | // Statement transformation |
| 5800 | //===----------------------------------------------------------------------===// |
| 5801 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5802 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5803 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5804 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5808 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5809 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5810 | return getDerived().TransformCompoundStmt(S, false); |
| 5811 | } |
| 5812 | |
| 5813 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5814 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5815 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5816 | bool IsStmtExpr) { |
Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5817 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5818 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5819 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5820 | bool SubStmtChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5821 | SmallVector<Stmt*, 8> Statements; |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5822 | for (auto *B : S->body()) { |
| 5823 | StmtResult Result = getDerived().TransformStmt(B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5824 | if (Result.isInvalid()) { |
| 5825 | // Immediately fail if this was a DeclStmt, since it's very |
| 5826 | // likely that this will cause problems for future statements. |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5827 | if (isa<DeclStmt>(B)) |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5828 | return StmtError(); |
| 5829 | |
| 5830 | // Otherwise, just keep processing substatements and fail later. |
| 5831 | SubStmtInvalid = true; |
| 5832 | continue; |
| 5833 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5834 | |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5835 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5836 | Statements.push_back(Result.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5837 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5838 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5839 | if (SubStmtInvalid) |
| 5840 | return StmtError(); |
| 5841 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5842 | if (!getDerived().AlwaysRebuild() && |
| 5843 | !SubStmtChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5844 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5845 | |
| 5846 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5847 | Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5848 | S->getRBracLoc(), |
| 5849 | IsStmtExpr); |
| 5850 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5851 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5852 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5853 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5854 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5855 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5856 | { |
Eli Friedman | 1f4f9dd | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5857 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5858 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5859 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5860 | // Transform the left-hand case value. |
| 5861 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5862 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5863 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5864 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5865 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5866 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5867 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5868 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5869 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5870 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5871 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5872 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5873 | // Build the case statement. |
| 5874 | // Case statements are always rebuilt so that they will attached to their |
| 5875 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5876 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5877 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5878 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5879 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5880 | S->getColonLoc()); |
| 5881 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5882 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5883 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5884 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5885 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5886 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5887 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5888 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5889 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5890 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5894 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5895 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5896 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5897 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5898 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5899 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5900 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5901 | // Default statements are always rebuilt |
| 5902 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5903 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5905 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5906 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5907 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5908 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5909 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5910 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5911 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5912 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5913 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5914 | S->getDecl()); |
| 5915 | if (!LD) |
| 5916 | return StmtError(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5917 | |
| 5918 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5919 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5920 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5921 | cast<LabelDecl>(LD), SourceLocation(), |
| 5922 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5923 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5924 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5925 | template <typename Derived> |
| 5926 | const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 5927 | if (!R) |
| 5928 | return R; |
| 5929 | |
| 5930 | switch (R->getKind()) { |
| 5931 | // Transform attributes with a pragma spelling by calling TransformXXXAttr. |
| 5932 | #define ATTR(X) |
| 5933 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 5934 | case attr::X: \ |
| 5935 | return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 5936 | #include "clang/Basic/AttrList.inc" |
| 5937 | default: |
| 5938 | return R; |
| 5939 | } |
| 5940 | } |
| 5941 | |
| 5942 | template <typename Derived> |
| 5943 | StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5944 | bool AttrsChanged = false; |
| 5945 | SmallVector<const Attr *, 1> Attrs; |
| 5946 | |
| 5947 | // Visit attributes and keep track if any are transformed. |
| 5948 | for (const auto *I : S->getAttrs()) { |
| 5949 | const Attr *R = getDerived().TransformAttr(I); |
| 5950 | AttrsChanged |= (I != R); |
| 5951 | Attrs.push_back(R); |
| 5952 | } |
| 5953 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5954 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5955 | if (SubStmt.isInvalid()) |
| 5956 | return StmtError(); |
| 5957 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5958 | if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5959 | return S; |
| 5960 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5961 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5962 | SubStmt.get()); |
| 5963 | } |
| 5964 | |
| 5965 | template<typename Derived> |
| 5966 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5967 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5968 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5969 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5970 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5971 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5972 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5973 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5974 | getDerived().TransformDefinition( |
| 5975 | S->getConditionVariable()->getLocation(), |
| 5976 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5977 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5978 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5979 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5980 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5981 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5982 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5983 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5984 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5985 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5986 | if (S->getCond()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5987 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5988 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5989 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5990 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5991 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5992 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5993 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5994 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5995 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5996 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5997 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5998 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5999 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6000 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6001 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6002 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6003 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6004 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6005 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6006 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6007 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6008 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6009 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6010 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6011 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6012 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6013 | Then.get() == S->getThen() && |
| 6014 | Else.get() == S->getElse()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6015 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6016 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6017 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 6018 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6019 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6023 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6024 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6025 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6026 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6027 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 6028 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6029 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 6030 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 6031 | getDerived().TransformDefinition( |
| 6032 | S->getConditionVariable()->getLocation(), |
| 6033 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 6034 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6035 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6036 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 6037 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6038 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6039 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6040 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6041 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6042 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6043 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6044 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6045 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 6046 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6047 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6048 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6049 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6050 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6051 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6052 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6053 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6054 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6055 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6056 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 6057 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6059 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6060 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6061 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6062 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6063 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6064 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6065 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 6066 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6067 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 6068 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 6069 | getDerived().TransformDefinition( |
| 6070 | S->getConditionVariable()->getLocation(), |
| 6071 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 6072 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6073 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6074 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 6075 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6076 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6077 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6078 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6079 | |
| 6080 | if (S->getCond()) { |
| 6081 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6082 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 6083 | S->getWhileLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 6084 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6085 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6086 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6087 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6088 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6090 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6091 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6092 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6093 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6094 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6095 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6096 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6097 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6098 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6099 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6100 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6101 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6102 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6103 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6104 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6105 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6106 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6107 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6109 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6110 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6111 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6112 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6113 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6114 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6115 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6116 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6117 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6118 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6119 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6120 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6121 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6122 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6123 | if (!getDerived().AlwaysRebuild() && |
| 6124 | Cond.get() == S->getCond() && |
| 6125 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6126 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6127 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6128 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 6129 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6130 | S->getRParenLoc()); |
| 6131 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6132 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6133 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6134 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6135 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6136 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6137 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6138 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6139 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6140 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6141 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6142 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6143 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6144 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6145 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6146 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 6147 | getDerived().TransformDefinition( |
| 6148 | S->getConditionVariable()->getLocation(), |
| 6149 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6150 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6151 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6152 | } else { |
| 6153 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6154 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6155 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6156 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6157 | |
| 6158 | if (S->getCond()) { |
| 6159 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6160 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 6161 | S->getForLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 6162 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6163 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6164 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6165 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6166 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6167 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6169 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6170 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6171 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6172 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6173 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6174 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6175 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6176 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6177 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6178 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 6179 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6180 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6181 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6182 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6183 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6184 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6185 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6186 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6187 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6188 | if (!getDerived().AlwaysRebuild() && |
| 6189 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6190 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6191 | Inc.get() == S->getInc() && |
| 6192 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6193 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6194 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6195 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6196 | Init.get(), FullCond, ConditionVar, |
| 6197 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6198 | } |
| 6199 | |
| 6200 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6201 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6202 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6203 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 6204 | S->getLabel()); |
| 6205 | if (!LD) |
| 6206 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6207 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6208 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6209 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6210 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6214 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6215 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6216 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6217 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6218 | return StmtError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6219 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6220 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6221 | if (!getDerived().AlwaysRebuild() && |
| 6222 | Target.get() == S->getTarget()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6223 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6224 | |
| 6225 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6226 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6230 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6231 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6232 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6233 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6234 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6235 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6236 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6237 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6238 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6239 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6240 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6241 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6242 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6243 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Richard Smith | 3b71752 | 2014-08-21 20:51:13 +0000 | [diff] [blame] | 6244 | ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 6245 | /*NotCopyInit*/false); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6246 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6247 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6248 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6249 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6250 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6251 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6252 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6253 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6254 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6255 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6256 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6257 | bool DeclChanged = false; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6258 | SmallVector<Decl *, 4> Decls; |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 6259 | for (auto *D : S->decls()) { |
| 6260 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6261 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6262 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6263 | |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 6264 | if (Transformed != D) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6265 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6266 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6267 | Decls.push_back(Transformed); |
| 6268 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6269 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6270 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6271 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6272 | |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 6273 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6274 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6275 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6276 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6277 | StmtResult |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 6278 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6279 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6280 | SmallVector<Expr*, 8> Constraints; |
| 6281 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6282 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 6283 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6284 | ExprResult AsmString; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6285 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6286 | |
| 6287 | bool ExprsChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6288 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6289 | // Go through the outputs. |
| 6290 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 6291 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6292 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6293 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6294 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6295 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6296 | // Transform the output expr. |
| 6297 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6298 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6299 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6300 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6301 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6302 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6303 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6304 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6305 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6306 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6307 | // Go through the inputs. |
| 6308 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 6309 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6310 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6311 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6312 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6313 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6314 | // Transform the input expr. |
| 6315 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6316 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6317 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6318 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6319 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6320 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6321 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6322 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6323 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6324 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6325 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6326 | return S; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6327 | |
| 6328 | // Go through the clobbers. |
| 6329 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 6330 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6331 | |
| 6332 | // No need to transform the asm string literal. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6333 | AsmString = S->getAsmString(); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 6334 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 6335 | S->isVolatile(), S->getNumOutputs(), |
| 6336 | S->getNumInputs(), Names.data(), |
| 6337 | Constraints, Exprs, AsmString.get(), |
| 6338 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6341 | template<typename Derived> |
| 6342 | StmtResult |
| 6343 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 6344 | ArrayRef<Token> AsmToks = |
| 6345 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 6346 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6347 | bool HadError = false, HadChange = false; |
| 6348 | |
| 6349 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 6350 | SmallVector<Expr*, 8> TransformedExprs; |
| 6351 | TransformedExprs.reserve(SrcExprs.size()); |
| 6352 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 6353 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 6354 | if (!Result.isUsable()) { |
| 6355 | HadError = true; |
| 6356 | } else { |
| 6357 | HadChange |= (Result.get() != SrcExprs[i]); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6358 | TransformedExprs.push_back(Result.get()); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6359 | } |
| 6360 | } |
| 6361 | |
| 6362 | if (HadError) return StmtError(); |
| 6363 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 6364 | return Owned(S); |
| 6365 | |
Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 6366 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6367 | AsmToks, S->getAsmString(), |
| 6368 | S->getNumOutputs(), S->getNumInputs(), |
| 6369 | S->getAllConstraints(), S->getClobbers(), |
| 6370 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6371 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6372 | |
| 6373 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6374 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6375 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6376 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6377 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6378 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6379 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6380 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6381 | // Transform the @catch statements (if present). |
| 6382 | bool AnyCatchChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6383 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6384 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6385 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6386 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6387 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6388 | if (Catch.get() != S->getCatchStmt(I)) |
| 6389 | AnyCatchChanged = true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6390 | CatchStmts.push_back(Catch.get()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6391 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6392 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6393 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6394 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6395 | if (S->getFinallyStmt()) { |
| 6396 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 6397 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6398 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | // If nothing changed, just retain this statement. |
| 6402 | if (!getDerived().AlwaysRebuild() && |
| 6403 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6404 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6405 | Finally.get() == S->getFinallyStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6406 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6407 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6408 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6409 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6410 | CatchStmts, Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6412 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6413 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6414 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6415 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6416 | // Transform the @catch parameter, if there is one. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6417 | VarDecl *Var = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6418 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6419 | TypeSourceInfo *TSInfo = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6420 | if (FromVar->getTypeSourceInfo()) { |
| 6421 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 6422 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6423 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6424 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6425 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6426 | QualType T; |
| 6427 | if (TSInfo) |
| 6428 | T = TSInfo->getType(); |
| 6429 | else { |
| 6430 | T = getDerived().TransformType(FromVar->getType()); |
| 6431 | if (T.isNull()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6432 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6433 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6434 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6435 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 6436 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6437 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6438 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6439 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6440 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6441 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6442 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6443 | |
| 6444 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6445 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6446 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6447 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6448 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6449 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6450 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6451 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6452 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6453 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6454 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6455 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6456 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6457 | // If nothing changed, just retain this statement. |
| 6458 | if (!getDerived().AlwaysRebuild() && |
| 6459 | Body.get() == S->getFinallyBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6460 | return S; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6461 | |
| 6462 | // Build a new statement. |
| 6463 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6464 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6465 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6466 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6467 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6468 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6469 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6470 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6471 | if (S->getThrowExpr()) { |
| 6472 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 6473 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6474 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6475 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6476 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6477 | if (!getDerived().AlwaysRebuild() && |
| 6478 | Operand.get() == S->getThrowExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6479 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6480 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6481 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6482 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6483 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6484 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6485 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6486 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6487 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6488 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6489 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6490 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6491 | return StmtError(); |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 6492 | Object = |
| 6493 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 6494 | Object.get()); |
| 6495 | if (Object.isInvalid()) |
| 6496 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6497 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6498 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6499 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6500 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6501 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6502 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6503 | // If nothing change, just retain the current statement. |
| 6504 | if (!getDerived().AlwaysRebuild() && |
| 6505 | Object.get() == S->getSynchExpr() && |
| 6506 | Body.get() == S->getSynchBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6507 | return S; |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6508 | |
| 6509 | // Build a new statement. |
| 6510 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6511 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6512 | } |
| 6513 | |
| 6514 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6515 | StmtResult |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6516 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 6517 | ObjCAutoreleasePoolStmt *S) { |
| 6518 | // Transform the body. |
| 6519 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 6520 | if (Body.isInvalid()) |
| 6521 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6522 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6523 | // If nothing changed, just retain this statement. |
| 6524 | if (!getDerived().AlwaysRebuild() && |
| 6525 | Body.get() == S->getSubStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6526 | return S; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6527 | |
| 6528 | // Build a new statement. |
| 6529 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 6530 | S->getAtLoc(), Body.get()); |
| 6531 | } |
| 6532 | |
| 6533 | template<typename Derived> |
| 6534 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6535 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6536 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6537 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6538 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6539 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6540 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6541 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6542 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6543 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6544 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6545 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6546 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6547 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6548 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6549 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6550 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6551 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6552 | // If nothing changed, just retain this statement. |
| 6553 | if (!getDerived().AlwaysRebuild() && |
| 6554 | Element.get() == S->getElement() && |
| 6555 | Collection.get() == S->getCollection() && |
| 6556 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6557 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6558 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6559 | // Build a new statement. |
| 6560 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6561 | Element.get(), |
| 6562 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6563 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6564 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6565 | } |
| 6566 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6567 | template <typename Derived> |
| 6568 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6569 | // Transform the exception declaration, if any. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6570 | VarDecl *Var = nullptr; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6571 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 6572 | TypeSourceInfo *T = |
| 6573 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 6574 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6575 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6576 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6577 | Var = getDerived().RebuildExceptionDecl( |
| 6578 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 6579 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6580 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6581 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6582 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6583 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6584 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6585 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6586 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6587 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6588 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6589 | if (!getDerived().AlwaysRebuild() && !Var && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6590 | Handler.get() == S->getHandlerBlock()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6591 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6592 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6593 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6594 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6595 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6596 | template <typename Derived> |
| 6597 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6598 | // Transform the try block itself. |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6599 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6600 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6601 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6602 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6603 | // Transform the handlers. |
| 6604 | bool HandlerChanged = false; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6605 | SmallVector<Stmt *, 8> Handlers; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6606 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6607 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6608 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6609 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6610 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6611 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6612 | Handlers.push_back(Handler.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6613 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6614 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6615 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6616 | !HandlerChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6617 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6618 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6619 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6620 | Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6621 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6622 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6623 | template<typename Derived> |
| 6624 | StmtResult |
| 6625 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6626 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6627 | if (Range.isInvalid()) |
| 6628 | return StmtError(); |
| 6629 | |
| 6630 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6631 | if (BeginEnd.isInvalid()) |
| 6632 | return StmtError(); |
| 6633 | |
| 6634 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6635 | if (Cond.isInvalid()) |
| 6636 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6637 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6638 | Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc()); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6639 | if (Cond.isInvalid()) |
| 6640 | return StmtError(); |
| 6641 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6642 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6643 | |
| 6644 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6645 | if (Inc.isInvalid()) |
| 6646 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6647 | if (Inc.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6648 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6649 | |
| 6650 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6651 | if (LoopVar.isInvalid()) |
| 6652 | return StmtError(); |
| 6653 | |
| 6654 | StmtResult NewStmt = S; |
| 6655 | if (getDerived().AlwaysRebuild() || |
| 6656 | Range.get() != S->getRangeStmt() || |
| 6657 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6658 | Cond.get() != S->getCond() || |
| 6659 | Inc.get() != S->getInc() || |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6660 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6661 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6662 | S->getColonLoc(), Range.get(), |
| 6663 | BeginEnd.get(), Cond.get(), |
| 6664 | Inc.get(), LoopVar.get(), |
| 6665 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6666 | if (NewStmt.isInvalid()) |
| 6667 | return StmtError(); |
| 6668 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6669 | |
| 6670 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6671 | if (Body.isInvalid()) |
| 6672 | return StmtError(); |
| 6673 | |
| 6674 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6675 | // 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] | 6676 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6677 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6678 | S->getColonLoc(), Range.get(), |
| 6679 | BeginEnd.get(), Cond.get(), |
| 6680 | Inc.get(), LoopVar.get(), |
| 6681 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6682 | if (NewStmt.isInvalid()) |
| 6683 | return StmtError(); |
| 6684 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6685 | |
| 6686 | if (NewStmt.get() == S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6687 | return S; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6688 | |
| 6689 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6690 | } |
| 6691 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6692 | template<typename Derived> |
| 6693 | StmtResult |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6694 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6695 | MSDependentExistsStmt *S) { |
| 6696 | // Transform the nested-name-specifier, if any. |
| 6697 | NestedNameSpecifierLoc QualifierLoc; |
| 6698 | if (S->getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6699 | QualifierLoc |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6700 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6701 | if (!QualifierLoc) |
| 6702 | return StmtError(); |
| 6703 | } |
| 6704 | |
| 6705 | // Transform the declaration name. |
| 6706 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6707 | if (NameInfo.getName()) { |
| 6708 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6709 | if (!NameInfo.getName()) |
| 6710 | return StmtError(); |
| 6711 | } |
| 6712 | |
| 6713 | // Check whether anything changed. |
| 6714 | if (!getDerived().AlwaysRebuild() && |
| 6715 | QualifierLoc == S->getQualifierLoc() && |
| 6716 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6717 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6718 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6719 | // Determine whether this name exists, if we can. |
| 6720 | CXXScopeSpec SS; |
| 6721 | SS.Adopt(QualifierLoc); |
| 6722 | bool Dependent = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6723 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6724 | case Sema::IER_Exists: |
| 6725 | if (S->isIfExists()) |
| 6726 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6727 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6728 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6729 | |
| 6730 | case Sema::IER_DoesNotExist: |
| 6731 | if (S->isIfNotExists()) |
| 6732 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6733 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6734 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6735 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6736 | case Sema::IER_Dependent: |
| 6737 | Dependent = true; |
| 6738 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6739 | |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6740 | case Sema::IER_Error: |
| 6741 | return StmtError(); |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6742 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6743 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6744 | // We need to continue with the instantiation, so do so now. |
| 6745 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6746 | if (SubStmt.isInvalid()) |
| 6747 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6748 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6749 | // If we have resolved the name, just transform to the substatement. |
| 6750 | if (!Dependent) |
| 6751 | return SubStmt; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6752 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6753 | // The name is still dependent, so build a dependent expression again. |
| 6754 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6755 | S->isIfExists(), |
| 6756 | QualifierLoc, |
| 6757 | NameInfo, |
| 6758 | SubStmt.get()); |
| 6759 | } |
| 6760 | |
| 6761 | template<typename Derived> |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6762 | ExprResult |
| 6763 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6764 | NestedNameSpecifierLoc QualifierLoc; |
| 6765 | if (E->getQualifierLoc()) { |
| 6766 | QualifierLoc |
| 6767 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6768 | if (!QualifierLoc) |
| 6769 | return ExprError(); |
| 6770 | } |
| 6771 | |
| 6772 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6773 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6774 | if (!PD) |
| 6775 | return ExprError(); |
| 6776 | |
| 6777 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6778 | if (Base.isInvalid()) |
| 6779 | return ExprError(); |
| 6780 | |
| 6781 | return new (SemaRef.getASTContext()) |
| 6782 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6783 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6784 | QualifierLoc, E->getMemberLoc()); |
| 6785 | } |
| 6786 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6787 | template <typename Derived> |
| 6788 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6789 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6790 | if (TryBlock.isInvalid()) |
| 6791 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6792 | |
| 6793 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6794 | if (Handler.isInvalid()) |
| 6795 | return StmtError(); |
| 6796 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6797 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 6798 | Handler.get() == S->getHandler()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6799 | return S; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6800 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 6801 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 6802 | TryBlock.get(), Handler.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6803 | } |
| 6804 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6805 | template <typename Derived> |
| 6806 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6807 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6808 | if (Block.isInvalid()) |
| 6809 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6810 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6811 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6812 | } |
| 6813 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6814 | template <typename Derived> |
| 6815 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6816 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6817 | if (FilterExpr.isInvalid()) |
| 6818 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6819 | |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6820 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6821 | if (Block.isInvalid()) |
| 6822 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6823 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6824 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 6825 | Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6826 | } |
| 6827 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6828 | template <typename Derived> |
| 6829 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6830 | if (isa<SEHFinallyStmt>(Handler)) |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6831 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6832 | else |
| 6833 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6834 | } |
| 6835 | |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 6836 | template<typename Derived> |
| 6837 | StmtResult |
| 6838 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 6839 | return S; |
| 6840 | } |
| 6841 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6842 | //===----------------------------------------------------------------------===// |
| 6843 | // OpenMP directive transformation |
| 6844 | //===----------------------------------------------------------------------===// |
| 6845 | template <typename Derived> |
| 6846 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 6847 | OMPExecutableDirective *D) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6848 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6849 | // Transform the clauses |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6850 | llvm::SmallVector<OMPClause *, 16> TClauses; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6851 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6852 | TClauses.reserve(Clauses.size()); |
| 6853 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6854 | I != E; ++I) { |
| 6855 | if (*I) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 6856 | getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6857 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 6858 | getDerived().getSema().EndOpenMPClause(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6859 | if (Clause) |
| 6860 | TClauses.push_back(Clause); |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6861 | } else { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 6862 | TClauses.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6863 | } |
| 6864 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6865 | StmtResult AssociatedStmt; |
| 6866 | if (D->hasAssociatedStmt()) { |
| 6867 | if (!D->getAssociatedStmt()) { |
| 6868 | return StmtError(); |
| 6869 | } |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 6870 | getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), |
| 6871 | /*CurScope=*/nullptr); |
| 6872 | StmtResult Body; |
| 6873 | { |
| 6874 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 6875 | Body = getDerived().TransformStmt( |
| 6876 | cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt()); |
| 6877 | } |
| 6878 | AssociatedStmt = |
| 6879 | getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6880 | if (AssociatedStmt.isInvalid()) { |
| 6881 | return StmtError(); |
| 6882 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6883 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6884 | if (TClauses.size() != Clauses.size()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6885 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6886 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6887 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6888 | // Transform directive name for 'omp critical' directive. |
| 6889 | DeclarationNameInfo DirName; |
| 6890 | if (D->getDirectiveKind() == OMPD_critical) { |
| 6891 | DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 6892 | DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 6893 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6894 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
| 6895 | if (D->getDirectiveKind() == OMPD_cancellation_point) { |
| 6896 | CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6897 | } else if (D->getDirectiveKind() == OMPD_cancel) { |
| 6898 | CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6899 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6900 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6901 | return getDerived().RebuildOMPExecutableDirective( |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6902 | D->getDirectiveKind(), DirName, CancelRegion, TClauses, |
| 6903 | AssociatedStmt.get(), D->getLocStart(), D->getLocEnd()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6904 | } |
| 6905 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6906 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6907 | StmtResult |
| 6908 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 6909 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6910 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| 6911 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6912 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6913 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6914 | return Res; |
| 6915 | } |
| 6916 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6917 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6918 | StmtResult |
| 6919 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 6920 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6921 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| 6922 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6923 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6924 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6925 | return Res; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6926 | } |
| 6927 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6928 | template <typename Derived> |
| 6929 | StmtResult |
| 6930 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 6931 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6932 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| 6933 | D->getLocStart()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6934 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6935 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6936 | return Res; |
| 6937 | } |
| 6938 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6939 | template <typename Derived> |
| 6940 | StmtResult |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 6941 | TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 6942 | DeclarationNameInfo DirName; |
| 6943 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, |
| 6944 | D->getLocStart()); |
| 6945 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6946 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6947 | return Res; |
| 6948 | } |
| 6949 | |
| 6950 | template <typename Derived> |
| 6951 | StmtResult |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6952 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 6953 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6954 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| 6955 | D->getLocStart()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6956 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6957 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6958 | return Res; |
| 6959 | } |
| 6960 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6961 | template <typename Derived> |
| 6962 | StmtResult |
| 6963 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 6964 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6965 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| 6966 | D->getLocStart()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6967 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6968 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6969 | return Res; |
| 6970 | } |
| 6971 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6972 | template <typename Derived> |
| 6973 | StmtResult |
| 6974 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 6975 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6976 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| 6977 | D->getLocStart()); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6978 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6979 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6980 | return Res; |
| 6981 | } |
| 6982 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6983 | template <typename Derived> |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 6984 | StmtResult |
| 6985 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 6986 | DeclarationNameInfo DirName; |
| 6987 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| 6988 | D->getLocStart()); |
| 6989 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6990 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6991 | return Res; |
| 6992 | } |
| 6993 | |
| 6994 | template <typename Derived> |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6995 | StmtResult |
| 6996 | TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 6997 | getDerived().getSema().StartOpenMPDSABlock( |
| 6998 | OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart()); |
| 6999 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7000 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7001 | return Res; |
| 7002 | } |
| 7003 | |
| 7004 | template <typename Derived> |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7005 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 7006 | OMPParallelForDirective *D) { |
| 7007 | DeclarationNameInfo DirName; |
| 7008 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| 7009 | nullptr, D->getLocStart()); |
| 7010 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7011 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7012 | return Res; |
| 7013 | } |
| 7014 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7015 | template <typename Derived> |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 7016 | StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 7017 | OMPParallelForSimdDirective *D) { |
| 7018 | DeclarationNameInfo DirName; |
| 7019 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, |
| 7020 | nullptr, D->getLocStart()); |
| 7021 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7022 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7023 | return Res; |
| 7024 | } |
| 7025 | |
| 7026 | template <typename Derived> |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7027 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 7028 | OMPParallelSectionsDirective *D) { |
| 7029 | DeclarationNameInfo DirName; |
| 7030 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| 7031 | nullptr, D->getLocStart()); |
| 7032 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7033 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7034 | return Res; |
| 7035 | } |
| 7036 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7037 | template <typename Derived> |
| 7038 | StmtResult |
| 7039 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 7040 | DeclarationNameInfo DirName; |
| 7041 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| 7042 | D->getLocStart()); |
| 7043 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7044 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7045 | return Res; |
| 7046 | } |
| 7047 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7048 | template <typename Derived> |
| 7049 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 7050 | OMPTaskyieldDirective *D) { |
| 7051 | DeclarationNameInfo DirName; |
| 7052 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| 7053 | D->getLocStart()); |
| 7054 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7055 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7056 | return Res; |
| 7057 | } |
| 7058 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 7059 | template <typename Derived> |
| 7060 | StmtResult |
| 7061 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 7062 | DeclarationNameInfo DirName; |
| 7063 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| 7064 | D->getLocStart()); |
| 7065 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7066 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7067 | return Res; |
| 7068 | } |
| 7069 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 7070 | template <typename Derived> |
| 7071 | StmtResult |
| 7072 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 7073 | DeclarationNameInfo DirName; |
| 7074 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| 7075 | D->getLocStart()); |
| 7076 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7077 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7078 | return Res; |
| 7079 | } |
| 7080 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7081 | template <typename Derived> |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 7082 | StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( |
| 7083 | OMPTaskgroupDirective *D) { |
| 7084 | DeclarationNameInfo DirName; |
| 7085 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, |
| 7086 | D->getLocStart()); |
| 7087 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7088 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7089 | return Res; |
| 7090 | } |
| 7091 | |
| 7092 | template <typename Derived> |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7093 | StmtResult |
| 7094 | TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 7095 | DeclarationNameInfo DirName; |
| 7096 | getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, |
| 7097 | D->getLocStart()); |
| 7098 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7099 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7100 | return Res; |
| 7101 | } |
| 7102 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 7103 | template <typename Derived> |
| 7104 | StmtResult |
| 7105 | TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 7106 | DeclarationNameInfo DirName; |
| 7107 | getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, |
| 7108 | D->getLocStart()); |
| 7109 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7110 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7111 | return Res; |
| 7112 | } |
| 7113 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 7114 | template <typename Derived> |
| 7115 | StmtResult |
| 7116 | TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 7117 | DeclarationNameInfo DirName; |
| 7118 | getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, |
| 7119 | D->getLocStart()); |
| 7120 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7121 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7122 | return Res; |
| 7123 | } |
| 7124 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 7125 | template <typename Derived> |
| 7126 | StmtResult |
| 7127 | TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 7128 | DeclarationNameInfo DirName; |
| 7129 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, |
| 7130 | D->getLocStart()); |
| 7131 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7132 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7133 | return Res; |
| 7134 | } |
| 7135 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7136 | template <typename Derived> |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 7137 | StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( |
| 7138 | OMPTargetDataDirective *D) { |
| 7139 | DeclarationNameInfo DirName; |
| 7140 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, |
| 7141 | D->getLocStart()); |
| 7142 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7143 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7144 | return Res; |
| 7145 | } |
| 7146 | |
| 7147 | template <typename Derived> |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7148 | StmtResult |
| 7149 | TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 7150 | DeclarationNameInfo DirName; |
| 7151 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, |
| 7152 | D->getLocStart()); |
| 7153 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7154 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7155 | return Res; |
| 7156 | } |
| 7157 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7158 | template <typename Derived> |
| 7159 | StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( |
| 7160 | OMPCancellationPointDirective *D) { |
| 7161 | DeclarationNameInfo DirName; |
| 7162 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, |
| 7163 | nullptr, D->getLocStart()); |
| 7164 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7165 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7166 | return Res; |
| 7167 | } |
| 7168 | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7169 | template <typename Derived> |
| 7170 | StmtResult |
| 7171 | TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { |
| 7172 | DeclarationNameInfo DirName; |
| 7173 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, |
| 7174 | D->getLocStart()); |
| 7175 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7176 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7177 | return Res; |
| 7178 | } |
| 7179 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7180 | //===----------------------------------------------------------------------===// |
| 7181 | // OpenMP clause transformation |
| 7182 | //===----------------------------------------------------------------------===// |
| 7183 | template <typename Derived> |
| 7184 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 7185 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 7186 | if (Cond.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7187 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7188 | return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(), |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7189 | C->getLParenLoc(), C->getLocEnd()); |
| 7190 | } |
| 7191 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7192 | template <typename Derived> |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7193 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 7194 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 7195 | if (Cond.isInvalid()) |
| 7196 | return nullptr; |
| 7197 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(), |
| 7198 | C->getLParenLoc(), C->getLocEnd()); |
| 7199 | } |
| 7200 | |
| 7201 | template <typename Derived> |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7202 | OMPClause * |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7203 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 7204 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 7205 | if (NumThreads.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7206 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7207 | return getDerived().RebuildOMPNumThreadsClause( |
| 7208 | NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7209 | } |
| 7210 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7211 | template <typename Derived> |
| 7212 | OMPClause * |
| 7213 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 7214 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 7215 | if (E.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7216 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7217 | return getDerived().RebuildOMPSafelenClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7218 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7219 | } |
| 7220 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7221 | template <typename Derived> |
| 7222 | OMPClause * |
| 7223 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 7224 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 7225 | if (E.isInvalid()) |
| 7226 | return 0; |
| 7227 | return getDerived().RebuildOMPCollapseClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7228 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7229 | } |
| 7230 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7231 | template <typename Derived> |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7232 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7233 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7234 | return getDerived().RebuildOMPDefaultClause( |
| 7235 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(), |
| 7236 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7237 | } |
| 7238 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7239 | template <typename Derived> |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7240 | OMPClause * |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7241 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7242 | return getDerived().RebuildOMPProcBindClause( |
| 7243 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(), |
| 7244 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7245 | } |
| 7246 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7247 | template <typename Derived> |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7248 | OMPClause * |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7249 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 7250 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 7251 | if (E.isInvalid()) |
| 7252 | return nullptr; |
| 7253 | return getDerived().RebuildOMPScheduleClause( |
| 7254 | C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(), |
| 7255 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd()); |
| 7256 | } |
| 7257 | |
| 7258 | template <typename Derived> |
| 7259 | OMPClause * |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7260 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7261 | ExprResult E; |
| 7262 | if (auto *Num = C->getNumForLoops()) { |
| 7263 | E = getDerived().TransformExpr(Num); |
| 7264 | if (E.isInvalid()) |
| 7265 | return nullptr; |
| 7266 | } |
| 7267 | return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(), |
| 7268 | C->getLParenLoc(), E.get()); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7269 | } |
| 7270 | |
| 7271 | template <typename Derived> |
| 7272 | OMPClause * |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7273 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 7274 | // No need to rebuild this clause, no template-dependent parameters. |
| 7275 | return C; |
| 7276 | } |
| 7277 | |
| 7278 | template <typename Derived> |
| 7279 | OMPClause * |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7280 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 7281 | // No need to rebuild this clause, no template-dependent parameters. |
| 7282 | return C; |
| 7283 | } |
| 7284 | |
| 7285 | template <typename Derived> |
| 7286 | OMPClause * |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7287 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 7288 | // No need to rebuild this clause, no template-dependent parameters. |
| 7289 | return C; |
| 7290 | } |
| 7291 | |
| 7292 | template <typename Derived> |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7293 | OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 7294 | // No need to rebuild this clause, no template-dependent parameters. |
| 7295 | return C; |
| 7296 | } |
| 7297 | |
| 7298 | template <typename Derived> |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7299 | OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 7300 | // No need to rebuild this clause, no template-dependent parameters. |
| 7301 | return C; |
| 7302 | } |
| 7303 | |
| 7304 | template <typename Derived> |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7305 | OMPClause * |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7306 | TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 7307 | // No need to rebuild this clause, no template-dependent parameters. |
| 7308 | return C; |
| 7309 | } |
| 7310 | |
| 7311 | template <typename Derived> |
| 7312 | OMPClause * |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7313 | TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 7314 | // No need to rebuild this clause, no template-dependent parameters. |
| 7315 | return C; |
| 7316 | } |
| 7317 | |
| 7318 | template <typename Derived> |
| 7319 | OMPClause * |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7320 | TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 7321 | // No need to rebuild this clause, no template-dependent parameters. |
| 7322 | return C; |
| 7323 | } |
| 7324 | |
| 7325 | template <typename Derived> |
| 7326 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7327 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7328 | llvm::SmallVector<Expr *, 16> Vars; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7329 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7330 | for (auto *VE : C->varlists()) { |
| 7331 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7332 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7333 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7334 | Vars.push_back(EVar.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7335 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7336 | return getDerived().RebuildOMPPrivateClause( |
| 7337 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7338 | } |
| 7339 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7340 | template <typename Derived> |
| 7341 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 7342 | OMPFirstprivateClause *C) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7343 | llvm::SmallVector<Expr *, 16> Vars; |
| 7344 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7345 | for (auto *VE : C->varlists()) { |
| 7346 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7347 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7348 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7349 | Vars.push_back(EVar.get()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7350 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7351 | return getDerived().RebuildOMPFirstprivateClause( |
| 7352 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7353 | } |
| 7354 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7355 | template <typename Derived> |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7356 | OMPClause * |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7357 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 7358 | llvm::SmallVector<Expr *, 16> Vars; |
| 7359 | Vars.reserve(C->varlist_size()); |
| 7360 | for (auto *VE : C->varlists()) { |
| 7361 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7362 | if (EVar.isInvalid()) |
| 7363 | return nullptr; |
| 7364 | Vars.push_back(EVar.get()); |
| 7365 | } |
| 7366 | return getDerived().RebuildOMPLastprivateClause( |
| 7367 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7368 | } |
| 7369 | |
| 7370 | template <typename Derived> |
| 7371 | OMPClause * |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7372 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 7373 | llvm::SmallVector<Expr *, 16> Vars; |
| 7374 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7375 | for (auto *VE : C->varlists()) { |
| 7376 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7377 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7378 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7379 | Vars.push_back(EVar.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7380 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7381 | return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(), |
| 7382 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7383 | } |
| 7384 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7385 | template <typename Derived> |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7386 | OMPClause * |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7387 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 7388 | llvm::SmallVector<Expr *, 16> Vars; |
| 7389 | Vars.reserve(C->varlist_size()); |
| 7390 | for (auto *VE : C->varlists()) { |
| 7391 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7392 | if (EVar.isInvalid()) |
| 7393 | return nullptr; |
| 7394 | Vars.push_back(EVar.get()); |
| 7395 | } |
| 7396 | CXXScopeSpec ReductionIdScopeSpec; |
| 7397 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 7398 | |
| 7399 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 7400 | if (NameInfo.getName()) { |
| 7401 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7402 | if (!NameInfo.getName()) |
| 7403 | return nullptr; |
| 7404 | } |
| 7405 | return getDerived().RebuildOMPReductionClause( |
| 7406 | Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(), |
| 7407 | C->getLocEnd(), ReductionIdScopeSpec, NameInfo); |
| 7408 | } |
| 7409 | |
| 7410 | template <typename Derived> |
| 7411 | OMPClause * |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7412 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 7413 | llvm::SmallVector<Expr *, 16> Vars; |
| 7414 | Vars.reserve(C->varlist_size()); |
| 7415 | for (auto *VE : C->varlists()) { |
| 7416 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7417 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7418 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7419 | Vars.push_back(EVar.get()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7420 | } |
| 7421 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 7422 | if (Step.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7423 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7424 | return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(), |
| 7425 | C->getLParenLoc(), |
| 7426 | C->getColonLoc(), C->getLocEnd()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7427 | } |
| 7428 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7429 | template <typename Derived> |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7430 | OMPClause * |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7431 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 7432 | llvm::SmallVector<Expr *, 16> Vars; |
| 7433 | Vars.reserve(C->varlist_size()); |
| 7434 | for (auto *VE : C->varlists()) { |
| 7435 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7436 | if (EVar.isInvalid()) |
| 7437 | return nullptr; |
| 7438 | Vars.push_back(EVar.get()); |
| 7439 | } |
| 7440 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 7441 | if (Alignment.isInvalid()) |
| 7442 | return nullptr; |
| 7443 | return getDerived().RebuildOMPAlignedClause( |
| 7444 | Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(), |
| 7445 | C->getColonLoc(), C->getLocEnd()); |
| 7446 | } |
| 7447 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7448 | template <typename Derived> |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7449 | OMPClause * |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7450 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 7451 | llvm::SmallVector<Expr *, 16> Vars; |
| 7452 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7453 | for (auto *VE : C->varlists()) { |
| 7454 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7455 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7456 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7457 | Vars.push_back(EVar.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7458 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7459 | return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(), |
| 7460 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7461 | } |
| 7462 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7463 | template <typename Derived> |
| 7464 | OMPClause * |
| 7465 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 7466 | llvm::SmallVector<Expr *, 16> Vars; |
| 7467 | Vars.reserve(C->varlist_size()); |
| 7468 | for (auto *VE : C->varlists()) { |
| 7469 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7470 | if (EVar.isInvalid()) |
| 7471 | return nullptr; |
| 7472 | Vars.push_back(EVar.get()); |
| 7473 | } |
| 7474 | return getDerived().RebuildOMPCopyprivateClause( |
| 7475 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7476 | } |
| 7477 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7478 | template <typename Derived> |
| 7479 | OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 7480 | llvm::SmallVector<Expr *, 16> Vars; |
| 7481 | Vars.reserve(C->varlist_size()); |
| 7482 | for (auto *VE : C->varlists()) { |
| 7483 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7484 | if (EVar.isInvalid()) |
| 7485 | return nullptr; |
| 7486 | Vars.push_back(EVar.get()); |
| 7487 | } |
| 7488 | return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(), |
| 7489 | C->getLParenLoc(), C->getLocEnd()); |
| 7490 | } |
| 7491 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7492 | template <typename Derived> |
| 7493 | OMPClause * |
| 7494 | TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { |
| 7495 | llvm::SmallVector<Expr *, 16> Vars; |
| 7496 | Vars.reserve(C->varlist_size()); |
| 7497 | for (auto *VE : C->varlists()) { |
| 7498 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7499 | if (EVar.isInvalid()) |
| 7500 | return nullptr; |
| 7501 | Vars.push_back(EVar.get()); |
| 7502 | } |
| 7503 | return getDerived().RebuildOMPDependClause( |
| 7504 | C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars, |
| 7505 | C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7506 | } |
| 7507 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame^] | 7508 | template <typename Derived> |
| 7509 | OMPClause * |
| 7510 | TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { |
| 7511 | ExprResult E = getDerived().TransformExpr(C->getDevice()); |
| 7512 | if (E.isInvalid()) |
| 7513 | return nullptr; |
| 7514 | return getDerived().RebuildOMPDeviceClause( |
| 7515 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7516 | } |
| 7517 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7518 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7519 | // Expression transformation |
| 7520 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7521 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7522 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7523 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 7524 | if (!E->isTypeDependent()) |
| 7525 | return E; |
| 7526 | |
| 7527 | return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| 7528 | E->getIdentType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7529 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7530 | |
| 7531 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7532 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7533 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7534 | NestedNameSpecifierLoc QualifierLoc; |
| 7535 | if (E->getQualifierLoc()) { |
| 7536 | QualifierLoc |
| 7537 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7538 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7539 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7540 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7541 | |
| 7542 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7543 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7544 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7545 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7546 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7547 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 7548 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 7549 | if (NameInfo.getName()) { |
| 7550 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7551 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7552 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 7553 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7554 | |
| 7555 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7556 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7557 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7558 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7559 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7560 | |
| 7561 | // Mark it referenced in the new context regardless. |
| 7562 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7563 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7564 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7565 | return E; |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7566 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7567 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7568 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7569 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7570 | TemplateArgs = &TransArgs; |
| 7571 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 7572 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7573 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7574 | E->getNumTemplateArgs(), |
| 7575 | TransArgs)) |
| 7576 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7577 | } |
| 7578 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7579 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7580 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7581 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7582 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7583 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7584 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7585 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7586 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7587 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7588 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7589 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7590 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7591 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7592 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7593 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7594 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7595 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7596 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7597 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7598 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7599 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7600 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7601 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7602 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7603 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7604 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7605 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7606 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7607 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7608 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7609 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7610 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7611 | } |
| 7612 | |
| 7613 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7614 | ExprResult |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 7615 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 7616 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 7617 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 7618 | return SemaRef.MaybeBindToTemporary(E); |
| 7619 | } |
| 7620 | |
| 7621 | template<typename Derived> |
| 7622 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7623 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 7624 | ExprResult ControllingExpr = |
| 7625 | getDerived().TransformExpr(E->getControllingExpr()); |
| 7626 | if (ControllingExpr.isInvalid()) |
| 7627 | return ExprError(); |
| 7628 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7629 | SmallVector<Expr *, 4> AssocExprs; |
| 7630 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7631 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 7632 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 7633 | if (TS) { |
| 7634 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 7635 | if (!AssocType) |
| 7636 | return ExprError(); |
| 7637 | AssocTypes.push_back(AssocType); |
| 7638 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7639 | AssocTypes.push_back(nullptr); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7640 | } |
| 7641 | |
| 7642 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 7643 | if (AssocExpr.isInvalid()) |
| 7644 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7645 | AssocExprs.push_back(AssocExpr.get()); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7646 | } |
| 7647 | |
| 7648 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 7649 | E->getDefaultLoc(), |
| 7650 | E->getRParenLoc(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7651 | ControllingExpr.get(), |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 7652 | AssocTypes, |
| 7653 | AssocExprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | template<typename Derived> |
| 7657 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7658 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7659 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7660 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7661 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7663 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7664 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7665 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7666 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7667 | E->getRParen()); |
| 7668 | } |
| 7669 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7670 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 7671 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 7672 | /// object available. |
| 7673 | template<typename Derived> |
| 7674 | ExprResult |
| 7675 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 7676 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7677 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7678 | else |
| 7679 | return getDerived().TransformExpr(E); |
| 7680 | } |
| 7681 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 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>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 7685 | ExprResult SubExpr; |
| 7686 | if (E->getOpcode() == UO_AddrOf) |
| 7687 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 7688 | else |
| 7689 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7690 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7691 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7692 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7693 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7694 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7695 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7696 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 7697 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7698 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7699 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7700 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7701 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7702 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7703 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 7704 | // Transform the type. |
| 7705 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7706 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7707 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7708 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7709 | // Transform all of the components into components similar to what the |
| 7710 | // parser uses. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7711 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 7712 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 7713 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7714 | // template code that we don't care. |
| 7715 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7716 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7717 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7718 | SmallVector<Component, 4> Components; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7719 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 7720 | const Node &ON = E->getComponent(I); |
| 7721 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 7722 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 7723 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 7724 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7725 | switch (ON.getKind()) { |
| 7726 | case Node::Array: { |
| 7727 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7728 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7729 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7730 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7731 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7732 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 7733 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7734 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7735 | break; |
| 7736 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7737 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7738 | case Node::Field: |
| 7739 | case Node::Identifier: |
| 7740 | Comp.isBrackets = false; |
| 7741 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 7742 | if (!Comp.U.IdentInfo) |
| 7743 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7744 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7745 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7746 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 7747 | case Node::Base: |
| 7748 | // Will be recomputed during the rebuild. |
| 7749 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7750 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7751 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7752 | Components.push_back(Comp); |
| 7753 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7754 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7755 | // If nothing changed, retain the existing expression. |
| 7756 | if (!getDerived().AlwaysRebuild() && |
| 7757 | Type == E->getTypeSourceInfo() && |
| 7758 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7759 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7760 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7761 | // Build a new offsetof expression. |
| 7762 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 7763 | Components.data(), Components.size(), |
| 7764 | E->getRParenLoc()); |
| 7765 | } |
| 7766 | |
| 7767 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7768 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7769 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 7770 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 7771 | "opaque value expression requires transformation"); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7772 | return E; |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7773 | } |
| 7774 | |
| 7775 | template<typename Derived> |
| 7776 | ExprResult |
Kaelyn Takata | e1f49d5 | 2014-10-27 18:07:20 +0000 | [diff] [blame] | 7777 | TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { |
| 7778 | return E; |
| 7779 | } |
| 7780 | |
| 7781 | template<typename Derived> |
| 7782 | ExprResult |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7783 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 7784 | // Rebuild the syntactic form. The original syntactic form has |
| 7785 | // opaque-value expressions in it, so strip those away and rebuild |
| 7786 | // the result. This is a really awful way of doing this, but the |
| 7787 | // better solution (rebuilding the semantic expressions and |
| 7788 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 7789 | // TreeTransform to not strip away implicit conversions. |
| 7790 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 7791 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7792 | if (result.isInvalid()) return ExprError(); |
| 7793 | |
| 7794 | // If that gives us a pseudo-object result back, the pseudo-object |
| 7795 | // expression must have been an lvalue-to-rvalue conversion which we |
| 7796 | // should reapply. |
| 7797 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7798 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7799 | |
| 7800 | return result; |
| 7801 | } |
| 7802 | |
| 7803 | template<typename Derived> |
| 7804 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7805 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 7806 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7807 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7808 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7809 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7810 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7811 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7812 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7813 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7814 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7815 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7816 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7817 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 7818 | E->getKind(), |
| 7819 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7820 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7821 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7822 | // C++0x [expr.sizeof]p1: |
| 7823 | // The operand is either an expression, which is an unevaluated operand |
| 7824 | // [...] |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7825 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7826 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7827 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7828 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 7829 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 7830 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 7831 | ExprResult SubExpr; |
| 7832 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 7833 | if (auto *DRE = |
| 7834 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 7835 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 7836 | PE, DRE, false, &RecoveryTSI); |
| 7837 | else |
| 7838 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 7839 | |
| 7840 | if (RecoveryTSI) { |
| 7841 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 7842 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 7843 | } else if (SubExpr.isInvalid()) |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7844 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7845 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7846 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7847 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7848 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7849 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 7850 | E->getOperatorLoc(), |
| 7851 | E->getKind(), |
| 7852 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7853 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7854 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7855 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7856 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7857 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7858 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7859 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7860 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7861 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7862 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7863 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7864 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7865 | |
| 7866 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7867 | if (!getDerived().AlwaysRebuild() && |
| 7868 | LHS.get() == E->getLHS() && |
| 7869 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7870 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7871 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7872 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7873 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7874 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7875 | E->getRBracketLoc()); |
| 7876 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7877 | |
| 7878 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7879 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7880 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7881 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7882 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7883 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7884 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7885 | |
| 7886 | // Transform arguments. |
| 7887 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7888 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7889 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7890 | &ArgChanged)) |
| 7891 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7892 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7893 | if (!getDerived().AlwaysRebuild() && |
| 7894 | Callee.get() == E->getCallee() && |
| 7895 | !ArgChanged) |
Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 7896 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7898 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7899 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7900 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7901 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7902 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7903 | E->getRParenLoc()); |
| 7904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7905 | |
| 7906 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7907 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7908 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7909 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7910 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7911 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7912 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7913 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7914 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7915 | QualifierLoc |
| 7916 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7917 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7918 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7919 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7920 | } |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7921 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7922 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 7923 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7924 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 7925 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7926 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7927 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7928 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7929 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 7930 | if (FoundDecl == E->getMemberDecl()) { |
| 7931 | FoundDecl = Member; |
| 7932 | } else { |
| 7933 | FoundDecl = cast_or_null<NamedDecl>( |
| 7934 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 7935 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7936 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7937 | } |
| 7938 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7939 | if (!getDerived().AlwaysRebuild() && |
| 7940 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7941 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7942 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7943 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7944 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7945 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 7946 | // Mark it referenced in the new context regardless. |
| 7947 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7948 | SemaRef.MarkMemberReferenced(E); |
| 7949 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7950 | return E; |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 7951 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7952 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7953 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7954 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7955 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 7956 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7957 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7958 | E->getNumTemplateArgs(), |
| 7959 | TransArgs)) |
| 7960 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7961 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7963 | // FIXME: Bogus source location for the operator |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7964 | SourceLocation FakeOperatorLoc = |
| 7965 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7966 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7967 | // FIXME: to do this check properly, we will need to preserve the |
| 7968 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7969 | // base (and therefore couldn't do the check) and a |
| 7970 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7971 | NamedDecl *FirstQualifierInScope = nullptr; |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7972 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7973 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7974 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7975 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7976 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7977 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7978 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7979 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7980 | (E->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7981 | ? &TransArgs : nullptr), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7982 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7983 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7984 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7985 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7986 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7987 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7988 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7989 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7990 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7991 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7992 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7993 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7994 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7995 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7996 | if (!getDerived().AlwaysRebuild() && |
| 7997 | LHS.get() == E->getLHS() && |
| 7998 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7999 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8000 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 8001 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 8002 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 8003 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8004 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8005 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8006 | } |
| 8007 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8008 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8009 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8010 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8011 | CompoundAssignOperator *E) { |
| 8012 | return getDerived().TransformBinaryOperator(E); |
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 | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8016 | ExprResult TreeTransform<Derived>:: |
| 8017 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 8018 | // Just rebuild the common and RHS expressions and see whether we |
| 8019 | // get any changes. |
| 8020 | |
| 8021 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 8022 | if (commonExpr.isInvalid()) |
| 8023 | return ExprError(); |
| 8024 | |
| 8025 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 8026 | if (rhs.isInvalid()) |
| 8027 | return ExprError(); |
| 8028 | |
| 8029 | if (!getDerived().AlwaysRebuild() && |
| 8030 | commonExpr.get() == e->getCommon() && |
| 8031 | rhs.get() == e->getFalseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8032 | return e; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8033 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8034 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8035 | e->getQuestionLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8036 | nullptr, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8037 | e->getColonLoc(), |
| 8038 | rhs.get()); |
| 8039 | } |
| 8040 | |
| 8041 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8042 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8043 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8044 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8045 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8046 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8047 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8048 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8049 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8050 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8051 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8052 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8053 | if (RHS.isInvalid()) |
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 | if (!getDerived().AlwaysRebuild() && |
| 8057 | Cond.get() == E->getCond() && |
| 8058 | LHS.get() == E->getLHS() && |
| 8059 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8060 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8061 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8062 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 8063 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8064 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 8065 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8066 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8067 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8068 | |
| 8069 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8070 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8071 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 8072 | // Implicit casts are eliminated during transformation, since they |
| 8073 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8074 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8075 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8076 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8077 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8078 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8079 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8080 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8081 | if (!Type) |
| 8082 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8083 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8084 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8085 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8086 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8087 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8089 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8090 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8091 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8092 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8093 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 8094 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8095 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8096 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8097 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8098 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8099 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8100 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8101 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8102 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8103 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 8104 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 8105 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8106 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8107 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8108 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8109 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8110 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8112 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8113 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8114 | Init.get() == E->getInitializer()) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8115 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8116 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 8117 | // Note: the expression type doesn't necessarily match the |
| 8118 | // type-as-written, but that's okay, because it should always be |
| 8119 | // derivable from the initializer. |
| 8120 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8121 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8122 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8123 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8125 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8126 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8127 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8128 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8129 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8130 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8131 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8133 | if (!getDerived().AlwaysRebuild() && |
| 8134 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8135 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8137 | // FIXME: Bad source location |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 8138 | SourceLocation FakeOperatorLoc = |
| 8139 | SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8140 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8141 | E->getAccessorLoc(), |
| 8142 | E->getAccessor()); |
| 8143 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8144 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8145 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8146 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8147 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 8148 | if (InitListExpr *Syntactic = E->getSyntacticForm()) |
| 8149 | E = Syntactic; |
| 8150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8151 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8152 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8153 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8154 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8155 | Inits, &InitChanged)) |
| 8156 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8157 | |
Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 8158 | if (!getDerived().AlwaysRebuild() && !InitChanged) { |
| 8159 | // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr |
| 8160 | // in some cases. We can't reuse it in general, because the syntactic and |
| 8161 | // semantic forms are linked, and we can't know that semantic form will |
| 8162 | // match even if the syntactic form does. |
| 8163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8164 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8165 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 8166 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8168 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8169 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8170 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8171 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8172 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8173 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 8174 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8175 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8176 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8177 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8178 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 8179 | // transform the designators. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8180 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8181 | bool ExprChanged = false; |
| 8182 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 8183 | DEnd = E->designators_end(); |
| 8184 | D != DEnd; ++D) { |
| 8185 | if (D->isFieldDesignator()) { |
| 8186 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 8187 | D->getDotLoc(), |
| 8188 | D->getFieldLoc())); |
| 8189 | continue; |
| 8190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8191 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8192 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8193 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8194 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8195 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8196 | |
| 8197 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8198 | D->getLBracketLoc())); |
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 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8201 | ArrayExprs.push_back(Index.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8202 | continue; |
| 8203 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8204 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8205 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8206 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8207 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 8208 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8209 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8210 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8211 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8212 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8213 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8214 | |
| 8215 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8216 | End.get(), |
| 8217 | D->getLBracketLoc(), |
| 8218 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8219 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8220 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 8221 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8222 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8223 | ArrayExprs.push_back(Start.get()); |
| 8224 | ArrayExprs.push_back(End.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8225 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8226 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8227 | if (!getDerived().AlwaysRebuild() && |
| 8228 | Init.get() == E->getInit() && |
| 8229 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8230 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8231 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8232 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8233 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8234 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8235 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8236 | |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 8237 | // Seems that if TransformInitListExpr() only works on the syntactic form of an |
| 8238 | // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. |
| 8239 | template<typename Derived> |
| 8240 | ExprResult |
| 8241 | TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( |
| 8242 | DesignatedInitUpdateExpr *E) { |
| 8243 | llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " |
| 8244 | "initializer"); |
| 8245 | return ExprError(); |
| 8246 | } |
| 8247 | |
| 8248 | template<typename Derived> |
| 8249 | ExprResult |
| 8250 | TreeTransform<Derived>::TransformNoInitExpr( |
| 8251 | NoInitExpr *E) { |
| 8252 | llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); |
| 8253 | return ExprError(); |
| 8254 | } |
| 8255 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8256 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8257 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8258 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8259 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 8260 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8261 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 8262 | // FIXME: Will we ever have proper type location here? Will we actually |
| 8263 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8264 | QualType T = getDerived().TransformType(E->getType()); |
| 8265 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8266 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8267 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8268 | if (!getDerived().AlwaysRebuild() && |
| 8269 | T == E->getType()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8270 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8271 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8272 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 8273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8274 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8275 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8276 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8277 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 8278 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 8279 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8280 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8281 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8282 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8283 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8284 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8285 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8286 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 8287 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8288 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8289 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8290 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8291 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 8292 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8293 | } |
| 8294 | |
| 8295 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8296 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8297 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8298 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8299 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8300 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 8301 | &ArgumentChanged)) |
| 8302 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8304 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8305 | Inits, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8306 | E->getRParenLoc()); |
| 8307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8308 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8309 | /// \brief Transform an address-of-label expression. |
| 8310 | /// |
| 8311 | /// By default, the transformation of an address-of-label expression always |
| 8312 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 8313 | /// the corresponding label statement by semantic analysis. |
| 8314 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8315 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8316 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 8317 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 8318 | E->getLabel()); |
| 8319 | if (!LD) |
| 8320 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8321 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8322 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 8323 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8324 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8325 | |
| 8326 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8327 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8328 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8329 | SemaRef.ActOnStartStmtExpr(); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8330 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8331 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8332 | if (SubStmt.isInvalid()) { |
| 8333 | SemaRef.ActOnStmtExprError(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8334 | return ExprError(); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8335 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8336 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8337 | if (!getDerived().AlwaysRebuild() && |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8338 | SubStmt.get() == E->getSubStmt()) { |
| 8339 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 8340 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8341 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8343 | |
| 8344 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8345 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8346 | E->getRParenLoc()); |
| 8347 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8348 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8349 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8350 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8351 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8352 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8353 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8354 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8355 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8356 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8357 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8358 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8359 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8360 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8361 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8362 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8363 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8364 | if (!getDerived().AlwaysRebuild() && |
| 8365 | Cond.get() == E->getCond() && |
| 8366 | LHS.get() == E->getLHS() && |
| 8367 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8368 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8369 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8370 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8371 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8372 | E->getRParenLoc()); |
| 8373 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8374 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8375 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8376 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8377 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8378 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8379 | } |
| 8380 | |
| 8381 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8382 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8383 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8384 | switch (E->getOperator()) { |
| 8385 | case OO_New: |
| 8386 | case OO_Delete: |
| 8387 | case OO_Array_New: |
| 8388 | case OO_Array_Delete: |
| 8389 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8390 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8391 | case OO_Call: { |
| 8392 | // This is a call to an object's operator(). |
| 8393 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 8394 | |
| 8395 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8396 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8397 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8398 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8399 | |
| 8400 | // FIXME: Poor location information |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 8401 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| 8402 | static_cast<Expr *>(Object.get())->getLocEnd()); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8403 | |
| 8404 | // Transform the call arguments. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8405 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8406 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8407 | Args)) |
| 8408 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8409 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8410 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8411 | Args, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8412 | E->getLocEnd()); |
| 8413 | } |
| 8414 | |
| 8415 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 8416 | case OO_##Name: |
| 8417 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 8418 | #include "clang/Basic/OperatorKinds.def" |
| 8419 | case OO_Subscript: |
| 8420 | // Handled below. |
| 8421 | break; |
| 8422 | |
| 8423 | case OO_Conditional: |
| 8424 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8425 | |
| 8426 | case OO_None: |
| 8427 | case NUM_OVERLOADED_OPERATORS: |
| 8428 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8429 | } |
| 8430 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8431 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8432 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8433 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8434 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8435 | ExprResult First; |
| 8436 | if (E->getOperator() == OO_Amp) |
| 8437 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 8438 | else |
| 8439 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8440 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8441 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8442 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8443 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8444 | if (E->getNumArgs() == 2) { |
| 8445 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 8446 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8447 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8448 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8449 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8450 | if (!getDerived().AlwaysRebuild() && |
| 8451 | Callee.get() == E->getCallee() && |
| 8452 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8453 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8454 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8455 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 8456 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 8457 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 8458 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8459 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 8460 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8461 | Callee.get(), |
| 8462 | First.get(), |
| 8463 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8465 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8466 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8467 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8468 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 8469 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8470 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8471 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8472 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8473 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8474 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 8475 | // Transform the callee. |
| 8476 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 8477 | if (Callee.isInvalid()) |
| 8478 | return ExprError(); |
| 8479 | |
| 8480 | // Transform exec config. |
| 8481 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 8482 | if (EC.isInvalid()) |
| 8483 | return ExprError(); |
| 8484 | |
| 8485 | // Transform arguments. |
| 8486 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8487 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8488 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8489 | &ArgChanged)) |
| 8490 | return ExprError(); |
| 8491 | |
| 8492 | if (!getDerived().AlwaysRebuild() && |
| 8493 | Callee.get() == E->getCallee() && |
| 8494 | !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8495 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8496 | |
| 8497 | // FIXME: Wrong source location information for the '('. |
| 8498 | SourceLocation FakeLParenLoc |
| 8499 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 8500 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8501 | Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8502 | E->getRParenLoc(), EC.get()); |
| 8503 | } |
| 8504 | |
| 8505 | template<typename Derived> |
| 8506 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8507 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8508 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8509 | if (!Type) |
| 8510 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8511 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8512 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8513 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8514 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8515 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8516 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8517 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8518 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8519 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8520 | return E; |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 8521 | return getDerived().RebuildCXXNamedCastExpr( |
| 8522 | E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 8523 | Type, E->getAngleBrackets().getEnd(), |
| 8524 | // FIXME. this should be '(' location |
| 8525 | E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8526 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8527 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8528 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8529 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8530 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 8531 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8532 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8533 | |
| 8534 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8535 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8536 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 8537 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8538 | } |
| 8539 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8540 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8541 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8542 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8543 | CXXReinterpretCastExpr *E) { |
| 8544 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8545 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8546 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8547 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8548 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8549 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 8550 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8551 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8552 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8553 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8554 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8555 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8556 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8557 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8558 | if (!Type) |
| 8559 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8560 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8561 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8562 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8563 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8564 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8565 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8566 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8567 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8568 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8569 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8570 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8571 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 8572 | E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8573 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8574 | E->getRParenLoc()); |
| 8575 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8576 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8577 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8578 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8579 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8580 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8581 | TypeSourceInfo *TInfo |
| 8582 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 8583 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8584 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8585 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8586 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8587 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8588 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8589 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8590 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 8591 | E->getLocStart(), |
| 8592 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8593 | E->getLocEnd()); |
| 8594 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8595 | |
Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 8596 | // We don't know whether the subexpression is potentially evaluated until |
| 8597 | // after we perform semantic analysis. We speculatively assume it is |
| 8598 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8599 | // potentially evaluated. |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 8600 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 8601 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8602 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8603 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8604 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8605 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8606 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8607 | if (!getDerived().AlwaysRebuild() && |
| 8608 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8609 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8610 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8611 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 8612 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8613 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8614 | E->getLocEnd()); |
| 8615 | } |
| 8616 | |
| 8617 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8618 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8619 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 8620 | if (E->isTypeOperand()) { |
| 8621 | TypeSourceInfo *TInfo |
| 8622 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 8623 | if (!TInfo) |
| 8624 | return ExprError(); |
| 8625 | |
| 8626 | if (!getDerived().AlwaysRebuild() && |
| 8627 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8628 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8629 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 8630 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8631 | E->getLocStart(), |
| 8632 | TInfo, |
| 8633 | E->getLocEnd()); |
| 8634 | } |
| 8635 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8636 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8637 | |
| 8638 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 8639 | if (SubExpr.isInvalid()) |
| 8640 | return ExprError(); |
| 8641 | |
| 8642 | if (!getDerived().AlwaysRebuild() && |
| 8643 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8644 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8645 | |
| 8646 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 8647 | E->getLocStart(), |
| 8648 | SubExpr.get(), |
| 8649 | E->getLocEnd()); |
| 8650 | } |
| 8651 | |
| 8652 | template<typename Derived> |
| 8653 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8654 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8655 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8658 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8659 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8660 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8661 | CXXNullPtrLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8662 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8663 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8664 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8665 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8666 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8667 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 8668 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8669 | |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8670 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 8671 | // Make sure that we capture 'this'. |
| 8672 | getSema().CheckCXXThisCapture(E->getLocStart()); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8673 | return E; |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8674 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8675 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 8676 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8677 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8678 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8679 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8680 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8681 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8682 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8683 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8684 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8685 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8686 | if (!getDerived().AlwaysRebuild() && |
| 8687 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8688 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8689 | |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 8690 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 8691 | E->isThrownVariableInScope()); |
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 |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8696 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8697 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8698 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8699 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8700 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8701 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8702 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 8703 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8704 | Param == E->getParam()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8705 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8706 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 8707 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8708 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8709 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8710 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8711 | ExprResult |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8712 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 8713 | FieldDecl *Field |
| 8714 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8715 | E->getField())); |
| 8716 | if (!Field) |
| 8717 | return ExprError(); |
| 8718 | |
| 8719 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8720 | return E; |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8721 | |
| 8722 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 8723 | } |
| 8724 | |
| 8725 | template<typename Derived> |
| 8726 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8727 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 8728 | CXXScalarValueInitExpr *E) { |
| 8729 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8730 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8731 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8732 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8733 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8734 | T == E->getTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8735 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8736 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8737 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8738 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 8739 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8740 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8741 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8742 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8743 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8744 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8745 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8746 | TypeSourceInfo *AllocTypeInfo |
| 8747 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 8748 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8749 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8751 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8752 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8753 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8754 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8755 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8756 | // Transform the placement arguments (if any). |
| 8757 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8758 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8759 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8760 | E->getNumPlacementArgs(), true, |
| 8761 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8762 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8763 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8764 | // Transform the initializer (if any). |
| 8765 | Expr *OldInit = E->getInitializer(); |
| 8766 | ExprResult NewInit; |
| 8767 | if (OldInit) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 8768 | NewInit = getDerived().TransformInitializer(OldInit, true); |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8769 | if (NewInit.isInvalid()) |
| 8770 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8771 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8772 | // Transform new operator and delete operator. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8773 | FunctionDecl *OperatorNew = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8774 | if (E->getOperatorNew()) { |
| 8775 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8776 | getDerived().TransformDecl(E->getLocStart(), |
| 8777 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8778 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8779 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8780 | } |
| 8781 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8782 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8783 | if (E->getOperatorDelete()) { |
| 8784 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8785 | getDerived().TransformDecl(E->getLocStart(), |
| 8786 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8787 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8788 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8789 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8790 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8791 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8792 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8793 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8794 | NewInit.get() == OldInit && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8795 | OperatorNew == E->getOperatorNew() && |
| 8796 | OperatorDelete == E->getOperatorDelete() && |
| 8797 | !ArgumentChanged) { |
| 8798 | // Mark any declarations we need as referenced. |
| 8799 | // FIXME: instantiation-specific. |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8800 | if (OperatorNew) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8801 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8802 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8803 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8804 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8805 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8806 | QualType ElementType |
| 8807 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 8808 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 8809 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 8810 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8811 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8812 | } |
| 8813 | } |
| 8814 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8815 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8816 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8817 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8818 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8819 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8820 | if (!ArraySize.get()) { |
| 8821 | // If no array size was specified, but the new expression was |
| 8822 | // instantiated with an array type (e.g., "new T" where T is |
| 8823 | // instantiated with "int[4]"), extract the outer bound from the |
| 8824 | // array type as our array size. We do this with constant and |
| 8825 | // dependently-sized array types. |
| 8826 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 8827 | if (!ArrayT) { |
| 8828 | // Do nothing |
| 8829 | } else if (const ConstantArrayType *ConsArrayT |
| 8830 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8831 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 8832 | SemaRef.Context.getSizeType(), |
| 8833 | /*FIXME:*/ E->getLocStart()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8834 | AllocType = ConsArrayT->getElementType(); |
| 8835 | } else if (const DependentSizedArrayType *DepArrayT |
| 8836 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 8837 | if (DepArrayT->getSizeExpr()) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8838 | ArraySize = DepArrayT->getSizeExpr(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8839 | AllocType = DepArrayT->getElementType(); |
| 8840 | } |
| 8841 | } |
| 8842 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8843 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8844 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 8845 | E->isGlobalNew(), |
| 8846 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8847 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8848 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 8849 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8850 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8851 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8852 | ArraySize.get(), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8853 | E->getDirectInitRange(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8854 | NewInit.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8856 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8857 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8858 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8859 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8860 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8861 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8862 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8863 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8864 | // Transform the delete operator, if known. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8865 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8866 | if (E->getOperatorDelete()) { |
| 8867 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8868 | getDerived().TransformDecl(E->getLocStart(), |
| 8869 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8870 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8871 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8872 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8873 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8874 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8875 | Operand.get() == E->getArgument() && |
| 8876 | OperatorDelete == E->getOperatorDelete()) { |
| 8877 | // Mark any declarations we need as referenced. |
| 8878 | // FIXME: instantiation-specific. |
| 8879 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8880 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8881 | |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8882 | if (!E->getArgument()->isTypeDependent()) { |
| 8883 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 8884 | E->getDestroyedType()); |
| 8885 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 8886 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8887 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8888 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8889 | } |
| 8890 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8891 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8892 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8893 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8894 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8895 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 8896 | E->isGlobalDelete(), |
| 8897 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8898 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8900 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8901 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8902 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8903 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8904 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8905 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8906 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8907 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8908 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8909 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8910 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8911 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8912 | E->getOperatorLoc(), |
| 8913 | E->isArrow()? tok::arrow : tok::period, |
| 8914 | ObjectTypePtr, |
| 8915 | MayBePseudoDestructor); |
| 8916 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8917 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8918 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8919 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8920 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 8921 | if (QualifierLoc) { |
| 8922 | QualifierLoc |
| 8923 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 8924 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8925 | return ExprError(); |
| 8926 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8927 | CXXScopeSpec SS; |
| 8928 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8929 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8930 | PseudoDestructorTypeStorage Destroyed; |
| 8931 | if (E->getDestroyedTypeInfo()) { |
| 8932 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8933 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8934 | ObjectType, nullptr, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8935 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8936 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8937 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 8938 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8939 | // We aren't likely to be able to resolve the identifier down to a type |
| 8940 | // now anyway, so just retain the identifier. |
| 8941 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 8942 | E->getDestroyedTypeLoc()); |
| 8943 | } else { |
| 8944 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8945 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8946 | *E->getDestroyedTypeIdentifier(), |
| 8947 | E->getDestroyedTypeLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8948 | /*Scope=*/nullptr, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8949 | SS, ObjectTypePtr, |
| 8950 | false); |
| 8951 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8952 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8953 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8954 | Destroyed |
| 8955 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 8956 | E->getDestroyedTypeLoc()); |
| 8957 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8958 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8959 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8960 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 8961 | CXXScopeSpec EmptySS; |
| 8962 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8963 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8964 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8965 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8966 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8967 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8968 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8969 | E->getOperatorLoc(), |
| 8970 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8971 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8972 | ScopeTypeInfo, |
| 8973 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8974 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8975 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8976 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8977 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8978 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8979 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8980 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8981 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8982 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 8983 | Sema::LookupOrdinaryName); |
| 8984 | |
| 8985 | // Transform all the decls. |
| 8986 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 8987 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8988 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8989 | getDerived().TransformDecl(Old->getNameLoc(), |
| 8990 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8991 | if (!InstD) { |
| 8992 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8993 | // This can happen because of dependent hiding. |
| 8994 | if (isa<UsingShadowDecl>(*I)) |
| 8995 | continue; |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8996 | else { |
| 8997 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8998 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8999 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9000 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9001 | |
| 9002 | // Expand using declarations. |
| 9003 | if (isa<UsingDecl>(InstD)) { |
| 9004 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 9005 | for (auto *I : UD->shadows()) |
| 9006 | R.addDecl(I); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9007 | continue; |
| 9008 | } |
| 9009 | |
| 9010 | R.addDecl(InstD); |
| 9011 | } |
| 9012 | |
| 9013 | // Resolve a kind, but don't do any further analysis. If it's |
| 9014 | // ambiguous, the callee needs to deal with it. |
| 9015 | R.resolveKind(); |
| 9016 | |
| 9017 | // Rebuild the nested-name qualifier, if present. |
| 9018 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9019 | if (Old->getQualifierLoc()) { |
| 9020 | NestedNameSpecifierLoc QualifierLoc |
| 9021 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 9022 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9023 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9024 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9025 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9026 | } |
| 9027 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9028 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9029 | CXXRecordDecl *NamingClass |
| 9030 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 9031 | Old->getNameLoc(), |
| 9032 | Old->getNamingClass())); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9033 | if (!NamingClass) { |
| 9034 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9035 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9036 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9037 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9038 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9039 | } |
| 9040 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9041 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 9042 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 9043 | // If we have neither explicit template arguments, nor the template keyword, |
| 9044 | // it's a normal declaration name. |
| 9045 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9046 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 9047 | |
| 9048 | // If we have template arguments, rebuild them, then rebuild the |
| 9049 | // templateid expression. |
| 9050 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 9051 | if (Old->hasExplicitTemplateArgs() && |
| 9052 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9053 | Old->getNumTemplateArgs(), |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9054 | TransArgs)) { |
| 9055 | R.clear(); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9056 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9057 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9058 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9059 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 9060 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9062 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9063 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9064 | ExprResult |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9065 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 9066 | bool ArgChanged = false; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9067 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9068 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 9069 | TypeSourceInfo *From = E->getArg(I); |
| 9070 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 9071 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9072 | TypeLocBuilder TLB; |
| 9073 | TLB.reserve(FromTL.getFullDataSize()); |
| 9074 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 9075 | if (To.isNull()) |
| 9076 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9077 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9078 | if (To == From->getType()) |
| 9079 | Args.push_back(From); |
| 9080 | else { |
| 9081 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9082 | ArgChanged = true; |
| 9083 | } |
| 9084 | continue; |
| 9085 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9086 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9087 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9088 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9089 | // We have a pack expansion. Instantiate it. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 9090 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9091 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 9092 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 9093 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9094 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9095 | // Determine whether the set of unexpanded parameter packs can and should |
| 9096 | // be expanded. |
| 9097 | bool Expand = true; |
| 9098 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9099 | Optional<unsigned> OrigNumExpansions = |
| 9100 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 9101 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9102 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 9103 | PatternTL.getSourceRange(), |
| 9104 | Unexpanded, |
| 9105 | Expand, RetainExpansion, |
| 9106 | NumExpansions)) |
| 9107 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9108 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9109 | if (!Expand) { |
| 9110 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9111 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9112 | // expansion. |
| 9113 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9114 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9115 | TypeLocBuilder TLB; |
| 9116 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 9117 | |
| 9118 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9119 | if (To.isNull()) |
| 9120 | return ExprError(); |
| 9121 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9122 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9123 | PatternTL.getSourceRange(), |
| 9124 | ExpansionTL.getEllipsisLoc(), |
| 9125 | NumExpansions); |
| 9126 | if (To.isNull()) |
| 9127 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9128 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9129 | PackExpansionTypeLoc ToExpansionTL |
| 9130 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9131 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9132 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9133 | continue; |
| 9134 | } |
| 9135 | |
| 9136 | // Expand the pack expansion by substituting for each argument in the |
| 9137 | // pack(s). |
| 9138 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9139 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 9140 | TypeLocBuilder TLB; |
| 9141 | TLB.reserve(PatternTL.getFullDataSize()); |
| 9142 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9143 | if (To.isNull()) |
| 9144 | return ExprError(); |
| 9145 | |
Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 9146 | if (To->containsUnexpandedParameterPack()) { |
| 9147 | To = getDerived().RebuildPackExpansionType(To, |
| 9148 | PatternTL.getSourceRange(), |
| 9149 | ExpansionTL.getEllipsisLoc(), |
| 9150 | NumExpansions); |
| 9151 | if (To.isNull()) |
| 9152 | return ExprError(); |
| 9153 | |
| 9154 | PackExpansionTypeLoc ToExpansionTL |
| 9155 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9156 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9157 | } |
| 9158 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9159 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9160 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9161 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9162 | if (!RetainExpansion) |
| 9163 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9164 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9165 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 9166 | // forgetting the partially-substituted parameter pack. |
| 9167 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 9168 | |
| 9169 | TypeLocBuilder TLB; |
| 9170 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9171 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9172 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9173 | if (To.isNull()) |
| 9174 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9175 | |
| 9176 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9177 | PatternTL.getSourceRange(), |
| 9178 | ExpansionTL.getEllipsisLoc(), |
| 9179 | NumExpansions); |
| 9180 | if (To.isNull()) |
| 9181 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9182 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9183 | PackExpansionTypeLoc ToExpansionTL |
| 9184 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9185 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9186 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9187 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9188 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9189 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9190 | return E; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9191 | |
| 9192 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 9193 | E->getLocStart(), |
| 9194 | Args, |
| 9195 | E->getLocEnd()); |
| 9196 | } |
| 9197 | |
| 9198 | template<typename Derived> |
| 9199 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9200 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 9201 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 9202 | if (!T) |
| 9203 | return ExprError(); |
| 9204 | |
| 9205 | if (!getDerived().AlwaysRebuild() && |
| 9206 | T == E->getQueriedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9207 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9208 | |
| 9209 | ExprResult SubExpr; |
| 9210 | { |
| 9211 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 9212 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 9213 | if (SubExpr.isInvalid()) |
| 9214 | return ExprError(); |
| 9215 | |
| 9216 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9217 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9218 | } |
| 9219 | |
| 9220 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 9221 | E->getLocStart(), |
| 9222 | T, |
| 9223 | SubExpr.get(), |
| 9224 | E->getLocEnd()); |
| 9225 | } |
| 9226 | |
| 9227 | template<typename Derived> |
| 9228 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 9229 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 9230 | ExprResult SubExpr; |
| 9231 | { |
| 9232 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 9233 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 9234 | if (SubExpr.isInvalid()) |
| 9235 | return ExprError(); |
| 9236 | |
| 9237 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9238 | return E; |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 9239 | } |
| 9240 | |
| 9241 | return getDerived().RebuildExpressionTrait( |
| 9242 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 9243 | } |
| 9244 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9245 | template <typename Derived> |
| 9246 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 9247 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 9248 | TypeSourceInfo **RecoveryTSI) { |
| 9249 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 9250 | DRE, AddrTaken, RecoveryTSI); |
| 9251 | |
| 9252 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 9253 | if (!NewDRE.isUsable()) |
| 9254 | return NewDRE; |
| 9255 | |
| 9256 | // We got an expr, wrap it up in parens. |
| 9257 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 9258 | return PE; |
| 9259 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 9260 | PE->getRParen()); |
| 9261 | } |
| 9262 | |
| 9263 | template <typename Derived> |
| 9264 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 9265 | DependentScopeDeclRefExpr *E) { |
| 9266 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 9267 | nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9268 | } |
| 9269 | |
| 9270 | template<typename Derived> |
| 9271 | ExprResult |
| 9272 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 9273 | DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9274 | bool IsAddressOfOperand, |
| 9275 | TypeSourceInfo **RecoveryTSI) { |
Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 9276 | assert(E->getQualifierLoc()); |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 9277 | NestedNameSpecifierLoc QualifierLoc |
| 9278 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 9279 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9280 | return ExprError(); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9281 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9282 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9283 | // TODO: If this is a conversion-function-id, verify that the |
| 9284 | // destination type name (if present) resolves the same way after |
| 9285 | // instantiation as it did in the local scope. |
| 9286 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9287 | DeclarationNameInfo NameInfo |
| 9288 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 9289 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9290 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9291 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9292 | if (!E->hasExplicitTemplateArgs()) { |
| 9293 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 9294 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9295 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 9296 | // if name has not changed, DNLoc has not changed either. |
| 9297 | NameInfo.getName() == E->getDeclName()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9298 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9299 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9300 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 9301 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 9302 | IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 9303 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9304 | |
| 9305 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9306 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9307 | E->getNumTemplateArgs(), |
| 9308 | TransArgs)) |
| 9309 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9310 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9311 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 9312 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 9313 | RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9314 | } |
| 9315 | |
| 9316 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9317 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9318 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9319 | // CXXConstructExprs other than for list-initialization and |
| 9320 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 9321 | // a 1-argument construction we just transform that argument. |
Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 9322 | if ((E->getNumArgs() == 1 || |
| 9323 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9324 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 9325 | !E->isListInitialization()) |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 9326 | return getDerived().TransformExpr(E->getArg(0)); |
| 9327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9328 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 9329 | |
| 9330 | QualType T = getDerived().TransformType(E->getType()); |
| 9331 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9332 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9333 | |
| 9334 | CXXConstructorDecl *Constructor |
| 9335 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9336 | getDerived().TransformDecl(E->getLocStart(), |
| 9337 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9338 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9339 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9340 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9341 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9342 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9343 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9344 | &ArgumentChanged)) |
| 9345 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9346 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9347 | if (!getDerived().AlwaysRebuild() && |
| 9348 | T == E->getType() && |
| 9349 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 9350 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9351 | // Mark the constructor as referenced. |
| 9352 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9353 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9354 | return E; |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 9355 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9356 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 9357 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 9358 | Constructor, E->isElidable(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9359 | Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 9360 | E->hadMultipleCandidates(), |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9361 | E->isListInitialization(), |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 9362 | E->isStdInitListInitialization(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 9363 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 9364 | E->getConstructionKind(), |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 9365 | E->getParenOrBraceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9367 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9368 | /// \brief Transform a C++ temporary-binding expression. |
| 9369 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9370 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 9371 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9372 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9373 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9374 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9375 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9376 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9377 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 9378 | /// \brief Transform a C++ expression that contains cleanups that should |
| 9379 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9380 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 9381 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9382 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9383 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9384 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 9385 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9386 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9387 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9388 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9389 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9390 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9391 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9392 | CXXTemporaryObjectExpr *E) { |
| 9393 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9394 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9395 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9396 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9397 | CXXConstructorDecl *Constructor |
| 9398 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9399 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9400 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9401 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9402 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9403 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9404 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9405 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9406 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9407 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9408 | &ArgumentChanged)) |
| 9409 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9410 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9411 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9412 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9413 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 9414 | !ArgumentChanged) { |
| 9415 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9416 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9417 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 9418 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9419 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9420 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9421 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 9422 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9423 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9424 | E->getLocEnd()); |
| 9425 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9426 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9427 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9428 | ExprResult |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 9429 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9430 | // Transform any init-capture expressions before entering the scope of the |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9431 | // lambda body, because they are not semantically within that scope. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9432 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9433 | SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes; |
| 9434 | InitCaptureExprsAndTypes.resize(E->explicit_capture_end() - |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9435 | E->explicit_capture_begin()); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9436 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9437 | CEnd = E->capture_end(); |
| 9438 | C != CEnd; ++C) { |
James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 9439 | if (!E->isInitCapture(C)) |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9440 | continue; |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9441 | EnterExpressionEvaluationContext EEEC(getSema(), |
| 9442 | Sema::PotentiallyEvaluated); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9443 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 9444 | C->getCapturedVar()->getInit(), |
| 9445 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9446 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9447 | if (NewExprInitResult.isInvalid()) |
| 9448 | return ExprError(); |
| 9449 | Expr *NewExprInit = NewExprInitResult.get(); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9450 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9451 | VarDecl *OldVD = C->getCapturedVar(); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9452 | QualType NewInitCaptureType = |
| 9453 | getSema().performLambdaInitCaptureInitialization(C->getLocation(), |
| 9454 | OldVD->getType()->isReferenceType(), OldVD->getIdentifier(), |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9455 | NewExprInit); |
| 9456 | NewExprInitResult = NewExprInit; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9457 | InitCaptureExprsAndTypes[C - E->capture_begin()] = |
| 9458 | std::make_pair(NewExprInitResult, NewInitCaptureType); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9459 | } |
| 9460 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9461 | // Transform the template parameters, and add them to the current |
| 9462 | // instantiation scope. The null case is handled correctly. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9463 | auto TPL = getDerived().TransformTemplateParameterList( |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9464 | E->getTemplateParameterList()); |
| 9465 | |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9466 | // Transform the type of the original lambda's call operator. |
| 9467 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 9468 | // it introduces a mapping of the original to the newly created |
| 9469 | // transformed parameters. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9470 | TypeSourceInfo *NewCallOpTSI = nullptr; |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9471 | { |
| 9472 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 9473 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 9474 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9475 | |
| 9476 | TypeLocBuilder NewCallOpTLBuilder; |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 9477 | SmallVector<QualType, 4> ExceptionStorage; |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 9478 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 9479 | QualType NewCallOpType = TransformFunctionProtoType( |
| 9480 | NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0, |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 9481 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 9482 | return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, |
| 9483 | ExceptionStorage, Changed); |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 9484 | }); |
Reid Kleckner | aac43c6 | 2014-12-15 21:07:16 +0000 | [diff] [blame] | 9485 | if (NewCallOpType.isNull()) |
| 9486 | return ExprError(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9487 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 9488 | NewCallOpType); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 9489 | } |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9490 | |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9491 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
| 9492 | Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); |
| 9493 | LSI->GLTemplateParameterList = TPL; |
| 9494 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 9495 | // Create the local class that will describe the lambda. |
| 9496 | CXXRecordDecl *Class |
| 9497 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9498 | NewCallOpTSI, |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 9499 | /*KnownDependent=*/false, |
| 9500 | E->getCaptureDefault()); |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 9501 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 9502 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9503 | // Build the call operator. |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9504 | CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition( |
| 9505 | Class, E->getIntroducerRange(), NewCallOpTSI, |
| 9506 | E->getCallOperator()->getLocEnd(), |
| 9507 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams()); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9508 | LSI->CallOperator = NewCallOperator; |
Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 9509 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9510 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9511 | getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9512 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9513 | // Introduce the context of the call operator. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9514 | Sema::ContextRAII SavedContext(getSema(), NewCallOperator, |
Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 9515 | /*NewThisContext*/false); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9516 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9517 | // Enter the scope of the lambda. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9518 | getSema().buildLambdaScope(LSI, NewCallOperator, |
| 9519 | E->getIntroducerRange(), |
| 9520 | E->getCaptureDefault(), |
| 9521 | E->getCaptureDefaultLoc(), |
| 9522 | E->hasExplicitParameters(), |
| 9523 | E->hasExplicitResultType(), |
| 9524 | E->isMutable()); |
| 9525 | |
| 9526 | bool Invalid = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9527 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9528 | // Transform captures. |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9529 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9530 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9531 | CEnd = E->capture_end(); |
| 9532 | C != CEnd; ++C) { |
| 9533 | // When we hit the first implicit capture, tell Sema that we've finished |
| 9534 | // the list of explicit captures. |
| 9535 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 9536 | getSema().finishLambdaExplicitCaptures(LSI); |
| 9537 | FinishedExplicitCaptures = true; |
| 9538 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9539 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9540 | // Capturing 'this' is trivial. |
| 9541 | if (C->capturesThis()) { |
| 9542 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 9543 | continue; |
| 9544 | } |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 9545 | // Captured expression will be recaptured during captured variables |
| 9546 | // rebuilding. |
| 9547 | if (C->capturesVLAType()) |
| 9548 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9549 | |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9550 | // Rebuild init-captures, including the implied field declaration. |
James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 9551 | if (E->isInitCapture(C)) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9552 | InitCaptureInfoTy InitExprTypePair = |
| 9553 | InitCaptureExprsAndTypes[C - E->capture_begin()]; |
| 9554 | ExprResult Init = InitExprTypePair.first; |
| 9555 | QualType InitQualType = InitExprTypePair.second; |
| 9556 | if (Init.isInvalid() || InitQualType.isNull()) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9557 | Invalid = true; |
| 9558 | continue; |
| 9559 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9560 | VarDecl *OldVD = C->getCapturedVar(); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9561 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 9562 | OldVD->getLocation(), InitExprTypePair.second, |
| 9563 | OldVD->getIdentifier(), Init.get()); |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9564 | if (!NewVD) |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9565 | Invalid = true; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9566 | else { |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9567 | getDerived().transformedLocalDecl(OldVD, NewVD); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9568 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9569 | getSema().buildInitCaptureField(LSI, NewVD); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9570 | continue; |
| 9571 | } |
| 9572 | |
| 9573 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 9574 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9575 | // Determine the capture kind for Sema. |
| 9576 | Sema::TryCaptureKind Kind |
| 9577 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 9578 | : C->getCaptureKind() == LCK_ByCopy |
| 9579 | ? Sema::TryCapture_ExplicitByVal |
| 9580 | : Sema::TryCapture_ExplicitByRef; |
| 9581 | SourceLocation EllipsisLoc; |
| 9582 | if (C->isPackExpansion()) { |
| 9583 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 9584 | bool ShouldExpand = false; |
| 9585 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9586 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9587 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 9588 | C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9589 | Unexpanded, |
| 9590 | ShouldExpand, RetainExpansion, |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9591 | NumExpansions)) { |
| 9592 | Invalid = true; |
| 9593 | continue; |
| 9594 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9595 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9596 | if (ShouldExpand) { |
| 9597 | // The transform has determined that we should perform an expansion; |
| 9598 | // transform and capture each of the arguments. |
| 9599 | // expansion of the pattern. Do so. |
| 9600 | VarDecl *Pack = C->getCapturedVar(); |
| 9601 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9602 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 9603 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9604 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9605 | Pack)); |
| 9606 | if (!CapturedVar) { |
| 9607 | Invalid = true; |
| 9608 | continue; |
| 9609 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9610 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9611 | // Capture the transformed variable. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9612 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 9613 | } |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9614 | |
| 9615 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 9616 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9617 | continue; |
| 9618 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9619 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9620 | EllipsisLoc = C->getEllipsisLoc(); |
| 9621 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9622 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9623 | // Transform the captured variable. |
| 9624 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9625 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9626 | C->getCapturedVar())); |
Richard Trieu | b292604 | 2014-09-02 19:32:44 +0000 | [diff] [blame] | 9627 | if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9628 | Invalid = true; |
| 9629 | continue; |
| 9630 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9631 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9632 | // Capture the transformed variable. |
Meador Inge | 4f9dee7 | 2015-06-26 00:09:55 +0000 | [diff] [blame] | 9633 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, |
| 9634 | EllipsisLoc); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9635 | } |
| 9636 | if (!FinishedExplicitCaptures) |
| 9637 | getSema().finishLambdaExplicitCaptures(LSI); |
| 9638 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9639 | // Enter a new evaluation context to insulate the lambda from any |
| 9640 | // cleanups from the enclosing full-expression. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9641 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9642 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9643 | // Instantiate the body of the lambda expression. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9644 | StmtResult Body = |
| 9645 | Invalid ? StmtError() : getDerived().TransformStmt(E->getBody()); |
| 9646 | |
| 9647 | // ActOnLambda* will pop the function scope for us. |
| 9648 | FuncScopeCleanup.disable(); |
| 9649 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9650 | if (Body.isInvalid()) { |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9651 | SavedContext.pop(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9652 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9653 | /*IsInstantiation=*/true); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9654 | return ExprError(); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9655 | } |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 9656 | |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9657 | // Copy the LSI before ActOnFinishFunctionBody removes it. |
| 9658 | // FIXME: This is dumb. Store the lambda information somewhere that outlives |
| 9659 | // the call operator. |
| 9660 | auto LSICopy = *LSI; |
| 9661 | getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), |
| 9662 | /*IsInstantiation*/ true); |
| 9663 | SavedContext.pop(); |
| 9664 | |
| 9665 | return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(), |
| 9666 | &LSICopy); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 9667 | } |
| 9668 | |
| 9669 | template<typename Derived> |
| 9670 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9671 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9672 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9673 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9674 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9675 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9676 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9677 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9678 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9679 | Args.reserve(E->arg_size()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9680 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9681 | &ArgumentChanged)) |
| 9682 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9683 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9684 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9685 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9686 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9687 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9688 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9689 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9690 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9691 | E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9692 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9693 | E->getRParenLoc()); |
| 9694 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9695 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9696 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9697 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 9698 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9699 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9700 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9701 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9702 | Expr *OldBase; |
| 9703 | QualType BaseType; |
| 9704 | QualType ObjectType; |
| 9705 | if (!E->isImplicitAccess()) { |
| 9706 | OldBase = E->getBase(); |
| 9707 | Base = getDerived().TransformExpr(OldBase); |
| 9708 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9709 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9710 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9711 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9712 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9713 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9714 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9715 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9716 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9717 | ObjectTy, |
| 9718 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9719 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9720 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9721 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9722 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9723 | BaseType = ((Expr*) Base.get())->getType(); |
| 9724 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9725 | OldBase = nullptr; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9726 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 9727 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 9728 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9729 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9730 | // Transform the first part of the nested-name-specifier that qualifies |
| 9731 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 9732 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9733 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9734 | E->getFirstQualifierFoundInScope(), |
| 9735 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9736 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9737 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9738 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9739 | QualifierLoc |
| 9740 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 9741 | ObjectType, |
| 9742 | FirstQualifierInScope); |
| 9743 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9744 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9745 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9746 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9747 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 9748 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9749 | // TODO: If this is a conversion-function-id, verify that the |
| 9750 | // destination type name (if present) resolves the same way after |
| 9751 | // instantiation as it did in the local scope. |
| 9752 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9753 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9754 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9755 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9756 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9757 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9758 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9759 | // This is a reference to a member without an explicitly-specified |
| 9760 | // template argument list. Optimize for this common case. |
| 9761 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9762 | Base.get() == OldBase && |
| 9763 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9764 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9765 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9766 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9767 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9768 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9769 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9770 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9771 | E->isArrow(), |
| 9772 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9773 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9774 | TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9775 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9776 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9777 | /*TemplateArgs*/nullptr); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9778 | } |
| 9779 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9780 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9781 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9782 | E->getNumTemplateArgs(), |
| 9783 | TransArgs)) |
| 9784 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9785 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9786 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9787 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9788 | E->isArrow(), |
| 9789 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9790 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9791 | TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9792 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9793 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9794 | &TransArgs); |
| 9795 | } |
| 9796 | |
| 9797 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9798 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9799 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9800 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9801 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9802 | QualType BaseType; |
| 9803 | if (!Old->isImplicitAccess()) { |
| 9804 | Base = getDerived().TransformExpr(Old->getBase()); |
| 9805 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9806 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9807 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 9808 | Old->isArrow()); |
| 9809 | if (Base.isInvalid()) |
| 9810 | return ExprError(); |
| 9811 | BaseType = Base.get()->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9812 | } else { |
| 9813 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 9814 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9815 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9816 | NestedNameSpecifierLoc QualifierLoc; |
| 9817 | if (Old->getQualifierLoc()) { |
| 9818 | QualifierLoc |
| 9819 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 9820 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9821 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9822 | } |
| 9823 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9824 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 9825 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9826 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9827 | Sema::LookupOrdinaryName); |
| 9828 | |
| 9829 | // Transform all the decls. |
| 9830 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 9831 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9832 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 9833 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 9834 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9835 | if (!InstD) { |
| 9836 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 9837 | // This can happen because of dependent hiding. |
| 9838 | if (isa<UsingShadowDecl>(*I)) |
| 9839 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9840 | else { |
| 9841 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9842 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9843 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9844 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9845 | |
| 9846 | // Expand using declarations. |
| 9847 | if (isa<UsingDecl>(InstD)) { |
| 9848 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 9849 | for (auto *I : UD->shadows()) |
| 9850 | R.addDecl(I); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9851 | continue; |
| 9852 | } |
| 9853 | |
| 9854 | R.addDecl(InstD); |
| 9855 | } |
| 9856 | |
| 9857 | R.resolveKind(); |
| 9858 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9859 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 9860 | if (Old->getNamingClass()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9861 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9862 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9863 | Old->getMemberLoc(), |
| 9864 | Old->getNamingClass())); |
| 9865 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9866 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9867 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9868 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9869 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9870 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9871 | TemplateArgumentListInfo TransArgs; |
| 9872 | if (Old->hasExplicitTemplateArgs()) { |
| 9873 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 9874 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9875 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 9876 | Old->getNumTemplateArgs(), |
| 9877 | TransArgs)) |
| 9878 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9879 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9880 | |
| 9881 | // FIXME: to do this check properly, we will need to preserve the |
| 9882 | // first-qualifier-in-scope here, just in case we had a dependent |
| 9883 | // base (and therefore couldn't do the check) and a |
| 9884 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9885 | NamedDecl *FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9886 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9887 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9888 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9889 | Old->getOperatorLoc(), |
| 9890 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9891 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9892 | TemplateKWLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9893 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9894 | R, |
| 9895 | (Old->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9896 | ? &TransArgs : nullptr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9897 | } |
| 9898 | |
| 9899 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9900 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9901 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Alexis Hunt | 414e3e3 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 9902 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9903 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 9904 | if (SubExpr.isInvalid()) |
| 9905 | return ExprError(); |
| 9906 | |
| 9907 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9908 | return E; |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9909 | |
| 9910 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 9911 | } |
| 9912 | |
| 9913 | template<typename Derived> |
| 9914 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9915 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9916 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 9917 | if (Pattern.isInvalid()) |
| 9918 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9919 | |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9920 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9921 | return E; |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9922 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 9923 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 9924 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9925 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9926 | |
| 9927 | template<typename Derived> |
| 9928 | ExprResult |
| 9929 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 9930 | // If E is not value-dependent, then nothing will change when we transform it. |
| 9931 | // Note: This is an instantiation-centric view. |
| 9932 | if (!E->isValueDependent()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9933 | return E; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9934 | |
| 9935 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 9936 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9937 | // so |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9938 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 9939 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 9940 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9941 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9942 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 9943 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 9944 | ShouldExpand, RetainExpansion, |
| 9945 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9946 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9947 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9948 | if (RetainExpansion) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9949 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9950 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9951 | NamedDecl *Pack = E->getPack(); |
| 9952 | if (!ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9953 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9954 | Pack)); |
| 9955 | if (!Pack) |
| 9956 | return ExprError(); |
| 9957 | } |
| 9958 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9959 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9960 | // We now know the length of the parameter pack, so build a new expression |
| 9961 | // that stores that length. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9962 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 9963 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9964 | NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9965 | } |
| 9966 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9967 | template<typename Derived> |
| 9968 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 9969 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 9970 | SubstNonTypeTemplateParmPackExpr *E) { |
| 9971 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9972 | return E; |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 9973 | } |
| 9974 | |
| 9975 | template<typename Derived> |
| 9976 | ExprResult |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 9977 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 9978 | SubstNonTypeTemplateParmExpr *E) { |
| 9979 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9980 | return E; |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 9981 | } |
| 9982 | |
| 9983 | template<typename Derived> |
| 9984 | ExprResult |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 9985 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 9986 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9987 | return E; |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 9988 | } |
| 9989 | |
| 9990 | template<typename Derived> |
| 9991 | ExprResult |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 9992 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 9993 | MaterializeTemporaryExpr *E) { |
| 9994 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 9995 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9996 | |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 9997 | template<typename Derived> |
| 9998 | ExprResult |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 9999 | TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { |
| 10000 | Expr *Pattern = E->getPattern(); |
| 10001 | |
| 10002 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10003 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 10004 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 10005 | |
| 10006 | // Determine whether the set of unexpanded parameter packs can and should |
| 10007 | // be expanded. |
| 10008 | bool Expand = true; |
| 10009 | bool RetainExpansion = false; |
| 10010 | Optional<unsigned> NumExpansions; |
| 10011 | if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), |
| 10012 | Pattern->getSourceRange(), |
| 10013 | Unexpanded, |
| 10014 | Expand, RetainExpansion, |
| 10015 | NumExpansions)) |
| 10016 | return true; |
| 10017 | |
| 10018 | if (!Expand) { |
| 10019 | // Do not expand any packs here, just transform and rebuild a fold |
| 10020 | // expression. |
| 10021 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 10022 | |
| 10023 | ExprResult LHS = |
| 10024 | E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); |
| 10025 | if (LHS.isInvalid()) |
| 10026 | return true; |
| 10027 | |
| 10028 | ExprResult RHS = |
| 10029 | E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); |
| 10030 | if (RHS.isInvalid()) |
| 10031 | return true; |
| 10032 | |
| 10033 | if (!getDerived().AlwaysRebuild() && |
| 10034 | LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) |
| 10035 | return E; |
| 10036 | |
| 10037 | return getDerived().RebuildCXXFoldExpr( |
| 10038 | E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(), |
| 10039 | RHS.get(), E->getLocEnd()); |
| 10040 | } |
| 10041 | |
| 10042 | // The transform has determined that we should perform an elementwise |
| 10043 | // expansion of the pattern. Do so. |
| 10044 | ExprResult Result = getDerived().TransformExpr(E->getInit()); |
| 10045 | if (Result.isInvalid()) |
| 10046 | return true; |
| 10047 | bool LeftFold = E->isLeftFold(); |
| 10048 | |
| 10049 | // If we're retaining an expansion for a right fold, it is the innermost |
| 10050 | // component and takes the init (if any). |
| 10051 | if (!LeftFold && RetainExpansion) { |
| 10052 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10053 | |
| 10054 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10055 | if (Out.isInvalid()) |
| 10056 | return true; |
| 10057 | |
| 10058 | Result = getDerived().RebuildCXXFoldExpr( |
| 10059 | E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(), |
| 10060 | Result.get(), E->getLocEnd()); |
| 10061 | if (Result.isInvalid()) |
| 10062 | return true; |
| 10063 | } |
| 10064 | |
| 10065 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10066 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( |
| 10067 | getSema(), LeftFold ? I : *NumExpansions - I - 1); |
| 10068 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10069 | if (Out.isInvalid()) |
| 10070 | return true; |
| 10071 | |
| 10072 | if (Out.get()->containsUnexpandedParameterPack()) { |
| 10073 | // We still have a pack; retain a pack expansion for this slice. |
| 10074 | Result = getDerived().RebuildCXXFoldExpr( |
| 10075 | E->getLocStart(), |
| 10076 | LeftFold ? Result.get() : Out.get(), |
| 10077 | E->getOperator(), E->getEllipsisLoc(), |
| 10078 | LeftFold ? Out.get() : Result.get(), |
| 10079 | E->getLocEnd()); |
| 10080 | } else if (Result.isUsable()) { |
| 10081 | // We've got down to a single element; build a binary operator. |
| 10082 | Result = getDerived().RebuildBinaryOperator( |
| 10083 | E->getEllipsisLoc(), E->getOperator(), |
| 10084 | LeftFold ? Result.get() : Out.get(), |
| 10085 | LeftFold ? Out.get() : Result.get()); |
| 10086 | } else |
| 10087 | Result = Out; |
| 10088 | |
| 10089 | if (Result.isInvalid()) |
| 10090 | return true; |
| 10091 | } |
| 10092 | |
| 10093 | // If we're retaining an expansion for a left fold, it is the outermost |
| 10094 | // component and takes the complete expansion so far as its init (if any). |
| 10095 | if (LeftFold && RetainExpansion) { |
| 10096 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10097 | |
| 10098 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10099 | if (Out.isInvalid()) |
| 10100 | return true; |
| 10101 | |
| 10102 | Result = getDerived().RebuildCXXFoldExpr( |
| 10103 | E->getLocStart(), Result.get(), |
| 10104 | E->getOperator(), E->getEllipsisLoc(), |
| 10105 | Out.get(), E->getLocEnd()); |
| 10106 | if (Result.isInvalid()) |
| 10107 | return true; |
| 10108 | } |
| 10109 | |
| 10110 | // If we had no init and an empty pack, and we're not retaining an expansion, |
| 10111 | // then produce a fallback value or error. |
| 10112 | if (Result.isUnset()) |
| 10113 | return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), |
| 10114 | E->getOperator()); |
| 10115 | |
| 10116 | return Result; |
| 10117 | } |
| 10118 | |
| 10119 | template<typename Derived> |
| 10120 | ExprResult |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 10121 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 10122 | CXXStdInitializerListExpr *E) { |
| 10123 | return getDerived().TransformExpr(E->getSubExpr()); |
| 10124 | } |
| 10125 | |
| 10126 | template<typename Derived> |
| 10127 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10128 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10129 | return SemaRef.MaybeBindToTemporary(E); |
| 10130 | } |
| 10131 | |
| 10132 | template<typename Derived> |
| 10133 | ExprResult |
| 10134 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10135 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10136 | } |
| 10137 | |
| 10138 | template<typename Derived> |
| 10139 | ExprResult |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 10140 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 10141 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 10142 | if (SubExpr.isInvalid()) |
| 10143 | return ExprError(); |
| 10144 | |
| 10145 | if (!getDerived().AlwaysRebuild() && |
| 10146 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10147 | return E; |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 10148 | |
| 10149 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10150 | } |
| 10151 | |
| 10152 | template<typename Derived> |
| 10153 | ExprResult |
| 10154 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 10155 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10156 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10157 | bool ArgChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10158 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10159 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 10160 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10161 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10162 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 10163 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10164 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10165 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 10166 | Elements.data(), |
| 10167 | Elements.size()); |
| 10168 | } |
| 10169 | |
| 10170 | template<typename Derived> |
| 10171 | ExprResult |
| 10172 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10173 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10174 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10175 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10176 | bool ArgChanged = false; |
| 10177 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 10178 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10179 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10180 | if (OrigElement.isPackExpansion()) { |
| 10181 | // This key/value element is a pack expansion. |
| 10182 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10183 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 10184 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 10185 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 10186 | |
| 10187 | // Determine whether the set of unexpanded parameter packs can |
| 10188 | // and should be expanded. |
| 10189 | bool Expand = true; |
| 10190 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 10191 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 10192 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10193 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 10194 | OrigElement.Value->getLocEnd()); |
| 10195 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 10196 | PatternRange, |
| 10197 | Unexpanded, |
| 10198 | Expand, RetainExpansion, |
| 10199 | NumExpansions)) |
| 10200 | return ExprError(); |
| 10201 | |
| 10202 | if (!Expand) { |
| 10203 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10204 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10205 | // expansion. |
| 10206 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 10207 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10208 | if (Key.isInvalid()) |
| 10209 | return ExprError(); |
| 10210 | |
| 10211 | if (Key.get() != OrigElement.Key) |
| 10212 | ArgChanged = true; |
| 10213 | |
| 10214 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 10215 | if (Value.isInvalid()) |
| 10216 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10217 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10218 | if (Value.get() != OrigElement.Value) |
| 10219 | ArgChanged = true; |
| 10220 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10221 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10222 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 10223 | }; |
| 10224 | Elements.push_back(Expansion); |
| 10225 | continue; |
| 10226 | } |
| 10227 | |
| 10228 | // Record right away that the argument was changed. This needs |
| 10229 | // to happen even if the array expands to nothing. |
| 10230 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10231 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10232 | // The transform has determined that we should perform an elementwise |
| 10233 | // expansion of the pattern. Do so. |
| 10234 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10235 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 10236 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10237 | if (Key.isInvalid()) |
| 10238 | return ExprError(); |
| 10239 | |
| 10240 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 10241 | if (Value.isInvalid()) |
| 10242 | return ExprError(); |
| 10243 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10244 | ObjCDictionaryElement Element = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10245 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 10246 | }; |
| 10247 | |
| 10248 | // If any unexpanded parameter packs remain, we still have a |
| 10249 | // pack expansion. |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 10250 | // FIXME: Can this really happen? |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10251 | if (Key.get()->containsUnexpandedParameterPack() || |
| 10252 | Value.get()->containsUnexpandedParameterPack()) |
| 10253 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10254 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10255 | Elements.push_back(Element); |
| 10256 | } |
| 10257 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 10258 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 10259 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10260 | // We've finished with this pack expansion. |
| 10261 | continue; |
| 10262 | } |
| 10263 | |
| 10264 | // Transform and check key. |
| 10265 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10266 | if (Key.isInvalid()) |
| 10267 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10268 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10269 | if (Key.get() != OrigElement.Key) |
| 10270 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10271 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10272 | // Transform and check value. |
| 10273 | ExprResult Value |
| 10274 | = getDerived().TransformExpr(OrigElement.Value); |
| 10275 | if (Value.isInvalid()) |
| 10276 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10277 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10278 | if (Value.get() != OrigElement.Value) |
| 10279 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10280 | |
| 10281 | ObjCDictionaryElement Element = { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 10282 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10283 | }; |
| 10284 | Elements.push_back(Element); |
| 10285 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10286 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10287 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 10288 | return SemaRef.MaybeBindToTemporary(E); |
| 10289 | |
| 10290 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 10291 | Elements.data(), |
| 10292 | Elements.size()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10293 | } |
| 10294 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10295 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10296 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10297 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10298 | TypeSourceInfo *EncodedTypeInfo |
| 10299 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 10300 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10301 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10302 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10303 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10304 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10305 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10306 | |
| 10307 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10308 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10309 | E->getRParenLoc()); |
| 10310 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10311 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10312 | template<typename Derived> |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10313 | ExprResult TreeTransform<Derived>:: |
| 10314 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 10315 | // This is a kind of implicit conversion, and it needs to get dropped |
| 10316 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 10317 | // do, as well a more specific one: this expression is only valid when |
| 10318 | // it appears *immediately* as an argument expression. |
| 10319 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10320 | } |
| 10321 | |
| 10322 | template<typename Derived> |
| 10323 | ExprResult TreeTransform<Derived>:: |
| 10324 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10325 | TypeSourceInfo *TSInfo |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10326 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 10327 | if (!TSInfo) |
| 10328 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10329 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10330 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10331 | if (Result.isInvalid()) |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10332 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10333 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10334 | if (!getDerived().AlwaysRebuild() && |
| 10335 | TSInfo == E->getTypeInfoAsWritten() && |
| 10336 | Result.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10337 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10338 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10339 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10340 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10341 | Result.get()); |
| 10342 | } |
| 10343 | |
| 10344 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10345 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10346 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10347 | // Transform arguments. |
| 10348 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10349 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10350 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10351 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10352 | &ArgChanged)) |
| 10353 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10354 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10355 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 10356 | // Class message: transform the receiver type. |
| 10357 | TypeSourceInfo *ReceiverTypeInfo |
| 10358 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 10359 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10360 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10361 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10362 | // If nothing changed, just retain the existing message send. |
| 10363 | if (!getDerived().AlwaysRebuild() && |
| 10364 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10365 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10366 | |
| 10367 | // Build a new class message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 10368 | SmallVector<SourceLocation, 16> SelLocs; |
| 10369 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10370 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 10371 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 10372 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10373 | E->getMethodDecl(), |
| 10374 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10375 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10376 | E->getRightLoc()); |
| 10377 | } |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 10378 | else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || |
| 10379 | E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { |
| 10380 | // Build a new class message send to 'super'. |
| 10381 | SmallVector<SourceLocation, 16> SelLocs; |
| 10382 | E->getSelectorLocs(SelLocs); |
| 10383 | return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), |
| 10384 | E->getSelector(), |
| 10385 | SelLocs, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 10386 | E->getReceiverType(), |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 10387 | E->getMethodDecl(), |
| 10388 | E->getLeftLoc(), |
| 10389 | Args, |
| 10390 | E->getRightLoc()); |
| 10391 | } |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10392 | |
| 10393 | // Instance message: transform the receiver |
| 10394 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 10395 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10396 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10397 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 10398 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10399 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10400 | |
| 10401 | // If nothing changed, just retain the existing message send. |
| 10402 | if (!getDerived().AlwaysRebuild() && |
| 10403 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10404 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10405 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10406 | // Build a new instance message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 10407 | SmallVector<SourceLocation, 16> SelLocs; |
| 10408 | E->getSelectorLocs(SelLocs); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10409 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10410 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 10411 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10412 | E->getMethodDecl(), |
| 10413 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10414 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10415 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10416 | } |
| 10417 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10418 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10419 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10420 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10421 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10422 | } |
| 10423 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10424 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10425 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10426 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10427 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10428 | } |
| 10429 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10430 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10431 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10432 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10433 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10434 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10435 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10436 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10437 | |
| 10438 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10439 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10440 | // If nothing changed, just retain the existing expression. |
| 10441 | if (!getDerived().AlwaysRebuild() && |
| 10442 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10443 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10444 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10445 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10446 | E->getLocation(), |
| 10447 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10448 | } |
| 10449 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10450 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10451 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10452 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 10453 | // 'super' and types never change. Property never changes. Just |
| 10454 | // retain the existing expression. |
| 10455 | if (!E->isObjectReceiver()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10456 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10457 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 10458 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10459 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 10460 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10461 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10462 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 10463 | // We don't need to transform the property; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10464 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 10465 | // If nothing changed, just retain the existing expression. |
| 10466 | if (!getDerived().AlwaysRebuild() && |
| 10467 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10468 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10469 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 10470 | if (E->isExplicitProperty()) |
| 10471 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 10472 | E->getExplicitProperty(), |
| 10473 | E->getLocation()); |
| 10474 | |
| 10475 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 10476 | SemaRef.Context.PseudoObjectTy, |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 10477 | E->getImplicitPropertyGetter(), |
| 10478 | E->getImplicitPropertySetter(), |
| 10479 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10480 | } |
| 10481 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10482 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10483 | ExprResult |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10484 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 10485 | // Transform the base expression. |
| 10486 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 10487 | if (Base.isInvalid()) |
| 10488 | return ExprError(); |
| 10489 | |
| 10490 | // Transform the key expression. |
| 10491 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 10492 | if (Key.isInvalid()) |
| 10493 | return ExprError(); |
| 10494 | |
| 10495 | // If nothing changed, just retain the existing expression. |
| 10496 | if (!getDerived().AlwaysRebuild() && |
| 10497 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10498 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10499 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10500 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10501 | Base.get(), Key.get(), |
| 10502 | E->getAtIndexMethodDecl(), |
| 10503 | E->setAtIndexMethodDecl()); |
| 10504 | } |
| 10505 | |
| 10506 | template<typename Derived> |
| 10507 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10508 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10509 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10510 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10511 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10512 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10513 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10514 | // If nothing changed, just retain the existing expression. |
| 10515 | if (!getDerived().AlwaysRebuild() && |
| 10516 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10517 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10518 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10519 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 10520 | E->getOpLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10521 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10522 | } |
| 10523 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10524 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10525 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10526 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10527 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10528 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10529 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10530 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10531 | SubExprs, &ArgumentChanged)) |
| 10532 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10533 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10534 | if (!getDerived().AlwaysRebuild() && |
| 10535 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10536 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10537 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10538 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10539 | SubExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10540 | E->getRParenLoc()); |
| 10541 | } |
| 10542 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10543 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10544 | ExprResult |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 10545 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 10546 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 10547 | if (SrcExpr.isInvalid()) |
| 10548 | return ExprError(); |
| 10549 | |
| 10550 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 10551 | if (!Type) |
| 10552 | return ExprError(); |
| 10553 | |
| 10554 | if (!getDerived().AlwaysRebuild() && |
| 10555 | Type == E->getTypeSourceInfo() && |
| 10556 | SrcExpr.get() == E->getSrcExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10557 | return E; |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 10558 | |
| 10559 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 10560 | SrcExpr.get(), Type, |
| 10561 | E->getRParenLoc()); |
| 10562 | } |
| 10563 | |
| 10564 | template<typename Derived> |
| 10565 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10566 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10567 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10568 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10569 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10570 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 10571 | |
| 10572 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 10573 | blockScope->TheDecl->setBlockMissingReturnType( |
| 10574 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10575 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 10576 | SmallVector<ParmVarDecl*, 4> params; |
| 10577 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10578 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 10579 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10580 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 10581 | oldBlock->param_begin(), |
| 10582 | oldBlock->param_size(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10583 | nullptr, paramTypes, ¶ms)) { |
| 10584 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10585 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10586 | } |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10587 | |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10588 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 10589 | QualType exprResultType = |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 10590 | getDerived().TransformType(exprFunctionType->getReturnType()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 10591 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 10592 | QualType functionType = |
| 10593 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10594 | exprFunctionType->getExtProtoInfo()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10595 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10596 | |
| 10597 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10598 | if (!params.empty()) |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 10599 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 10600 | |
| 10601 | if (!oldBlock->blockMissingReturnType()) { |
| 10602 | blockScope->HasImplicitReturnType = false; |
| 10603 | blockScope->ReturnType = exprResultType; |
| 10604 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10605 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10606 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10607 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10608 | if (body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10609 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10610 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10611 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10612 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10613 | #ifndef NDEBUG |
| 10614 | // In builds with assertions, make sure that we captured everything we |
| 10615 | // captured before. |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10616 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 10617 | for (const auto &I : oldBlock->captures()) { |
| 10618 | VarDecl *oldCapture = I.getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10619 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10620 | // Ignore parameter packs. |
| 10621 | if (isa<ParmVarDecl>(oldCapture) && |
| 10622 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 10623 | continue; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10624 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10625 | VarDecl *newCapture = |
| 10626 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 10627 | oldCapture)); |
| 10628 | assert(blockScope->CaptureMap.count(newCapture)); |
| 10629 | } |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10630 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10631 | } |
| 10632 | #endif |
| 10633 | |
| 10634 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10635 | /*Scope=*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10636 | } |
| 10637 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10638 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10639 | ExprResult |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 10640 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 10641 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 10642 | } |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 10643 | |
| 10644 | template<typename Derived> |
| 10645 | ExprResult |
| 10646 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10647 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 10648 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10649 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10650 | SubExprs.reserve(E->getNumSubExprs()); |
| 10651 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 10652 | SubExprs, &ArgumentChanged)) |
| 10653 | return ExprError(); |
| 10654 | |
| 10655 | if (!getDerived().AlwaysRebuild() && |
| 10656 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10657 | return E; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10658 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10659 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10660 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 10661 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10663 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10664 | // Type reconstruction |
| 10665 | //===----------------------------------------------------------------------===// |
| 10666 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10667 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10668 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 10669 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10670 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10671 | getDerived().getBaseEntity()); |
| 10672 | } |
| 10673 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10674 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10675 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 10676 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10677 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10678 | getDerived().getBaseEntity()); |
| 10679 | } |
| 10680 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10681 | template<typename Derived> |
| 10682 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10683 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 10684 | bool WrittenAsLValue, |
| 10685 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10686 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10687 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10688 | } |
| 10689 | |
| 10690 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10691 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10692 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 10693 | QualType ClassType, |
| 10694 | SourceLocation Sigil) { |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 10695 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 10696 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10697 | } |
| 10698 | |
| 10699 | template<typename Derived> |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 10700 | QualType TreeTransform<Derived>::RebuildObjCObjectType( |
| 10701 | QualType BaseType, |
| 10702 | SourceLocation Loc, |
| 10703 | SourceLocation TypeArgsLAngleLoc, |
| 10704 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 10705 | SourceLocation TypeArgsRAngleLoc, |
| 10706 | SourceLocation ProtocolLAngleLoc, |
| 10707 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 10708 | ArrayRef<SourceLocation> ProtocolLocs, |
| 10709 | SourceLocation ProtocolRAngleLoc) { |
| 10710 | return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, |
| 10711 | TypeArgs, TypeArgsRAngleLoc, |
| 10712 | ProtocolLAngleLoc, Protocols, ProtocolLocs, |
| 10713 | ProtocolRAngleLoc, |
| 10714 | /*FailOnError=*/true); |
| 10715 | } |
| 10716 | |
| 10717 | template<typename Derived> |
| 10718 | QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( |
| 10719 | QualType PointeeType, |
| 10720 | SourceLocation Star) { |
| 10721 | return SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 10722 | } |
| 10723 | |
| 10724 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10725 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10726 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 10727 | ArrayType::ArraySizeModifier SizeMod, |
| 10728 | const llvm::APInt *Size, |
| 10729 | Expr *SizeExpr, |
| 10730 | unsigned IndexTypeQuals, |
| 10731 | SourceRange BracketsRange) { |
| 10732 | if (SizeExpr || !Size) |
| 10733 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 10734 | IndexTypeQuals, BracketsRange, |
| 10735 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10736 | |
| 10737 | QualType Types[] = { |
| 10738 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 10739 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 10740 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10741 | }; |
Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 10742 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10743 | QualType SizeType; |
| 10744 | for (unsigned I = 0; I != NumTypes; ++I) |
| 10745 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 10746 | SizeType = Types[I]; |
| 10747 | break; |
| 10748 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10749 | |
Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 10750 | // Note that we can return a VariableArrayType here in the case where |
| 10751 | // the element type was a dependent VariableArrayType. |
| 10752 | IntegerLiteral *ArraySize |
| 10753 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 10754 | /*FIXME*/BracketsRange.getBegin()); |
| 10755 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10756 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10757 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10758 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10759 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10760 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10761 | QualType |
| 10762 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10763 | ArrayType::ArraySizeModifier SizeMod, |
| 10764 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10765 | unsigned IndexTypeQuals, |
| 10766 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10767 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10768 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10769 | } |
| 10770 | |
| 10771 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10772 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10773 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10774 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10775 | unsigned IndexTypeQuals, |
| 10776 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10777 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10778 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10779 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10780 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10781 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10782 | QualType |
| 10783 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10784 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10785 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10786 | unsigned IndexTypeQuals, |
| 10787 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10788 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10789 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10790 | IndexTypeQuals, BracketsRange); |
| 10791 | } |
| 10792 | |
| 10793 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10794 | QualType |
| 10795 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10796 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10797 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10798 | unsigned IndexTypeQuals, |
| 10799 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10800 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10801 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10802 | IndexTypeQuals, BracketsRange); |
| 10803 | } |
| 10804 | |
| 10805 | template<typename Derived> |
| 10806 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 10807 | unsigned NumElements, |
| 10808 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10809 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 10810 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10811 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10812 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10813 | template<typename Derived> |
| 10814 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 10815 | unsigned NumElements, |
| 10816 | SourceLocation AttributeLoc) { |
| 10817 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 10818 | NumElements, true); |
| 10819 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 10820 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 10821 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10822 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10823 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10824 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10825 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10826 | QualType |
| 10827 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10828 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10829 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10830 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10831 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10832 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10833 | template<typename Derived> |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 10834 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 10835 | QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 10836 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10837 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 10838 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10839 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 10840 | getDerived().getBaseEntity(), |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10841 | EPI); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10843 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10844 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 10845 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 10846 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 10847 | } |
| 10848 | |
| 10849 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10850 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 10851 | assert(D && "no decl found"); |
| 10852 | if (D->isInvalidDecl()) return QualType(); |
| 10853 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10854 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10855 | TypeDecl *Ty; |
| 10856 | if (isa<UsingDecl>(D)) { |
| 10857 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 10858 | assert(Using->hasTypename() && |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10859 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 10860 | |
| 10861 | // A valid resolved using typename decl points to exactly one type decl. |
| 10862 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 10863 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10864 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10865 | } else { |
| 10866 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 10867 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 10868 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 10869 | } |
| 10870 | |
| 10871 | return SemaRef.Context.getTypeDeclType(Ty); |
| 10872 | } |
| 10873 | |
| 10874 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 10875 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 10876 | SourceLocation Loc) { |
| 10877 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10878 | } |
| 10879 | |
| 10880 | template<typename Derived> |
| 10881 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 10882 | return SemaRef.Context.getTypeOfType(Underlying); |
| 10883 | } |
| 10884 | |
| 10885 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 10886 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 10887 | SourceLocation Loc) { |
| 10888 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10889 | } |
| 10890 | |
| 10891 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 10892 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 10893 | UnaryTransformType::UTTKind UKind, |
| 10894 | SourceLocation Loc) { |
| 10895 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 10896 | } |
| 10897 | |
| 10898 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10899 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 10900 | TemplateName Template, |
| 10901 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 10902 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 10903 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10905 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 10906 | template<typename Derived> |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 10907 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 10908 | SourceLocation KWLoc) { |
| 10909 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 10910 | } |
| 10911 | |
| 10912 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10913 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10914 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10915 | bool TemplateKW, |
| 10916 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10917 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10918 | Template); |
| 10919 | } |
| 10920 | |
| 10921 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10922 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10923 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 10924 | const IdentifierInfo &Name, |
| 10925 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10926 | QualType ObjectType, |
| 10927 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10928 | UnqualifiedId TemplateName; |
| 10929 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10930 | Sema::TemplateTy Template; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10931 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10932 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10933 | SS, TemplateKWLoc, TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10934 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10935 | /*EnteringContext=*/false, |
| 10936 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10937 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10939 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10940 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10941 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10942 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10943 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10944 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10945 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10946 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10947 | // FIXME: Bogus location information. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10948 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10949 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10950 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10951 | Sema::TemplateTy Template; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10952 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10953 | SS, TemplateKWLoc, Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10954 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10955 | /*EnteringContext=*/false, |
| 10956 | Template); |
Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 10957 | return Template.get(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10958 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10959 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10960 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10961 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10962 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 10963 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10964 | Expr *OrigCallee, |
| 10965 | Expr *First, |
| 10966 | Expr *Second) { |
| 10967 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 10968 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10969 | |
Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 10970 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 10971 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 10972 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 10973 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 10974 | First, Second); |
| 10975 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 10976 | if (Result.isInvalid()) |
| 10977 | return ExprError(); |
| 10978 | First = Result.get(); |
| 10979 | } |
| 10980 | |
| 10981 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 10982 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 10983 | if (Result.isInvalid()) |
| 10984 | return ExprError(); |
| 10985 | Second = Result.get(); |
| 10986 | } |
| 10987 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10988 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 10989 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10990 | if (!First->getType()->isOverloadableType() && |
| 10991 | !Second->getType()->isOverloadableType()) |
| 10992 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 10993 | Callee->getLocStart(), |
| 10994 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 10995 | } else if (Op == OO_Arrow) { |
| 10996 | // -> is never a builtin operation. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10997 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 10998 | } else if (Second == nullptr || isPostIncDec) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10999 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11000 | // The argument is not of overloadable type, so try to create a |
| 11001 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11002 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11003 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11004 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11005 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11006 | } |
| 11007 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11008 | if (!First->getType()->isOverloadableType() && |
| 11009 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11010 | // Neither of the arguments is an overloadable type, so try to |
| 11011 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11012 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11013 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11014 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11015 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11016 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11017 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11018 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11019 | } |
| 11020 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11021 | |
| 11022 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11023 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 11024 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11025 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11026 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11027 | assert(ULE->requiresADL()); |
Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 11028 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11029 | } else { |
Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 11030 | // If we've resolved this to a particular non-member function, just call |
| 11031 | // that function. If we resolved it to a member function, |
| 11032 | // CreateOverloaded* will find that function for us. |
| 11033 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 11034 | if (!isa<CXXMethodDecl>(ND)) |
| 11035 | Functions.addDecl(ND); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11036 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11037 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11038 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11039 | Expr *Args[2] = { First, Second }; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11040 | unsigned NumArgs = 1 + (Second != nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11041 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11042 | // Create the overloaded operator invocation for unary operators. |
| 11043 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11044 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11045 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11046 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11047 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11048 | |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 11049 | if (Op == OO_Subscript) { |
| 11050 | SourceLocation LBrace; |
| 11051 | SourceLocation RBrace; |
| 11052 | |
| 11053 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
NAKAMURA Takumi | 44d4d9a | 2014-10-29 08:11:47 +0000 | [diff] [blame] | 11054 | DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo(); |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 11055 | LBrace = SourceLocation::getFromRawEncoding( |
| 11056 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 11057 | RBrace = SourceLocation::getFromRawEncoding( |
| 11058 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 11059 | } else { |
| 11060 | LBrace = Callee->getLocStart(); |
| 11061 | RBrace = OpLoc; |
| 11062 | } |
| 11063 | |
| 11064 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 11065 | First, Second); |
| 11066 | } |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 11067 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11068 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11069 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11070 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11071 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 11072 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11073 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11074 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11075 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11076 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11077 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11078 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11079 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11080 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11081 | SourceLocation OperatorLoc, |
| 11082 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 11083 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11084 | TypeSourceInfo *ScopeType, |
| 11085 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 11086 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 11087 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11088 | QualType BaseType = Base->getType(); |
| 11089 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11090 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11091 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 11092 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 11093 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11094 | // This pseudo-destructor expression is still a pseudo-destructor. |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 11095 | return SemaRef.BuildPseudoDestructorExpr( |
| 11096 | Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, |
| 11097 | CCLoc, TildeLoc, Destroyed); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11098 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11099 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 11100 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11101 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 11102 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 11103 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 11104 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 11105 | |
Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 11106 | // The scope type is now known to be a valid nested name specifier |
| 11107 | // component. Tack it on to the end of the nested name specifier. |
Alexey Bataev | 2a06681 | 2014-10-16 03:04:35 +0000 | [diff] [blame] | 11108 | if (ScopeType) { |
| 11109 | if (!ScopeType->getType()->getAs<TagType>()) { |
| 11110 | getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 11111 | diag::err_expected_class_or_namespace) |
| 11112 | << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 11113 | return ExprError(); |
| 11114 | } |
| 11115 | SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), |
| 11116 | CCLoc); |
| 11117 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11118 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11119 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11120 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11121 | OperatorLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11122 | SS, TemplateKWLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11123 | /*FIXME: FirstQualifier*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11124 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11125 | /*TemplateArgs*/ nullptr); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11126 | } |
| 11127 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 11128 | template<typename Derived> |
| 11129 | StmtResult |
| 11130 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 11131 | SourceLocation Loc = S->getLocStart(); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 11132 | CapturedDecl *CD = S->getCapturedDecl(); |
| 11133 | unsigned NumParams = CD->getNumParams(); |
| 11134 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 11135 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 11136 | for (unsigned I = 0; I < NumParams; ++I) { |
| 11137 | if (I != ContextParamPos) { |
| 11138 | Params.push_back( |
| 11139 | std::make_pair( |
| 11140 | CD->getParam(I)->getName(), |
| 11141 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 11142 | } else { |
| 11143 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 11144 | } |
| 11145 | } |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11146 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 11147 | S->getCapturedRegionKind(), Params); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11148 | StmtResult Body; |
| 11149 | { |
| 11150 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 11151 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 11152 | } |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 11153 | |
| 11154 | if (Body.isInvalid()) { |
| 11155 | getSema().ActOnCapturedRegionError(); |
| 11156 | return StmtError(); |
| 11157 | } |
| 11158 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11159 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 11160 | } |
| 11161 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11162 | } // end namespace clang |
| 11163 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 11164 | #endif |