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" |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 24 | #include "clang/AST/ExprOpenMP.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 25 | #include "clang/AST/Stmt.h" |
| 26 | #include "clang/AST/StmtCXX.h" |
| 27 | #include "clang/AST/StmtObjC.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 28 | #include "clang/AST/StmtOpenMP.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Designator.h" |
| 30 | #include "clang/Sema/Lookup.h" |
| 31 | #include "clang/Sema/Ownership.h" |
| 32 | #include "clang/Sema/ParsedTemplate.h" |
| 33 | #include "clang/Sema/ScopeInfo.h" |
| 34 | #include "clang/Sema/SemaDiagnostic.h" |
| 35 | #include "clang/Sema/SemaInternal.h" |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/ArrayRef.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 37 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 38 | #include <algorithm> |
| 39 | |
| 40 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 41 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 43 | /// \brief A semantic tree transformation that allows one to transform one |
| 44 | /// abstract syntax tree into another. |
| 45 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 46 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 47 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 48 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// instantiation is implemented as a tree transformation where the |
| 50 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 51 | /// template arguments for their corresponding template parameters; a similar |
| 52 | /// transformation is performed for non-type template parameters and |
| 53 | /// template template parameters. |
| 54 | /// |
| 55 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 57 | /// override any of the transformation or rebuild operators by providing an |
| 58 | /// operation with the same signature as the default implementation. The |
| 59 | /// overridding function should not be virtual. |
| 60 | /// |
| 61 | /// Semantic tree transformations are split into two stages, either of which |
| 62 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 63 | /// or the parts of an AST node using the various transformation functions, |
| 64 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 65 | /// node of the appropriate kind from the pieces. The default transformation |
| 66 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 67 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 68 | /// were changed by the transformation, invokes the rebuild operation to create |
| 69 | /// a new AST node. |
| 70 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 72 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 73 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 75 | /// new implementations. |
| 76 | /// |
| 77 | /// For more fine-grained transformations, subclasses can replace any of the |
| 78 | /// \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] | 79 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 80 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 83 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 84 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 85 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 86 | /// be able to use more efficient rebuild steps. |
| 87 | /// |
| 88 | /// 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] | 89 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 90 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 91 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 92 | /// default locations and entity names used for type-checking |
| 93 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 94 | template<typename Derived> |
| 95 | class TreeTransform { |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 96 | /// \brief Private RAII object that helps us forget and then re-remember |
| 97 | /// the template argument corresponding to a partially-substituted parameter |
| 98 | /// pack. |
| 99 | class ForgetPartiallySubstitutedPackRAII { |
| 100 | Derived &Self; |
| 101 | TemplateArgument Old; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 103 | public: |
| 104 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 105 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 106 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 107 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 108 | ~ForgetPartiallySubstitutedPackRAII() { |
| 109 | Self.RememberPartiallySubstitutedPack(Old); |
| 110 | } |
| 111 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 113 | protected: |
| 114 | Sema &SemaRef; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 116 | /// \brief The set of local declarations that have been transformed, for |
| 117 | /// cases where we are forced to build new declarations within the transformer |
| 118 | /// rather than in the subclass (e.g., lambda closure types). |
| 119 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 120 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 123 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 125 | /// \brief Retrieves a reference to the derived class. |
| 126 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 127 | |
| 128 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | const Derived &getDerived() const { |
| 130 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 131 | } |
| 132 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 133 | static inline ExprResult Owned(Expr *E) { return E; } |
| 134 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 135 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 136 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 137 | /// this tree transform. |
| 138 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 140 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 141 | /// if none of the children have changed. |
| 142 | /// |
| 143 | /// Subclasses may override this function to specify when the transformation |
| 144 | /// should rebuild all AST nodes. |
Richard Smith | 2aa81a7 | 2013-11-07 20:07:17 +0000 | [diff] [blame] | 145 | /// |
| 146 | /// We must always rebuild all AST nodes when performing variadic template |
| 147 | /// pack expansion, in order to avoid violating the AST invariant that each |
| 148 | /// statement node appears at most once in its containing declaration. |
| 149 | bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 151 | /// \brief Returns the location of the entity being transformed, if that |
| 152 | /// information was not available elsewhere in the AST. |
| 153 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 154 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 155 | /// provide an alternative implementation that provides better location |
| 156 | /// information. |
| 157 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 159 | /// \brief Returns the name of the entity being transformed, if that |
| 160 | /// information was not available elsewhere in the AST. |
| 161 | /// |
| 162 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 163 | /// implementation with a more precise name. |
| 164 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 165 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 166 | /// \brief Sets the "base" location and entity when that |
| 167 | /// information is known based on another transformation. |
| 168 | /// |
| 169 | /// By default, the source location and entity are ignored. Subclasses can |
| 170 | /// override this function to provide a customized implementation. |
| 171 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 172 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 173 | /// \brief RAII object that temporarily sets the base location and entity |
| 174 | /// used for reporting diagnostics in types. |
| 175 | class TemporaryBase { |
| 176 | TreeTransform &Self; |
| 177 | SourceLocation OldLocation; |
| 178 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 180 | public: |
| 181 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 183 | OldLocation = Self.getDerived().getBaseLocation(); |
| 184 | OldEntity = Self.getDerived().getBaseEntity(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 185 | |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 186 | if (Location.isValid()) |
| 187 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 190 | ~TemporaryBase() { |
| 191 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 192 | } |
| 193 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | |
| 195 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 196 | /// transformed. |
| 197 | /// |
| 198 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | /// 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] | 200 | /// not change. For example, template instantiation need not traverse |
| 201 | /// non-dependent types. |
| 202 | bool AlreadyTransformed(QualType T) { |
| 203 | return T.isNull(); |
| 204 | } |
| 205 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 206 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 207 | /// because it is a default argument. |
| 208 | /// |
| 209 | /// Subclasses can provide an alternative implementation of this routine to |
| 210 | /// determine which kinds of call arguments get dropped. By default, |
| 211 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 212 | bool DropCallArgument(Expr *E) { |
| 213 | return E->isDefaultArgument(); |
| 214 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 215 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 216 | /// \brief Determine whether we should expand a pack expansion with the |
| 217 | /// given set of parameter packs into separate arguments by repeatedly |
| 218 | /// transforming the pattern. |
| 219 | /// |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 220 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 221 | /// Subclasses can override this routine to provide different behavior. |
| 222 | /// |
| 223 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 224 | /// pack expansion. |
| 225 | /// |
| 226 | /// \param PatternRange The source range that covers the entire pattern of |
| 227 | /// the pack expansion. |
| 228 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 229 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 230 | /// pattern. |
| 231 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 232 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 233 | /// expand the corresponding pack expansions into separate arguments. When |
| 234 | /// set, \c NumExpansions must also be set. |
| 235 | /// |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 236 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 237 | /// pack expansion after all of the expanded arguments. This is used |
| 238 | /// when extending explicitly-specified template argument packs per |
| 239 | /// C++0x [temp.arg.explicit]p9. |
| 240 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 241 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 242 | /// the expanded form of the corresponding pack expansion. This is both an |
| 243 | /// input and an output parameter, which can be set by the caller if the |
| 244 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 245 | /// and will be set by the callee when the number of expansions is known. |
| 246 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 247 | /// set this value in other cases. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 248 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 249 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 250 | /// are to be instantiated with arguments of different lengths), false |
| 251 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 252 | /// must be set. |
| 253 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 254 | SourceRange PatternRange, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 255 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 256 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 257 | bool &RetainExpansion, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 258 | Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 259 | ShouldExpand = false; |
| 260 | return false; |
| 261 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 262 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 263 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 264 | /// when performing an instantiation that must preserve the parameter pack |
| 265 | /// use. |
| 266 | /// |
| 267 | /// This routine is meant to be overridden by the template instantiator. |
| 268 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 269 | return TemplateArgument(); |
| 270 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 271 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 272 | /// \brief "Remember" the partially-substituted pack template argument |
| 273 | /// after performing an instantiation that must preserve the parameter pack |
| 274 | /// use. |
| 275 | /// |
| 276 | /// This routine is meant to be overridden by the template instantiator. |
| 277 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 279 | /// \brief Note to the derived class when a function parameter pack is |
| 280 | /// being expanded. |
| 281 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transforms the given type into another type. |
| 284 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 285 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 286 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 287 | /// function. This is expensive, but we don't mind, because |
| 288 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 289 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 290 | /// |
| 291 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 292 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 294 | /// \brief Transforms the given type-with-location into a new |
| 295 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 296 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 297 | /// By default, this routine transforms a type by delegating to the |
| 298 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 299 | /// may override this function (to take over all type |
| 300 | /// transformations) or some set of the TransformXXXType functions |
| 301 | /// to alter the transformation. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 302 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 303 | |
| 304 | /// \brief Transform the given type-with-location into a new |
| 305 | /// type, collecting location information in the given builder |
| 306 | /// as necessary. |
| 307 | /// |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 308 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 309 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 310 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 311 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 313 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 314 | /// statement or the TransformExpr() function to transform an expression. |
| 315 | /// Subclasses may override this function to transform statements using some |
| 316 | /// other mechanism. |
| 317 | /// |
| 318 | /// \returns the transformed statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 319 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 320 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 321 | /// \brief Transform the given statement. |
| 322 | /// |
| 323 | /// By default, this routine transforms a statement by delegating to the |
| 324 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 325 | /// of clause. Subclasses may override this function to transform statements |
| 326 | /// using some other mechanism. |
| 327 | /// |
| 328 | /// \returns the transformed OpenMP clause. |
| 329 | OMPClause *TransformOMPClause(OMPClause *S); |
| 330 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 331 | /// \brief Transform the given attribute. |
| 332 | /// |
| 333 | /// By default, this routine transforms a statement by delegating to the |
| 334 | /// appropriate TransformXXXAttr function to transform a specific kind |
| 335 | /// of attribute. Subclasses may override this function to transform |
| 336 | /// attributed statements using some other mechanism. |
| 337 | /// |
| 338 | /// \returns the transformed attribute |
| 339 | const Attr *TransformAttr(const Attr *S); |
| 340 | |
| 341 | /// \brief Transform the specified attribute. |
| 342 | /// |
| 343 | /// Subclasses should override the transformation of attributes with a pragma |
| 344 | /// spelling to transform expressions stored within the attribute. |
| 345 | /// |
| 346 | /// \returns the transformed attribute. |
| 347 | #define ATTR(X) |
| 348 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 349 | const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } |
| 350 | #include "clang/Basic/AttrList.inc" |
| 351 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 352 | /// \brief Transform the given expression. |
| 353 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 354 | /// By default, this routine transforms an expression by delegating to the |
| 355 | /// appropriate TransformXXXExpr function to build a new expression. |
| 356 | /// Subclasses may override this function to transform expressions using some |
| 357 | /// other mechanism. |
| 358 | /// |
| 359 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 360 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 362 | /// \brief Transform the given initializer. |
| 363 | /// |
| 364 | /// By default, this routine transforms an initializer by stripping off the |
| 365 | /// semantic nodes added by initialization, then passing the result to |
| 366 | /// TransformExpr or TransformExprs. |
| 367 | /// |
| 368 | /// \returns the transformed initializer. |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 369 | ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 370 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 371 | /// \brief Transform the given list of expressions. |
| 372 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 373 | /// This routine transforms a list of expressions by invoking |
| 374 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 375 | /// support for variadic templates by expanding any pack expansions (if the |
| 376 | /// derived class permits such expansion) along the way. When pack expansions |
| 377 | /// are present, the number of outputs may not equal the number of inputs. |
| 378 | /// |
| 379 | /// \param Inputs The set of expressions to be transformed. |
| 380 | /// |
| 381 | /// \param NumInputs The number of expressions in \c Inputs. |
| 382 | /// |
| 383 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 384 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 385 | /// be. |
| 386 | /// |
| 387 | /// \param Outputs The transformed input expressions will be added to this |
| 388 | /// vector. |
| 389 | /// |
| 390 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 391 | /// due to transformation. |
| 392 | /// |
| 393 | /// \returns true if an error occurred, false otherwise. |
| 394 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 395 | SmallVectorImpl<Expr *> &Outputs, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 396 | bool *ArgChanged = nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 397 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 398 | /// \brief Transform the given declaration, which is referenced from a type |
| 399 | /// or expression. |
| 400 | /// |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 401 | /// By default, acts as the identity function on declarations, unless the |
| 402 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 403 | /// may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 404 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 405 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 406 | = TransformedLocalDecls.find(D); |
| 407 | if (Known != TransformedLocalDecls.end()) |
| 408 | return Known->second; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 409 | |
| 410 | return D; |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 411 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 412 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 413 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 414 | /// place them on the new declaration. |
| 415 | /// |
| 416 | /// By default, this operation does nothing. Subclasses may override this |
| 417 | /// behavior to transform attributes. |
| 418 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 419 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 420 | /// \brief Note that a local declaration has been transformed by this |
| 421 | /// transformer. |
| 422 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 423 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 424 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 425 | /// the transformer itself has to transform the declarations. This routine |
| 426 | /// can be overridden by a subclass that keeps track of such mappings. |
| 427 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 428 | TransformedLocalDecls[Old] = New; |
| 429 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 430 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 431 | /// \brief Transform the definition of the given declaration. |
| 432 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 434 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 435 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 436 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 438 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 439 | /// \brief Transform the given declaration, which was the first part of a |
| 440 | /// nested-name-specifier in a member access expression. |
| 441 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 442 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 443 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 444 | /// the \c T in \c x->T::member |
| 445 | /// |
| 446 | /// By default, invokes TransformDecl() to transform the declaration. |
| 447 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 448 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 449 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 450 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 451 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 452 | /// \brief Transform the given nested-name-specifier with source-location |
| 453 | /// information. |
| 454 | /// |
| 455 | /// By default, transforms all of the types and declarations within the |
| 456 | /// nested-name-specifier. Subclasses may override this function to provide |
| 457 | /// alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 458 | NestedNameSpecifierLoc |
| 459 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 460 | QualType ObjectType = QualType(), |
| 461 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 462 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 463 | /// \brief Transform the given declaration name. |
| 464 | /// |
| 465 | /// By default, transforms the types of conversion function, constructor, |
| 466 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 467 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 468 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 469 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 470 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 471 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 472 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 473 | /// |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 474 | /// \param SS The nested-name-specifier that qualifies the template |
| 475 | /// name. This nested-name-specifier must already have been transformed. |
| 476 | /// |
| 477 | /// \param Name The template name to transform. |
| 478 | /// |
| 479 | /// \param NameLoc The source location of the template name. |
| 480 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 481 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 482 | /// access expression, this is the type of the object whose member template |
| 483 | /// is being referenced. |
| 484 | /// |
| 485 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 486 | /// also refers to a name within the current (lexical) scope, this is the |
| 487 | /// declaration it refers to. |
| 488 | /// |
| 489 | /// By default, transforms the template name by transforming the declarations |
| 490 | /// and nested-name-specifiers that occur within the template name. |
| 491 | /// Subclasses may override this function to provide alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 492 | TemplateName |
| 493 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 494 | SourceLocation NameLoc, |
| 495 | QualType ObjectType = QualType(), |
| 496 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 497 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 498 | /// \brief Transform the given template argument. |
| 499 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | /// By default, this operation transforms the type, expression, or |
| 501 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 502 | /// new template argument from the transformed result. Subclasses may |
| 503 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 504 | /// |
| 505 | /// Returns true if there was an error. |
| 506 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 507 | TemplateArgumentLoc &Output, |
| 508 | bool Uneval = false); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 509 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 510 | /// \brief Transform the given set of template arguments. |
| 511 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 512 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 513 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 514 | /// the transformed arguments to the output list. |
| 515 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 516 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 517 | /// a convenience function. Subclasses that wish to override this behavior |
| 518 | /// should override the iterator-based member template version. |
| 519 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 520 | /// \param Inputs The set of template arguments to be transformed. |
| 521 | /// |
| 522 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 523 | /// |
| 524 | /// \param Outputs The set of transformed template arguments output by this |
| 525 | /// routine. |
| 526 | /// |
| 527 | /// Returns true if an error occurred. |
| 528 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 529 | unsigned NumInputs, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 530 | TemplateArgumentListInfo &Outputs, |
| 531 | bool Uneval = false) { |
| 532 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, |
| 533 | Uneval); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 534 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 535 | |
| 536 | /// \brief Transform the given set of template arguments. |
| 537 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 538 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 539 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 540 | /// the transformed arguments to the output list. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 541 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 542 | /// \param First An iterator to the first template argument. |
| 543 | /// |
| 544 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 545 | /// |
| 546 | /// \param Outputs The set of transformed template arguments output by this |
| 547 | /// routine. |
| 548 | /// |
| 549 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 550 | template<typename InputIterator> |
| 551 | bool TransformTemplateArguments(InputIterator First, |
| 552 | InputIterator Last, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 553 | TemplateArgumentListInfo &Outputs, |
| 554 | bool Uneval = false); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 555 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 556 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 557 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 558 | TemplateArgumentLoc &ArgLoc); |
| 559 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 560 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 561 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 562 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 563 | getDerived().getBaseLocation()); |
| 564 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 565 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 566 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 567 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 568 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 569 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 570 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 571 | template<typename Fn> |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 572 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 573 | FunctionProtoTypeLoc TL, |
| 574 | CXXRecordDecl *ThisContext, |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 575 | unsigned ThisTypeQuals, |
| 576 | Fn TransformExceptionSpec); |
| 577 | |
| 578 | bool TransformExceptionSpec(SourceLocation Loc, |
| 579 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 580 | SmallVectorImpl<QualType> &Exceptions, |
| 581 | bool &Changed); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 582 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 583 | StmtResult TransformSEHHandler(Stmt *Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 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 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 587 | TemplateSpecializationTypeLoc TL, |
| 588 | TemplateName Template); |
| 589 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 590 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 591 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 592 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 593 | TemplateName Template, |
| 594 | CXXScopeSpec &SS); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 595 | |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 596 | QualType TransformDependentTemplateSpecializationType( |
| 597 | TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, |
| 598 | NestedNameSpecifierLoc QualifierLoc); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 599 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 600 | /// \brief Transforms the parameters of a function type into the |
| 601 | /// given vectors. |
| 602 | /// |
| 603 | /// The result vectors should be kept in sync; null entries in the |
| 604 | /// variables vector are acceptable. |
| 605 | /// |
| 606 | /// Return true on error. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 607 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 608 | ParmVarDecl **Params, unsigned NumParams, |
| 609 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 610 | SmallVectorImpl<QualType> &PTypes, |
| 611 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 612 | |
| 613 | /// \brief Transforms a single function-type parameter. Return null |
| 614 | /// on error. |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 615 | /// |
| 616 | /// \param indexAdjustment - A number to add to the parameter's |
| 617 | /// scope index; can be negative |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 618 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 619 | int indexAdjustment, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 620 | Optional<unsigned> NumExpansions, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 621 | bool ExpectParameterPack); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 622 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 623 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 624 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 625 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 626 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 627 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 628 | TemplateParameterList *TransformTemplateParameterList( |
| 629 | TemplateParameterList *TPL) { |
| 630 | return TPL; |
| 631 | } |
| 632 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 633 | ExprResult TransformAddressOfOperand(Expr *E); |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 634 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 635 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 636 | bool IsAddressOfOperand, |
| 637 | TypeSourceInfo **RecoveryTSI); |
| 638 | |
| 639 | ExprResult TransformParenDependentScopeDeclRefExpr( |
| 640 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 641 | TypeSourceInfo **RecoveryTSI); |
| 642 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 643 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 644 | |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 645 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 646 | // amount of stack usage with clang. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 647 | #define STMT(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 648 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 649 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 650 | #define EXPR(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 651 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 652 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 653 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 654 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 656 | #define OPENMP_CLAUSE(Name, Class) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 657 | LLVM_ATTRIBUTE_NOINLINE \ |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 658 | OMPClause *Transform ## Class(Class *S); |
| 659 | #include "clang/Basic/OpenMPKinds.def" |
| 660 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 661 | /// \brief Build a new pointer type given its pointee type. |
| 662 | /// |
| 663 | /// By default, performs semantic analysis when building the pointer type. |
| 664 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 665 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 666 | |
| 667 | /// \brief Build a new block pointer type given its pointee type. |
| 668 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 670 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 671 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 672 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 673 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 674 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 675 | /// By default, performs semantic analysis when building the |
| 676 | /// reference type. Subclasses may override this routine to provide |
| 677 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 678 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 679 | /// \param LValue whether the type was written with an lvalue sigil |
| 680 | /// or an rvalue sigil. |
| 681 | QualType RebuildReferenceType(QualType ReferentType, |
| 682 | bool LValue, |
| 683 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 685 | /// \brief Build a new member pointer type given the pointee type and the |
| 686 | /// class type it refers into. |
| 687 | /// |
| 688 | /// By default, performs semantic analysis when building the member pointer |
| 689 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 690 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 691 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 693 | /// \brief Build an Objective-C object type. |
| 694 | /// |
| 695 | /// By default, performs semantic analysis when building the object type. |
| 696 | /// Subclasses may override this routine to provide different behavior. |
| 697 | QualType RebuildObjCObjectType(QualType BaseType, |
| 698 | SourceLocation Loc, |
| 699 | SourceLocation TypeArgsLAngleLoc, |
| 700 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 701 | SourceLocation TypeArgsRAngleLoc, |
| 702 | SourceLocation ProtocolLAngleLoc, |
| 703 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 704 | ArrayRef<SourceLocation> ProtocolLocs, |
| 705 | SourceLocation ProtocolRAngleLoc); |
| 706 | |
| 707 | /// \brief Build a new Objective-C object pointer type given the pointee type. |
| 708 | /// |
| 709 | /// By default, directly builds the pointer type, with no additional semantic |
| 710 | /// analysis. |
| 711 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 712 | SourceLocation Star); |
| 713 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 714 | /// \brief Build a new array type given the element type, size |
| 715 | /// modifier, size of the array (if known), size expression, and index type |
| 716 | /// qualifiers. |
| 717 | /// |
| 718 | /// By default, performs semantic analysis when building the array type. |
| 719 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 720 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 721 | QualType RebuildArrayType(QualType ElementType, |
| 722 | ArrayType::ArraySizeModifier SizeMod, |
| 723 | const llvm::APInt *Size, |
| 724 | Expr *SizeExpr, |
| 725 | unsigned IndexTypeQuals, |
| 726 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 727 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 728 | /// \brief Build a new constant array type given the element type, size |
| 729 | /// modifier, (known) size of the array, and index type qualifiers. |
| 730 | /// |
| 731 | /// By default, performs semantic analysis when building the array type. |
| 732 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 734 | ArrayType::ArraySizeModifier SizeMod, |
| 735 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 736 | unsigned IndexTypeQuals, |
| 737 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 738 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 739 | /// \brief Build a new incomplete array type given the element type, size |
| 740 | /// modifier, and index type qualifiers. |
| 741 | /// |
| 742 | /// By default, performs semantic analysis when building the array type. |
| 743 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 744 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 745 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 746 | unsigned IndexTypeQuals, |
| 747 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 748 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 750 | /// size modifier, size expression, and index type qualifiers. |
| 751 | /// |
| 752 | /// By default, performs semantic analysis when building the array type. |
| 753 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 754 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 755 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 756 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 757 | unsigned IndexTypeQuals, |
| 758 | SourceRange BracketsRange); |
| 759 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 761 | /// size modifier, size expression, and index type qualifiers. |
| 762 | /// |
| 763 | /// By default, performs semantic analysis when building the array type. |
| 764 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 765 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 766 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 767 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 768 | unsigned IndexTypeQuals, |
| 769 | SourceRange BracketsRange); |
| 770 | |
| 771 | /// \brief Build a new vector type given the element type and |
| 772 | /// number of elements. |
| 773 | /// |
| 774 | /// By default, performs semantic analysis when building the vector type. |
| 775 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 776 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 777 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 779 | /// \brief Build a new extended vector type given the element type and |
| 780 | /// number of elements. |
| 781 | /// |
| 782 | /// By default, performs semantic analysis when building the vector type. |
| 783 | /// Subclasses may override this routine to provide different behavior. |
| 784 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 785 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | |
| 787 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 788 | /// given the element type and number of elements. |
| 789 | /// |
| 790 | /// By default, performs semantic analysis when building the vector type. |
| 791 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 792 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 793 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 794 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 795 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 796 | /// \brief Build a new function type. |
| 797 | /// |
| 798 | /// By default, performs semantic analysis when building the function type. |
| 799 | /// Subclasses may override this routine to provide different behavior. |
| 800 | QualType RebuildFunctionProtoType(QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 801 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 802 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 804 | /// \brief Build a new unprototyped function type. |
| 805 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 806 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 807 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 808 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 809 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 810 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 811 | /// \brief Build a new typedef type. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 812 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 813 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 814 | } |
| 815 | |
| 816 | /// \brief Build a new class/struct/union type. |
| 817 | QualType RebuildRecordType(RecordDecl *Record) { |
| 818 | return SemaRef.Context.getTypeDeclType(Record); |
| 819 | } |
| 820 | |
| 821 | /// \brief Build a new Enum type. |
| 822 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 823 | return SemaRef.Context.getTypeDeclType(Enum); |
| 824 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 825 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 827 | /// |
| 828 | /// By default, performs semantic analysis when building the typeof type. |
| 829 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 830 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 831 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 833 | /// |
| 834 | /// By default, builds a new TypeOfType with the given underlying type. |
| 835 | QualType RebuildTypeOfType(QualType Underlying); |
| 836 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 837 | /// \brief Build a new unary transform type. |
| 838 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 839 | UnaryTransformType::UTTKind UKind, |
| 840 | SourceLocation Loc); |
| 841 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 842 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 843 | /// |
| 844 | /// By default, performs semantic analysis when building the decltype type. |
| 845 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 846 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 847 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 848 | /// \brief Build a new C++11 auto type. |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 849 | /// |
| 850 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 851 | QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) { |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 852 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 853 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 854 | // that we'll retry deduction after the transformation. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 855 | return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto, |
| 856 | /*IsDependent*/ false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 859 | /// \brief Build a new template specialization type. |
| 860 | /// |
| 861 | /// By default, performs semantic analysis when building the template |
| 862 | /// specialization type. Subclasses may override this routine to provide |
| 863 | /// different behavior. |
| 864 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 865 | SourceLocation TemplateLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 866 | TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 867 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 868 | /// \brief Build a new parenthesized type. |
| 869 | /// |
| 870 | /// By default, builds a new ParenType type from the inner type. |
| 871 | /// Subclasses may override this routine to provide different behavior. |
| 872 | QualType RebuildParenType(QualType InnerType) { |
| 873 | return SemaRef.Context.getParenType(InnerType); |
| 874 | } |
| 875 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 876 | /// \brief Build a new qualified name type. |
| 877 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 878 | /// By default, builds a new ElaboratedType type from the keyword, |
| 879 | /// the nested-name-specifier and the named type. |
| 880 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 881 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 882 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 883 | NestedNameSpecifierLoc QualifierLoc, |
| 884 | QualType Named) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 885 | return SemaRef.Context.getElaboratedType(Keyword, |
| 886 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 887 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 888 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 889 | |
| 890 | /// \brief Build a new typename type that refers to a template-id. |
| 891 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 892 | /// By default, builds a new DependentNameType type from the |
| 893 | /// nested-name-specifier and the given type. Subclasses may override |
| 894 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 895 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 896 | ElaboratedTypeKeyword Keyword, |
| 897 | NestedNameSpecifierLoc QualifierLoc, |
| 898 | const IdentifierInfo *Name, |
| 899 | SourceLocation NameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 900 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 901 | // Rebuild the template name. |
| 902 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 903 | CXXScopeSpec SS; |
| 904 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 905 | TemplateName InstName |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 906 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), |
| 907 | nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 908 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 909 | if (InstName.isNull()) |
| 910 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 911 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 912 | // If it's still dependent, make a dependent specialization. |
| 913 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 914 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 915 | QualifierLoc.getNestedNameSpecifier(), |
| 916 | Name, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 917 | Args); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 918 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 919 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 920 | // specialization. |
| 921 | QualType T = |
| 922 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 923 | if (T.isNull()) return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 924 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 925 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 926 | return T; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 927 | |
| 928 | return SemaRef.Context.getElaboratedType(Keyword, |
| 929 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 930 | T); |
| 931 | } |
| 932 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 933 | /// \brief Build a new typename type that refers to an identifier. |
| 934 | /// |
| 935 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 936 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 937 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 938 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 939 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 940 | NestedNameSpecifierLoc QualifierLoc, |
| 941 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 942 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 943 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 944 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 945 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 946 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 947 | // If the name is still dependent, just build a new dependent name type. |
| 948 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 949 | return SemaRef.Context.getDependentNameType(Keyword, |
| 950 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 951 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 954 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 955 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 956 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 957 | |
| 958 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 959 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 960 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 961 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 962 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 963 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 964 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 965 | if (!DC) |
| 966 | return QualType(); |
| 967 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 968 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 969 | return QualType(); |
| 970 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 971 | TagDecl *Tag = nullptr; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 972 | SemaRef.LookupQualifiedName(Result, DC); |
| 973 | switch (Result.getResultKind()) { |
| 974 | case LookupResult::NotFound: |
| 975 | case LookupResult::NotFoundInCurrentInstantiation: |
| 976 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 977 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 978 | case LookupResult::Found: |
| 979 | Tag = Result.getAsSingle<TagDecl>(); |
| 980 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 982 | case LookupResult::FoundOverloaded: |
| 983 | case LookupResult::FoundUnresolvedValue: |
| 984 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 985 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 986 | case LookupResult::Ambiguous: |
| 987 | // Let the LookupResult structure handle ambiguities. |
| 988 | return QualType(); |
| 989 | } |
| 990 | |
| 991 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 992 | // Check where the name exists but isn't a tag type and use that to emit |
| 993 | // better diagnostics. |
| 994 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 995 | SemaRef.LookupQualifiedName(Result, DC); |
| 996 | switch (Result.getResultKind()) { |
| 997 | case LookupResult::Found: |
| 998 | case LookupResult::FoundOverloaded: |
| 999 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1000 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1001 | unsigned Kind = 0; |
| 1002 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1003 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 1004 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1005 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 1006 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 1007 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1008 | } |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1009 | default: |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1010 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Stephan Tolksdorf | eb7708d | 2014-03-13 20:34:03 +0000 | [diff] [blame] | 1011 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1012 | break; |
| 1013 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1014 | return QualType(); |
| 1015 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1016 | |
Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 1017 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
Justin Bogner | c6ecb7c | 2015-07-10 23:05:47 +0000 | [diff] [blame] | 1018 | IdLoc, Id)) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1019 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1020 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 1021 | return QualType(); |
| 1022 | } |
| 1023 | |
| 1024 | // Build the elaborated-type-specifier type. |
| 1025 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1026 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1027 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1028 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1029 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1031 | /// \brief Build a new pack expansion type. |
| 1032 | /// |
| 1033 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 1034 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1035 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1036 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1037 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1038 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1039 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 1040 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1043 | /// \brief Build a new atomic type given its value type. |
| 1044 | /// |
| 1045 | /// By default, performs semantic analysis when building the atomic type. |
| 1046 | /// Subclasses may override this routine to provide different behavior. |
| 1047 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1048 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1049 | /// \brief Build a new template name given a nested name specifier, a flag |
| 1050 | /// indicating whether the "template" keyword was provided, and the template |
| 1051 | /// that the template name refers to. |
| 1052 | /// |
| 1053 | /// By default, builds the new template name directly. Subclasses may override |
| 1054 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1055 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1056 | bool TemplateKW, |
| 1057 | TemplateDecl *Template); |
| 1058 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1059 | /// \brief Build a new template name given a nested name specifier and the |
| 1060 | /// name that is referred to as a template. |
| 1061 | /// |
| 1062 | /// By default, performs semantic analysis to determine whether the name can |
| 1063 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1064 | /// template name. Subclasses may override this routine to provide different |
| 1065 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1066 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1067 | const IdentifierInfo &Name, |
| 1068 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1069 | QualType ObjectType, |
| 1070 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1072 | /// \brief Build a new template name given a nested name specifier and the |
| 1073 | /// overloaded operator name that is referred to as a template. |
| 1074 | /// |
| 1075 | /// By default, performs semantic analysis to determine whether the name can |
| 1076 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1077 | /// template name. Subclasses may override this routine to provide different |
| 1078 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1079 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1080 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1081 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1082 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1083 | |
| 1084 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1085 | /// and the |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1086 | /// |
| 1087 | /// By default, performs semantic analysis to determine whether the name can |
| 1088 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1089 | /// template name. Subclasses may override this routine to provide different |
| 1090 | /// behavior. |
| 1091 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1092 | const TemplateArgument &ArgPack) { |
| 1093 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1094 | } |
| 1095 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1096 | /// \brief Build a new compound statement. |
| 1097 | /// |
| 1098 | /// By default, performs semantic analysis to build the new statement. |
| 1099 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1100 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1101 | MultiStmtArg Statements, |
| 1102 | SourceLocation RBraceLoc, |
| 1103 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1104 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1105 | IsStmtExpr); |
| 1106 | } |
| 1107 | |
| 1108 | /// \brief Build a new case statement. |
| 1109 | /// |
| 1110 | /// By default, performs semantic analysis to build the new statement. |
| 1111 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1112 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1113 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1114 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1115 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1116 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1117 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1118 | ColonLoc); |
| 1119 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1120 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1121 | /// \brief Attach the body to a new case statement. |
| 1122 | /// |
| 1123 | /// By default, performs semantic analysis to build the new statement. |
| 1124 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1125 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1126 | getSema().ActOnCaseStmtBody(S, Body); |
| 1127 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1128 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1130 | /// \brief Build a new default statement. |
| 1131 | /// |
| 1132 | /// By default, performs semantic analysis to build the new statement. |
| 1133 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1134 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1135 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1136 | Stmt *SubStmt) { |
| 1137 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1138 | /*CurScope=*/nullptr); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1141 | /// \brief Build a new label statement. |
| 1142 | /// |
| 1143 | /// By default, performs semantic analysis to build the new statement. |
| 1144 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1145 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1146 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1147 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1148 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1150 | /// \brief Build a new label statement. |
| 1151 | /// |
| 1152 | /// By default, performs semantic analysis to build the new statement. |
| 1153 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1154 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1155 | ArrayRef<const Attr*> Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1156 | Stmt *SubStmt) { |
| 1157 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1158 | } |
| 1159 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1160 | /// \brief Build a new "if" statement. |
| 1161 | /// |
| 1162 | /// By default, performs semantic analysis to build the new statement. |
| 1163 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1164 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1165 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1166 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1167 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1170 | /// \brief Start building a new switch statement. |
| 1171 | /// |
| 1172 | /// By default, performs semantic analysis to build the new statement. |
| 1173 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1174 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1175 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1176 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1177 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1180 | /// \brief Attach the body to the switch statement. |
| 1181 | /// |
| 1182 | /// By default, performs semantic analysis to build the new statement. |
| 1183 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1184 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1185 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1186 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | /// \brief Build a new while statement. |
| 1190 | /// |
| 1191 | /// By default, performs semantic analysis to build the new statement. |
| 1192 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1193 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1194 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1195 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1196 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1198 | /// \brief Build a new do-while statement. |
| 1199 | /// |
| 1200 | /// By default, performs semantic analysis to build the new statement. |
| 1201 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1202 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1203 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1204 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1205 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1206 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | /// \brief Build a new for statement. |
| 1210 | /// |
| 1211 | /// By default, performs semantic analysis to build the new statement. |
| 1212 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1213 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1214 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1215 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1216 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1217 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1218 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1219 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1221 | /// \brief Build a new goto statement. |
| 1222 | /// |
| 1223 | /// By default, performs semantic analysis to build the new statement. |
| 1224 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1225 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1226 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1227 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | /// \brief Build a new indirect goto statement. |
| 1231 | /// |
| 1232 | /// By default, performs semantic analysis to build the new statement. |
| 1233 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1234 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1235 | SourceLocation StarLoc, |
| 1236 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1237 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1238 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1240 | /// \brief Build a new return statement. |
| 1241 | /// |
| 1242 | /// By default, performs semantic analysis to build the new statement. |
| 1243 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1244 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
Nick Lewycky | d78f92f | 2014-05-03 00:41:18 +0000 | [diff] [blame] | 1245 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1246 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1248 | /// \brief Build a new declaration statement. |
| 1249 | /// |
| 1250 | /// By default, performs semantic analysis to build the new statement. |
| 1251 | /// Subclasses may override this routine to provide different behavior. |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 1252 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1253 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1254 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1255 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1256 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1257 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1258 | /// \brief Build a new inline asm statement. |
| 1259 | /// |
| 1260 | /// By default, performs semantic analysis to build the new statement. |
| 1261 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1262 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1263 | bool IsVolatile, unsigned NumOutputs, |
| 1264 | unsigned NumInputs, IdentifierInfo **Names, |
| 1265 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1266 | Expr *AsmString, MultiExprArg Clobbers, |
| 1267 | SourceLocation RParenLoc) { |
| 1268 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1269 | NumInputs, Names, Constraints, Exprs, |
| 1270 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1271 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1272 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1273 | /// \brief Build a new MS style inline asm statement. |
| 1274 | /// |
| 1275 | /// By default, performs semantic analysis to build the new statement. |
| 1276 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1277 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1278 | ArrayRef<Token> AsmToks, |
| 1279 | StringRef AsmString, |
| 1280 | unsigned NumOutputs, unsigned NumInputs, |
| 1281 | ArrayRef<StringRef> Constraints, |
| 1282 | ArrayRef<StringRef> Clobbers, |
| 1283 | ArrayRef<Expr*> Exprs, |
| 1284 | SourceLocation EndLoc) { |
| 1285 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1286 | NumOutputs, NumInputs, |
| 1287 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1290 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1291 | /// |
| 1292 | /// By default, performs semantic analysis to build the new statement. |
| 1293 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1294 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1295 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1296 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1297 | Stmt *Finally) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1298 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1299 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1302 | /// \brief Rebuild an Objective-C exception declaration. |
| 1303 | /// |
| 1304 | /// By default, performs semantic analysis to build the new declaration. |
| 1305 | /// Subclasses may override this routine to provide different behavior. |
| 1306 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1307 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1308 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1309 | ExceptionDecl->getInnerLocStart(), |
| 1310 | ExceptionDecl->getLocation(), |
| 1311 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1312 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1313 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1314 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1315 | /// |
| 1316 | /// By default, performs semantic analysis to build the new statement. |
| 1317 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1318 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1319 | SourceLocation RParenLoc, |
| 1320 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1321 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1322 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1323 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1324 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1325 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1326 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1327 | /// |
| 1328 | /// By default, performs semantic analysis to build the new statement. |
| 1329 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1330 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1331 | Stmt *Body) { |
| 1332 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1333 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1334 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1335 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1336 | /// |
| 1337 | /// By default, performs semantic analysis to build the new statement. |
| 1338 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1339 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1340 | Expr *Operand) { |
| 1341 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1342 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1343 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1344 | /// \brief Build a new OpenMP executable directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1345 | /// |
| 1346 | /// By default, performs semantic analysis to build the new statement. |
| 1347 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1348 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1349 | DeclarationNameInfo DirName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1350 | OpenMPDirectiveKind CancelRegion, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1351 | ArrayRef<OMPClause *> Clauses, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1352 | Stmt *AStmt, SourceLocation StartLoc, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1353 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1354 | return getSema().ActOnOpenMPExecutableDirective( |
| 1355 | Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1358 | /// \brief Build a new OpenMP 'if' clause. |
| 1359 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1360 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1361 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1362 | OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, |
| 1363 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1364 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1365 | SourceLocation NameModifierLoc, |
| 1366 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1367 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1368 | return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc, |
| 1369 | LParenLoc, NameModifierLoc, ColonLoc, |
| 1370 | EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1373 | /// \brief Build a new OpenMP 'final' clause. |
| 1374 | /// |
| 1375 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1376 | /// Subclasses may override this routine to provide different behavior. |
| 1377 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1378 | SourceLocation LParenLoc, |
| 1379 | SourceLocation EndLoc) { |
| 1380 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
| 1381 | EndLoc); |
| 1382 | } |
| 1383 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1384 | /// \brief Build a new OpenMP 'num_threads' clause. |
| 1385 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1386 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1387 | /// Subclasses may override this routine to provide different behavior. |
| 1388 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
| 1389 | SourceLocation StartLoc, |
| 1390 | SourceLocation LParenLoc, |
| 1391 | SourceLocation EndLoc) { |
| 1392 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
| 1393 | LParenLoc, EndLoc); |
| 1394 | } |
| 1395 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1396 | /// \brief Build a new OpenMP 'safelen' clause. |
| 1397 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1398 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1399 | /// Subclasses may override this routine to provide different behavior. |
| 1400 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1401 | SourceLocation LParenLoc, |
| 1402 | SourceLocation EndLoc) { |
| 1403 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1404 | } |
| 1405 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1406 | /// \brief Build a new OpenMP 'simdlen' clause. |
| 1407 | /// |
| 1408 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1409 | /// Subclasses may override this routine to provide different behavior. |
| 1410 | OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 1411 | SourceLocation LParenLoc, |
| 1412 | SourceLocation EndLoc) { |
| 1413 | return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1414 | } |
| 1415 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1416 | /// \brief Build a new OpenMP 'collapse' clause. |
| 1417 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1418 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1419 | /// Subclasses may override this routine to provide different behavior. |
| 1420 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1421 | SourceLocation LParenLoc, |
| 1422 | SourceLocation EndLoc) { |
| 1423 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
| 1424 | EndLoc); |
| 1425 | } |
| 1426 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1427 | /// \brief Build a new OpenMP 'default' clause. |
| 1428 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1429 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1430 | /// Subclasses may override this routine to provide different behavior. |
| 1431 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1432 | SourceLocation KindKwLoc, |
| 1433 | SourceLocation StartLoc, |
| 1434 | SourceLocation LParenLoc, |
| 1435 | SourceLocation EndLoc) { |
| 1436 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1437 | StartLoc, LParenLoc, EndLoc); |
| 1438 | } |
| 1439 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1440 | /// \brief Build a new OpenMP 'proc_bind' clause. |
| 1441 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1442 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1443 | /// Subclasses may override this routine to provide different behavior. |
| 1444 | OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 1445 | SourceLocation KindKwLoc, |
| 1446 | SourceLocation StartLoc, |
| 1447 | SourceLocation LParenLoc, |
| 1448 | SourceLocation EndLoc) { |
| 1449 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
| 1450 | StartLoc, LParenLoc, EndLoc); |
| 1451 | } |
| 1452 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1453 | /// \brief Build a new OpenMP 'schedule' clause. |
| 1454 | /// |
| 1455 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1456 | /// Subclasses may override this routine to provide different behavior. |
| 1457 | OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind, |
| 1458 | Expr *ChunkSize, |
| 1459 | SourceLocation StartLoc, |
| 1460 | SourceLocation LParenLoc, |
| 1461 | SourceLocation KindLoc, |
| 1462 | SourceLocation CommaLoc, |
| 1463 | SourceLocation EndLoc) { |
| 1464 | return getSema().ActOnOpenMPScheduleClause( |
| 1465 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 1466 | } |
| 1467 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1468 | /// \brief Build a new OpenMP 'ordered' clause. |
| 1469 | /// |
| 1470 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1471 | /// Subclasses may override this routine to provide different behavior. |
| 1472 | OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, |
| 1473 | SourceLocation EndLoc, |
| 1474 | SourceLocation LParenLoc, Expr *Num) { |
| 1475 | return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); |
| 1476 | } |
| 1477 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1478 | /// \brief Build a new OpenMP 'private' clause. |
| 1479 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1480 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1481 | /// Subclasses may override this routine to provide different behavior. |
| 1482 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1483 | SourceLocation StartLoc, |
| 1484 | SourceLocation LParenLoc, |
| 1485 | SourceLocation EndLoc) { |
| 1486 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1487 | EndLoc); |
| 1488 | } |
| 1489 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1490 | /// \brief Build a new OpenMP 'firstprivate' clause. |
| 1491 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1492 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1493 | /// Subclasses may override this routine to provide different behavior. |
| 1494 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1495 | SourceLocation StartLoc, |
| 1496 | SourceLocation LParenLoc, |
| 1497 | SourceLocation EndLoc) { |
| 1498 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1499 | EndLoc); |
| 1500 | } |
| 1501 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1502 | /// \brief Build a new OpenMP 'lastprivate' clause. |
| 1503 | /// |
| 1504 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1505 | /// Subclasses may override this routine to provide different behavior. |
| 1506 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1507 | SourceLocation StartLoc, |
| 1508 | SourceLocation LParenLoc, |
| 1509 | SourceLocation EndLoc) { |
| 1510 | return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, |
| 1511 | EndLoc); |
| 1512 | } |
| 1513 | |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1514 | /// \brief Build a new OpenMP 'shared' clause. |
| 1515 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1516 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1517 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1518 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1519 | SourceLocation StartLoc, |
| 1520 | SourceLocation LParenLoc, |
| 1521 | SourceLocation EndLoc) { |
| 1522 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1523 | EndLoc); |
| 1524 | } |
| 1525 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1526 | /// \brief Build a new OpenMP 'reduction' clause. |
| 1527 | /// |
| 1528 | /// By default, performs semantic analysis to build the new statement. |
| 1529 | /// Subclasses may override this routine to provide different behavior. |
| 1530 | OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList, |
| 1531 | SourceLocation StartLoc, |
| 1532 | SourceLocation LParenLoc, |
| 1533 | SourceLocation ColonLoc, |
| 1534 | SourceLocation EndLoc, |
| 1535 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1536 | const DeclarationNameInfo &ReductionId) { |
| 1537 | return getSema().ActOnOpenMPReductionClause( |
| 1538 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1539 | ReductionId); |
| 1540 | } |
| 1541 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1542 | /// \brief Build a new OpenMP 'linear' clause. |
| 1543 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1544 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1545 | /// Subclasses may override this routine to provide different behavior. |
| 1546 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1547 | SourceLocation StartLoc, |
| 1548 | SourceLocation LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1549 | OpenMPLinearClauseKind Modifier, |
| 1550 | SourceLocation ModifierLoc, |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1551 | SourceLocation ColonLoc, |
| 1552 | SourceLocation EndLoc) { |
| 1553 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1554 | Modifier, ModifierLoc, ColonLoc, |
| 1555 | EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1558 | /// \brief Build a new OpenMP 'aligned' clause. |
| 1559 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1560 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1561 | /// Subclasses may override this routine to provide different behavior. |
| 1562 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 1563 | SourceLocation StartLoc, |
| 1564 | SourceLocation LParenLoc, |
| 1565 | SourceLocation ColonLoc, |
| 1566 | SourceLocation EndLoc) { |
| 1567 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
| 1568 | LParenLoc, ColonLoc, EndLoc); |
| 1569 | } |
| 1570 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1571 | /// \brief Build a new OpenMP 'copyin' clause. |
| 1572 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1573 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1574 | /// Subclasses may override this routine to provide different behavior. |
| 1575 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1576 | SourceLocation StartLoc, |
| 1577 | SourceLocation LParenLoc, |
| 1578 | SourceLocation EndLoc) { |
| 1579 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
| 1580 | EndLoc); |
| 1581 | } |
| 1582 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1583 | /// \brief Build a new OpenMP 'copyprivate' clause. |
| 1584 | /// |
| 1585 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1586 | /// Subclasses may override this routine to provide different behavior. |
| 1587 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 1588 | SourceLocation StartLoc, |
| 1589 | SourceLocation LParenLoc, |
| 1590 | SourceLocation EndLoc) { |
| 1591 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
| 1592 | EndLoc); |
| 1593 | } |
| 1594 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1595 | /// \brief Build a new OpenMP 'flush' pseudo clause. |
| 1596 | /// |
| 1597 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1598 | /// Subclasses may override this routine to provide different behavior. |
| 1599 | OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
| 1600 | SourceLocation StartLoc, |
| 1601 | SourceLocation LParenLoc, |
| 1602 | SourceLocation EndLoc) { |
| 1603 | return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, |
| 1604 | EndLoc); |
| 1605 | } |
| 1606 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1607 | /// \brief Build a new OpenMP 'depend' pseudo clause. |
| 1608 | /// |
| 1609 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1610 | /// Subclasses may override this routine to provide different behavior. |
| 1611 | OMPClause * |
| 1612 | RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc, |
| 1613 | SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 1614 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1615 | SourceLocation EndLoc) { |
| 1616 | return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList, |
| 1617 | StartLoc, LParenLoc, EndLoc); |
| 1618 | } |
| 1619 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1620 | /// \brief Build a new OpenMP 'device' clause. |
| 1621 | /// |
| 1622 | /// By default, performs semantic analysis to build the new statement. |
| 1623 | /// Subclasses may override this routine to provide different behavior. |
| 1624 | OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 1625 | SourceLocation LParenLoc, |
| 1626 | SourceLocation EndLoc) { |
| 1627 | return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc, |
| 1628 | EndLoc); |
| 1629 | } |
| 1630 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1631 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1632 | /// |
| 1633 | /// By default, performs semantic analysis to build the new statement. |
| 1634 | /// Subclasses may override this routine to provide different behavior. |
| 1635 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1636 | Expr *object) { |
| 1637 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1638 | } |
| 1639 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1640 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1641 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1642 | /// By default, performs semantic analysis to build the new statement. |
| 1643 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1644 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1645 | Expr *Object, Stmt *Body) { |
| 1646 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1647 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1648 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1649 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1650 | /// |
| 1651 | /// By default, performs semantic analysis to build the new statement. |
| 1652 | /// Subclasses may override this routine to provide different behavior. |
| 1653 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1654 | Stmt *Body) { |
| 1655 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1656 | } |
John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1657 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1658 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1659 | /// |
| 1660 | /// By default, performs semantic analysis to build the new statement. |
| 1661 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1662 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1663 | Stmt *Element, |
| 1664 | Expr *Collection, |
| 1665 | SourceLocation RParenLoc, |
| 1666 | Stmt *Body) { |
Sam Panzer | 2c4ca0f | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1667 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1668 | Element, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1669 | Collection, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1670 | RParenLoc); |
| 1671 | if (ForEachStmt.isInvalid()) |
| 1672 | return StmtError(); |
| 1673 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1674 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1675 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1676 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1677 | /// \brief Build a new C++ exception declaration. |
| 1678 | /// |
| 1679 | /// By default, performs semantic analysis to build the new decaration. |
| 1680 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1681 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1682 | TypeSourceInfo *Declarator, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1683 | SourceLocation StartLoc, |
| 1684 | SourceLocation IdLoc, |
| 1685 | IdentifierInfo *Id) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1686 | VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1687 | StartLoc, IdLoc, Id); |
| 1688 | if (Var) |
| 1689 | getSema().CurContext->addDecl(Var); |
| 1690 | return Var; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | /// \brief Build a new C++ catch statement. |
| 1694 | /// |
| 1695 | /// By default, performs semantic analysis to build the new statement. |
| 1696 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1697 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1698 | VarDecl *ExceptionDecl, |
| 1699 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1700 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1701 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1702 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1703 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1704 | /// \brief Build a new C++ try statement. |
| 1705 | /// |
| 1706 | /// By default, performs semantic analysis to build the new statement. |
| 1707 | /// Subclasses may override this routine to provide different behavior. |
Robert Wilhelm | cafda82 | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 1708 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 1709 | ArrayRef<Stmt *> Handlers) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1710 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1711 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1712 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1713 | /// \brief Build a new C++0x range-based for statement. |
| 1714 | /// |
| 1715 | /// By default, performs semantic analysis to build the new statement. |
| 1716 | /// Subclasses may override this routine to provide different behavior. |
| 1717 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1718 | SourceLocation ColonLoc, |
| 1719 | Stmt *Range, Stmt *BeginEnd, |
| 1720 | Expr *Cond, Expr *Inc, |
| 1721 | Stmt *LoopVar, |
| 1722 | SourceLocation RParenLoc) { |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1723 | // If we've just learned that the range is actually an Objective-C |
| 1724 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1725 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1726 | if (RangeStmt->isSingleDecl()) { |
| 1727 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1728 | if (RangeVar->isInvalidDecl()) |
| 1729 | return StmtError(); |
| 1730 | |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1731 | Expr *RangeExpr = RangeVar->getInit(); |
| 1732 | if (!RangeExpr->isTypeDependent() && |
| 1733 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1734 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1735 | RParenLoc); |
| 1736 | } |
| 1737 | } |
| 1738 | } |
| 1739 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1740 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | a05b3b5 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1741 | Cond, Inc, LoopVar, RParenLoc, |
| 1742 | Sema::BFRK_Rebuild); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1743 | } |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1744 | |
| 1745 | /// \brief Build a new C++0x range-based for statement. |
| 1746 | /// |
| 1747 | /// By default, performs semantic analysis to build the new statement. |
| 1748 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1749 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1750 | bool IsIfExists, |
| 1751 | NestedNameSpecifierLoc QualifierLoc, |
| 1752 | DeclarationNameInfo NameInfo, |
| 1753 | Stmt *Nested) { |
| 1754 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1755 | QualifierLoc, NameInfo, Nested); |
| 1756 | } |
| 1757 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1758 | /// \brief Attach body to a C++0x range-based for statement. |
| 1759 | /// |
| 1760 | /// By default, performs semantic analysis to finish the new statement. |
| 1761 | /// Subclasses may override this routine to provide different behavior. |
| 1762 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1763 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1764 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1765 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1766 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1767 | Stmt *TryBlock, Stmt *Handler) { |
| 1768 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1771 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1772 | Stmt *Block) { |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1773 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1776 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
Nico Weber | d64657f | 2015-03-09 02:47:59 +0000 | [diff] [blame] | 1777 | return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 1780 | /// \brief Build a new predefined expression. |
| 1781 | /// |
| 1782 | /// By default, performs semantic analysis to build the new expression. |
| 1783 | /// Subclasses may override this routine to provide different behavior. |
| 1784 | ExprResult RebuildPredefinedExpr(SourceLocation Loc, |
| 1785 | PredefinedExpr::IdentType IT) { |
| 1786 | return getSema().BuildPredefinedExpr(Loc, IT); |
| 1787 | } |
| 1788 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1789 | /// \brief Build a new expression that references a declaration. |
| 1790 | /// |
| 1791 | /// By default, performs semantic analysis to build the new expression. |
| 1792 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1793 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1794 | LookupResult &R, |
| 1795 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1796 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1797 | } |
| 1798 | |
| 1799 | |
| 1800 | /// \brief Build a new expression that references a declaration. |
| 1801 | /// |
| 1802 | /// By default, performs semantic analysis to build the new expression. |
| 1803 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1804 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1805 | ValueDecl *VD, |
| 1806 | const DeclarationNameInfo &NameInfo, |
| 1807 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1808 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1809 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1810 | |
| 1811 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1812 | |
| 1813 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1814 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1815 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1816 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1817 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1818 | /// By default, performs semantic analysis to build the new expression. |
| 1819 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1820 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1821 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1822 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1825 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1826 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1827 | /// By default, performs semantic analysis to build the new expression. |
| 1828 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1829 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1830 | SourceLocation OperatorLoc, |
| 1831 | bool isArrow, |
| 1832 | CXXScopeSpec &SS, |
| 1833 | TypeSourceInfo *ScopeType, |
| 1834 | SourceLocation CCLoc, |
| 1835 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1836 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1837 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1838 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1840 | /// By default, performs semantic analysis to build the new expression. |
| 1841 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1842 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1843 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1844 | Expr *SubExpr) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1845 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1846 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1848 | /// \brief Build a new builtin offsetof expression. |
| 1849 | /// |
| 1850 | /// By default, performs semantic analysis to build the new expression. |
| 1851 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1852 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame^] | 1853 | TypeSourceInfo *Type, |
| 1854 | ArrayRef<Sema::OffsetOfComponent> Components, |
| 1855 | SourceLocation RParenLoc) { |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1856 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame^] | 1857 | RParenLoc); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1858 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1859 | |
| 1860 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1861 | /// type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1862 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1863 | /// By default, performs semantic analysis to build the new expression. |
| 1864 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1865 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1866 | SourceLocation OpLoc, |
| 1867 | UnaryExprOrTypeTrait ExprKind, |
| 1868 | SourceRange R) { |
| 1869 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1872 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1873 | /// expression argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1874 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1875 | /// By default, performs semantic analysis to build the new expression. |
| 1876 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1877 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1878 | UnaryExprOrTypeTrait ExprKind, |
| 1879 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1880 | ExprResult Result |
Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1881 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1882 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1883 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1884 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1885 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1886 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1888 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1889 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1890 | /// By default, performs semantic analysis to build the new expression. |
| 1891 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1892 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1893 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1894 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1895 | SourceLocation RBracketLoc) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1896 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1897 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1898 | RBracketLoc); |
| 1899 | } |
| 1900 | |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 1901 | /// \brief Build a new array section expression. |
| 1902 | /// |
| 1903 | /// By default, performs semantic analysis to build the new expression. |
| 1904 | /// Subclasses may override this routine to provide different behavior. |
| 1905 | ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, |
| 1906 | Expr *LowerBound, |
| 1907 | SourceLocation ColonLoc, Expr *Length, |
| 1908 | SourceLocation RBracketLoc) { |
| 1909 | return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound, |
| 1910 | ColonLoc, Length, RBracketLoc); |
| 1911 | } |
| 1912 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1913 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1914 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1915 | /// By default, performs semantic analysis to build the new expression. |
| 1916 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1917 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1918 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1919 | SourceLocation RParenLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1920 | Expr *ExecConfig = nullptr) { |
| 1921 | return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1922 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1926 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1927 | /// By default, performs semantic analysis to build the new expression. |
| 1928 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1929 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1930 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1931 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1932 | SourceLocation TemplateKWLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1933 | const DeclarationNameInfo &MemberNameInfo, |
| 1934 | ValueDecl *Member, |
| 1935 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1936 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1937 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1938 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1939 | isArrow); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1940 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1941 | // We have a reference to an unnamed field. This is always the |
| 1942 | // base of an anonymous struct/union member access, i.e. the |
| 1943 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1944 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1945 | assert(Member->getType()->isRecordType() && |
| 1946 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1947 | |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1948 | BaseResult = |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1949 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1950 | QualifierLoc.getNestedNameSpecifier(), |
| 1951 | FoundDecl, Member); |
| 1952 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1953 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1954 | Base = BaseResult.get(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1955 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Aaron Ballman | f4cb2be | 2015-03-24 15:07:53 +0000 | [diff] [blame] | 1956 | MemberExpr *ME = new (getSema().Context) |
| 1957 | MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo, |
| 1958 | cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1959 | return ME; |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1960 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1961 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1962 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1963 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1964 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1965 | Base = BaseResult.get(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1966 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1967 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1968 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1969 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1970 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1971 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1972 | R.resolveKind(); |
| 1973 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1974 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1975 | SS, TemplateKWLoc, |
| 1976 | FirstQualifierInScope, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 1977 | R, ExplicitTemplateArgs, |
| 1978 | /*S*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1979 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1980 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1981 | /// \brief Build a new binary operator expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1984 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1985 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1986 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1987 | Expr *LHS, Expr *RHS) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1988 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | /// By default, performs semantic analysis to build the new expression. |
| 1994 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1995 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1996 | SourceLocation QuestionLoc, |
| 1997 | Expr *LHS, |
| 1998 | SourceLocation ColonLoc, |
| 1999 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2000 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 2001 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2004 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2005 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2006 | /// By default, performs semantic analysis to build the new expression. |
| 2007 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2008 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2009 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2010 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2011 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 2012 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2013 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | } |
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 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2018 | /// By default, performs semantic analysis to build the new expression. |
| 2019 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2020 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 2021 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2022 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2023 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 2024 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2025 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2026 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2027 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2028 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2030 | /// By default, performs semantic analysis to build the new expression. |
| 2031 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2032 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2033 | SourceLocation OpLoc, |
| 2034 | SourceLocation AccessorLoc, |
| 2035 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2036 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2037 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2038 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2039 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2040 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2041 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2042 | /*FirstQualifierInScope*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2043 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2044 | /* TemplateArgs */ nullptr, |
| 2045 | /*S*/ nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2046 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2047 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2048 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2049 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2050 | /// By default, performs semantic analysis to build the new expression. |
| 2051 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2052 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2053 | MultiExprArg Inits, |
| 2054 | SourceLocation RBraceLoc, |
| 2055 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2056 | ExprResult Result |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2057 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 2058 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2059 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2060 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 2061 | // Patch in the result type we were given, which may have been computed |
| 2062 | // when the initial InitListExpr was built. |
| 2063 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 2064 | ILE->setType(ResultTy); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2065 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2066 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2068 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2069 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2070 | /// By default, performs semantic analysis to build the new expression. |
| 2071 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2072 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2073 | MultiExprArg ArrayExprs, |
| 2074 | SourceLocation EqualOrColonLoc, |
| 2075 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2076 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2077 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2078 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2079 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2080 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2081 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2082 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2083 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2084 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2085 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2086 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2087 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2088 | /// By default, builds the implicit value initialization without performing |
| 2089 | /// any semantic analysis. Subclasses may override this routine to provide |
| 2090 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2091 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2092 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2093 | } |
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 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2096 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2097 | /// By default, performs semantic analysis to build the new expression. |
| 2098 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2099 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2100 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2101 | SourceLocation RParenLoc) { |
| 2102 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2103 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2104 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2108 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2109 | /// By default, performs semantic analysis to build the new expression. |
| 2110 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2111 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 2112 | MultiExprArg SubExprs, |
| 2113 | SourceLocation RParenLoc) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2114 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2115 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2116 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2117 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2118 | /// |
| 2119 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2120 | /// rather than attempting to map the label statement itself. |
| 2121 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2122 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 2123 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2124 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2127 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2128 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2129 | /// By default, performs semantic analysis to build the new expression. |
| 2130 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2131 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2132 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2133 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2134 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2135 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2137 | /// \brief Build a new __builtin_choose_expr expression. |
| 2138 | /// |
| 2139 | /// By default, performs semantic analysis to build the new expression. |
| 2140 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2141 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2142 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2143 | SourceLocation RParenLoc) { |
| 2144 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2145 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2146 | RParenLoc); |
| 2147 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2148 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2149 | /// \brief Build a new generic selection expression. |
| 2150 | /// |
| 2151 | /// By default, performs semantic analysis to build the new expression. |
| 2152 | /// Subclasses may override this routine to provide different behavior. |
| 2153 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2154 | SourceLocation DefaultLoc, |
| 2155 | SourceLocation RParenLoc, |
| 2156 | Expr *ControllingExpr, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2157 | ArrayRef<TypeSourceInfo *> Types, |
| 2158 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2159 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2160 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2163 | /// \brief Build a new overloaded operator call expression. |
| 2164 | /// |
| 2165 | /// By default, performs semantic analysis to build the new expression. |
| 2166 | /// The semantic analysis provides the behavior of template instantiation, |
| 2167 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2168 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2169 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2170 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2171 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2172 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2173 | Expr *Callee, |
| 2174 | Expr *First, |
| 2175 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | |
| 2177 | /// \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] | 2178 | /// reinterpret_cast. |
| 2179 | /// |
| 2180 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2181 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2182 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2183 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2184 | Stmt::StmtClass Class, |
| 2185 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2186 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2187 | SourceLocation RAngleLoc, |
| 2188 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2189 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2190 | SourceLocation RParenLoc) { |
| 2191 | switch (Class) { |
| 2192 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2193 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2194 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2195 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2196 | |
| 2197 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2198 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2199 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2200 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2201 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2202 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2203 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2204 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2205 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2206 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2207 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2208 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2209 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2210 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2211 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2213 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2214 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2215 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2216 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2217 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2218 | /// \brief Build a new C++ static_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 RebuildCXXStaticCastExpr(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_static_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++ dynamic_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 RebuildCXXDynamicCastExpr(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_dynamic_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 | } |
| 2251 | |
| 2252 | /// \brief Build a new C++ reinterpret_cast expression. |
| 2253 | /// |
| 2254 | /// By default, performs semantic analysis to build the new expression. |
| 2255 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2256 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2257 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2258 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2259 | SourceLocation RAngleLoc, |
| 2260 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2261 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2262 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2263 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2264 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2265 | SourceRange(LAngleLoc, RAngleLoc), |
| 2266 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | /// \brief Build a new C++ const_cast expression. |
| 2270 | /// |
| 2271 | /// By default, performs semantic analysis to build the new expression. |
| 2272 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2273 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2274 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2275 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2276 | SourceLocation RAngleLoc, |
| 2277 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2278 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2279 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2280 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2281 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2282 | SourceRange(LAngleLoc, RAngleLoc), |
| 2283 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2284 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2285 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2286 | /// \brief Build a new C++ functional-style cast expression. |
| 2287 | /// |
| 2288 | /// By default, performs semantic analysis to build the new expression. |
| 2289 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2290 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2291 | SourceLocation LParenLoc, |
| 2292 | Expr *Sub, |
| 2293 | SourceLocation RParenLoc) { |
| 2294 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2295 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2296 | RParenLoc); |
| 2297 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2299 | /// \brief Build a new C++ typeid(type) expression. |
| 2300 | /// |
| 2301 | /// By default, performs semantic analysis to build the new expression. |
| 2302 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2303 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2304 | SourceLocation TypeidLoc, |
| 2305 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2306 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2307 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2308 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2310 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2311 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2312 | /// \brief Build a new C++ typeid(expr) expression. |
| 2313 | /// |
| 2314 | /// By default, performs semantic analysis to build the new expression. |
| 2315 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2316 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2317 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2318 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2319 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2320 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2321 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2324 | /// \brief Build a new C++ __uuidof(type) expression. |
| 2325 | /// |
| 2326 | /// By default, performs semantic analysis to build the new expression. |
| 2327 | /// Subclasses may override this routine to provide different behavior. |
| 2328 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2329 | SourceLocation TypeidLoc, |
| 2330 | TypeSourceInfo *Operand, |
| 2331 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2332 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2333 | RParenLoc); |
| 2334 | } |
| 2335 | |
| 2336 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2337 | /// |
| 2338 | /// By default, performs semantic analysis to build the new expression. |
| 2339 | /// Subclasses may override this routine to provide different behavior. |
| 2340 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2341 | SourceLocation TypeidLoc, |
| 2342 | Expr *Operand, |
| 2343 | SourceLocation RParenLoc) { |
| 2344 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2345 | RParenLoc); |
| 2346 | } |
| 2347 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2348 | /// \brief Build a new C++ "this" expression. |
| 2349 | /// |
| 2350 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2351 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2352 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2353 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2354 | QualType ThisType, |
| 2355 | bool isImplicit) { |
Eli Friedman | 20139d3 | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2356 | getSema().CheckCXXThisCapture(ThisLoc); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2357 | return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | /// \brief Build a new C++ throw expression. |
| 2361 | /// |
| 2362 | /// By default, performs semantic analysis to build the new expression. |
| 2363 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2364 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2365 | bool IsThrownVariableInScope) { |
| 2366 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | /// \brief Build a new C++ default-argument expression. |
| 2370 | /// |
| 2371 | /// By default, builds a new default-argument expression, which does not |
| 2372 | /// require any semantic analysis. Subclasses may override this routine to |
| 2373 | /// provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2374 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2375 | ParmVarDecl *Param) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2376 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2377 | } |
| 2378 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2379 | /// \brief Build a new C++11 default-initialization expression. |
| 2380 | /// |
| 2381 | /// By default, builds a new default field initialization expression, which |
| 2382 | /// does not require any semantic analysis. Subclasses may override this |
| 2383 | /// routine to provide different behavior. |
| 2384 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2385 | FieldDecl *Field) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2386 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field); |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2389 | /// \brief Build a new C++ zero-initialization expression. |
| 2390 | /// |
| 2391 | /// By default, performs semantic analysis to build the new expression. |
| 2392 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2393 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2394 | SourceLocation LParenLoc, |
| 2395 | SourceLocation RParenLoc) { |
| 2396 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2397 | None, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2398 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2399 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2400 | /// \brief Build a new C++ "new" expression. |
| 2401 | /// |
| 2402 | /// By default, performs semantic analysis to build the new expression. |
| 2403 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2404 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2405 | bool UseGlobal, |
| 2406 | SourceLocation PlacementLParen, |
| 2407 | MultiExprArg PlacementArgs, |
| 2408 | SourceLocation PlacementRParen, |
| 2409 | SourceRange TypeIdParens, |
| 2410 | QualType AllocatedType, |
| 2411 | TypeSourceInfo *AllocatedTypeInfo, |
| 2412 | Expr *ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2413 | SourceRange DirectInitRange, |
| 2414 | Expr *Initializer) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2415 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2416 | PlacementLParen, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2417 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2418 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2419 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2420 | AllocatedType, |
| 2421 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2422 | ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2423 | DirectInitRange, |
| 2424 | Initializer); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2425 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2426 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2427 | /// \brief Build a new C++ "delete" expression. |
| 2428 | /// |
| 2429 | /// By default, performs semantic analysis to build the new expression. |
| 2430 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2431 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2432 | bool IsGlobalDelete, |
| 2433 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2434 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2435 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2436 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2438 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2439 | /// \brief Build a new type trait expression. |
| 2440 | /// |
| 2441 | /// By default, performs semantic analysis to build the new expression. |
| 2442 | /// Subclasses may override this routine to provide different behavior. |
| 2443 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2444 | SourceLocation StartLoc, |
| 2445 | ArrayRef<TypeSourceInfo *> Args, |
| 2446 | SourceLocation RParenLoc) { |
| 2447 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2448 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2449 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2450 | /// \brief Build a new array type trait expression. |
| 2451 | /// |
| 2452 | /// By default, performs semantic analysis to build the new expression. |
| 2453 | /// Subclasses may override this routine to provide different behavior. |
| 2454 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2455 | SourceLocation StartLoc, |
| 2456 | TypeSourceInfo *TSInfo, |
| 2457 | Expr *DimExpr, |
| 2458 | SourceLocation RParenLoc) { |
| 2459 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2460 | } |
| 2461 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2462 | /// \brief Build a new expression trait expression. |
| 2463 | /// |
| 2464 | /// By default, performs semantic analysis to build the new expression. |
| 2465 | /// Subclasses may override this routine to provide different behavior. |
| 2466 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2467 | SourceLocation StartLoc, |
| 2468 | Expr *Queried, |
| 2469 | SourceLocation RParenLoc) { |
| 2470 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2471 | } |
| 2472 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2473 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2474 | /// expression. |
| 2475 | /// |
| 2476 | /// By default, performs semantic analysis to build the new expression. |
| 2477 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2478 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2479 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2480 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2481 | const DeclarationNameInfo &NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2482 | const TemplateArgumentListInfo *TemplateArgs, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2483 | bool IsAddressOfOperand, |
| 2484 | TypeSourceInfo **RecoveryTSI) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2485 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2486 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2487 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2488 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2489 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2490 | TemplateArgs); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2491 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2492 | return getSema().BuildQualifiedDeclarationNameExpr( |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2493 | SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | /// \brief Build a new template-id expression. |
| 2497 | /// |
| 2498 | /// By default, performs semantic analysis to build the new expression. |
| 2499 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2500 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2501 | SourceLocation TemplateKWLoc, |
| 2502 | LookupResult &R, |
| 2503 | bool RequiresADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2504 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2505 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2506 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | /// \brief Build a new object-construction expression. |
| 2510 | /// |
| 2511 | /// By default, performs semantic analysis to build the new expression. |
| 2512 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2513 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2514 | SourceLocation Loc, |
| 2515 | CXXConstructorDecl *Constructor, |
| 2516 | bool IsElidable, |
| 2517 | MultiExprArg Args, |
| 2518 | bool HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2519 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2520 | bool StdInitListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2521 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2522 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2523 | SourceRange ParenRange) { |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2524 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2525 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2526 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2527 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2528 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2529 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2530 | ConvertedArgs, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2531 | HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2532 | ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2533 | StdInitListInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2534 | RequiresZeroInit, ConstructKind, |
| 2535 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | /// \brief Build a new object-construction expression. |
| 2539 | /// |
| 2540 | /// By default, performs semantic analysis to build the new expression. |
| 2541 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2542 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2543 | SourceLocation LParenLoc, |
| 2544 | MultiExprArg Args, |
| 2545 | SourceLocation RParenLoc) { |
| 2546 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2547 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2548 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2549 | RParenLoc); |
| 2550 | } |
| 2551 | |
| 2552 | /// \brief Build a new object-construction expression. |
| 2553 | /// |
| 2554 | /// By default, performs semantic analysis to build the new expression. |
| 2555 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2556 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2557 | SourceLocation LParenLoc, |
| 2558 | MultiExprArg Args, |
| 2559 | SourceLocation RParenLoc) { |
| 2560 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2561 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2562 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2563 | RParenLoc); |
| 2564 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2565 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2566 | /// \brief Build a new member reference expression. |
| 2567 | /// |
| 2568 | /// By default, performs semantic analysis to build the new expression. |
| 2569 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2570 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2571 | QualType BaseType, |
| 2572 | bool IsArrow, |
| 2573 | SourceLocation OperatorLoc, |
| 2574 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2575 | SourceLocation TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2576 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2577 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2578 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2579 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2580 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2581 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2582 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2583 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2584 | SS, TemplateKWLoc, |
| 2585 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2586 | MemberNameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2587 | TemplateArgs, /*S*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2590 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2591 | /// |
| 2592 | /// By default, performs semantic analysis to build the new expression. |
| 2593 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2594 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2595 | SourceLocation OperatorLoc, |
| 2596 | bool IsArrow, |
| 2597 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2598 | SourceLocation TemplateKWLoc, |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2599 | NamedDecl *FirstQualifierInScope, |
| 2600 | LookupResult &R, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2601 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2602 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2603 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2604 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2605 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2606 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2607 | SS, TemplateKWLoc, |
| 2608 | FirstQualifierInScope, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2609 | R, TemplateArgs, /*S*/nullptr); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2610 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2611 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2612 | /// \brief Build a new noexcept expression. |
| 2613 | /// |
| 2614 | /// By default, performs semantic analysis to build the new expression. |
| 2615 | /// Subclasses may override this routine to provide different behavior. |
| 2616 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2617 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2618 | } |
| 2619 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2620 | /// \brief Build a new expression to compute the length of a parameter pack. |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 2621 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, |
| 2622 | NamedDecl *Pack, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2623 | SourceLocation PackLoc, |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2624 | SourceLocation RParenLoc, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 2625 | Optional<unsigned> Length, |
| 2626 | ArrayRef<TemplateArgument> PartialArgs) { |
| 2627 | return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, |
| 2628 | RParenLoc, Length, PartialArgs); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2629 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2630 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2631 | /// \brief Build a new Objective-C boxed expression. |
| 2632 | /// |
| 2633 | /// By default, performs semantic analysis to build the new expression. |
| 2634 | /// Subclasses may override this routine to provide different behavior. |
| 2635 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2636 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2637 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2638 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2639 | /// \brief Build a new Objective-C array literal. |
| 2640 | /// |
| 2641 | /// By default, performs semantic analysis to build the new expression. |
| 2642 | /// Subclasses may override this routine to provide different behavior. |
| 2643 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2644 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2645 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2646 | MultiExprArg(Elements, NumElements)); |
| 2647 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2648 | |
| 2649 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2650 | Expr *Base, Expr *Key, |
| 2651 | ObjCMethodDecl *getterMethod, |
| 2652 | ObjCMethodDecl *setterMethod) { |
| 2653 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2654 | getterMethod, setterMethod); |
| 2655 | } |
| 2656 | |
| 2657 | /// \brief Build a new Objective-C dictionary literal. |
| 2658 | /// |
| 2659 | /// By default, performs semantic analysis to build the new expression. |
| 2660 | /// Subclasses may override this routine to provide different behavior. |
| 2661 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2662 | ObjCDictionaryElement *Elements, |
| 2663 | unsigned NumElements) { |
| 2664 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2665 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2666 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2667 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2668 | /// |
| 2669 | /// By default, performs semantic analysis to build the new expression. |
| 2670 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2671 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2672 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2673 | SourceLocation RParenLoc) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2674 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2675 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2676 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2677 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2678 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2679 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2680 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2681 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2682 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2683 | MultiExprArg Args, |
| 2684 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2685 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2686 | ReceiverTypeInfo->getType(), |
| 2687 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2688 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2689 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2693 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2694 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2695 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2696 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2697 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2698 | MultiExprArg Args, |
| 2699 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2700 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2701 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2702 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2703 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2704 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2707 | /// \brief Build a new Objective-C instance/class message to 'super'. |
| 2708 | ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, |
| 2709 | Selector Sel, |
| 2710 | ArrayRef<SourceLocation> SelectorLocs, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2711 | QualType SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2712 | ObjCMethodDecl *Method, |
| 2713 | SourceLocation LBracLoc, |
| 2714 | MultiExprArg Args, |
| 2715 | SourceLocation RBracLoc) { |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2716 | return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2717 | SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2718 | SuperLoc, |
| 2719 | Sel, Method, LBracLoc, SelectorLocs, |
| 2720 | RBracLoc, Args) |
| 2721 | : SemaRef.BuildClassMessage(nullptr, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2722 | SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2723 | SuperLoc, |
| 2724 | Sel, Method, LBracLoc, SelectorLocs, |
| 2725 | RBracLoc, Args); |
| 2726 | |
| 2727 | |
| 2728 | } |
| 2729 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2730 | /// \brief Build a new Objective-C ivar reference expression. |
| 2731 | /// |
| 2732 | /// By default, performs semantic analysis to build the new expression. |
| 2733 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2734 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2735 | SourceLocation IvarLoc, |
| 2736 | bool IsArrow, bool IsFreeIvar) { |
| 2737 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2738 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2739 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| 2740 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2741 | /*FIXME:*/IvarLoc, IsArrow, |
| 2742 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2743 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2744 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2745 | /*TemplateArgs=*/nullptr, |
| 2746 | /*S=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2747 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2748 | |
| 2749 | /// \brief Build a new Objective-C property reference expression. |
| 2750 | /// |
| 2751 | /// By default, performs semantic analysis to build the new expression. |
| 2752 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2753 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2754 | ObjCPropertyDecl *Property, |
| 2755 | SourceLocation PropertyLoc) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2756 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2757 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 2758 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 2759 | /*FIXME:*/PropertyLoc, |
| 2760 | /*IsArrow=*/false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2761 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2762 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2763 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2764 | /*TemplateArgs=*/nullptr, |
| 2765 | /*S=*/nullptr); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2766 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2767 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2768 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2769 | /// |
| 2770 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2771 | /// Subclasses may override this routine to provide different behavior. |
| 2772 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2773 | ObjCMethodDecl *Getter, |
| 2774 | ObjCMethodDecl *Setter, |
| 2775 | SourceLocation PropertyLoc) { |
| 2776 | // Since these expressions can only be value-dependent, we do not |
| 2777 | // need to perform semantic analysis again. |
| 2778 | return Owned( |
| 2779 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2780 | VK_LValue, OK_ObjCProperty, |
| 2781 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2784 | /// \brief Build a new Objective-C "isa" expression. |
| 2785 | /// |
| 2786 | /// By default, performs semantic analysis to build the new expression. |
| 2787 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2788 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2789 | SourceLocation OpLoc, bool IsArrow) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2790 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2791 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 2792 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2793 | OpLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2794 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2795 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2796 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2797 | /*TemplateArgs=*/nullptr, |
| 2798 | /*S=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2799 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2800 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2801 | /// \brief Build a new shuffle vector expression. |
| 2802 | /// |
| 2803 | /// By default, performs semantic analysis to build the new expression. |
| 2804 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2805 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2806 | MultiExprArg SubExprs, |
| 2807 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2808 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2809 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2810 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2811 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2812 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2813 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2814 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2815 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2816 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2817 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2818 | SemaRef.Context.BuiltinFnTy, |
| 2819 | VK_RValue, BuiltinLoc); |
| 2820 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2821 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2822 | CK_BuiltinFnToFnPtr).get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2823 | |
| 2824 | // Build the CallExpr |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2825 | ExprResult TheCall = new (SemaRef.Context) CallExpr( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2826 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2827 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2828 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2829 | // Type-check the __builtin_shufflevector expression. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2830 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2831 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2832 | |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 2833 | /// \brief Build a new convert vector expression. |
| 2834 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 2835 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 2836 | SourceLocation RParenLoc) { |
| 2837 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 2838 | BuiltinLoc, RParenLoc); |
| 2839 | } |
| 2840 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2841 | /// \brief Build a new template argument pack expansion. |
| 2842 | /// |
| 2843 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2844 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2845 | /// different behavior. |
| 2846 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2847 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2848 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2849 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2850 | case TemplateArgument::Expression: { |
| 2851 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2852 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2853 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2854 | if (Result.isInvalid()) |
| 2855 | return TemplateArgumentLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2856 | |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2857 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2858 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2859 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2860 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2861 | return TemplateArgumentLoc(TemplateArgument( |
| 2862 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2863 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2864 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2865 | Pattern.getTemplateNameLoc(), |
| 2866 | EllipsisLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2867 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2868 | case TemplateArgument::Null: |
| 2869 | case TemplateArgument::Integral: |
| 2870 | case TemplateArgument::Declaration: |
| 2871 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2872 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2873 | case TemplateArgument::NullPtr: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2874 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2875 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2876 | case TemplateArgument::Type: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2877 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2878 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2879 | EllipsisLoc, |
| 2880 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2881 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2882 | Expansion); |
| 2883 | break; |
| 2884 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2885 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2886 | return TemplateArgumentLoc(); |
| 2887 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2888 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2889 | /// \brief Build a new expression pack expansion. |
| 2890 | /// |
| 2891 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2892 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2893 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2894 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2895 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2896 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2897 | } |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2898 | |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 2899 | /// \brief Build a new C++1z fold-expression. |
| 2900 | /// |
| 2901 | /// By default, performs semantic analysis in order to build a new fold |
| 2902 | /// expression. |
| 2903 | ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, |
| 2904 | BinaryOperatorKind Operator, |
| 2905 | SourceLocation EllipsisLoc, Expr *RHS, |
| 2906 | SourceLocation RParenLoc) { |
| 2907 | return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc, |
| 2908 | RHS, RParenLoc); |
| 2909 | } |
| 2910 | |
| 2911 | /// \brief Build an empty C++1z fold-expression with the given operator. |
| 2912 | /// |
| 2913 | /// By default, produces the fallback value for the fold-expression, or |
| 2914 | /// produce an error if there is no fallback value. |
| 2915 | ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 2916 | BinaryOperatorKind Operator) { |
| 2917 | return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); |
| 2918 | } |
| 2919 | |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2920 | /// \brief Build a new atomic operation expression. |
| 2921 | /// |
| 2922 | /// By default, performs semantic analysis to build the new expression. |
| 2923 | /// Subclasses may override this routine to provide different behavior. |
| 2924 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2925 | MultiExprArg SubExprs, |
| 2926 | QualType RetTy, |
| 2927 | AtomicExpr::AtomicOp Op, |
| 2928 | SourceLocation RParenLoc) { |
| 2929 | // Just create the expression; there is not any interesting semantic |
| 2930 | // analysis here because we can't actually build an AtomicExpr until |
| 2931 | // we are sure it is semantically sound. |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2932 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2933 | RParenLoc); |
| 2934 | } |
| 2935 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2936 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2937 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2938 | QualType ObjectType, |
| 2939 | NamedDecl *FirstQualifierInScope, |
| 2940 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2941 | |
| 2942 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2943 | QualType ObjectType, |
| 2944 | NamedDecl *FirstQualifierInScope, |
| 2945 | CXXScopeSpec &SS); |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 2946 | |
| 2947 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 2948 | NamedDecl *FirstQualifierInScope, |
| 2949 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2950 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2951 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2952 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2953 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2954 | if (!S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2955 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2956 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2957 | switch (S->getStmtClass()) { |
| 2958 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2959 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2960 | // Transform individual statement nodes |
| 2961 | #define STMT(Node, Parent) \ |
| 2962 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2963 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2964 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2965 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2966 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2967 | // Transform expressions by calling TransformExpr. |
| 2968 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2969 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2970 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2971 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2972 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2973 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2974 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2975 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2976 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2977 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2979 | } |
| 2980 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2981 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2982 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2983 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2984 | template<typename Derived> |
| 2985 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2986 | if (!S) |
| 2987 | return S; |
| 2988 | |
| 2989 | switch (S->getClauseKind()) { |
| 2990 | default: break; |
| 2991 | // Transform individual clause nodes |
| 2992 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2993 | case OMPC_ ## Name : \ |
| 2994 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2995 | #include "clang/Basic/OpenMPKinds.def" |
| 2996 | } |
| 2997 | |
| 2998 | return S; |
| 2999 | } |
| 3000 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3001 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3002 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3003 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3004 | if (!E) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3005 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3006 | |
| 3007 | switch (E->getStmtClass()) { |
| 3008 | case Stmt::NoStmtClass: break; |
| 3009 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3010 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3011 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3012 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3013 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3016 | return E; |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | template<typename Derived> |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3020 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3021 | bool NotCopyInit) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3022 | // Initializers are instantiated like expressions, except that various outer |
| 3023 | // layers are stripped. |
| 3024 | if (!Init) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3025 | return Init; |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3026 | |
| 3027 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 3028 | Init = ExprTemp->getSubExpr(); |
| 3029 | |
Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 3030 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 3031 | Init = MTE->GetTemporaryExpr(); |
| 3032 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3033 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 3034 | Init = Binder->getSubExpr(); |
| 3035 | |
| 3036 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 3037 | Init = ICE->getSubExprAsWritten(); |
| 3038 | |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3039 | if (CXXStdInitializerListExpr *ILE = |
| 3040 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3041 | return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3042 | |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3043 | // If this is copy-initialization, we only need to reconstruct |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3044 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 3045 | // the initializer is already the right type. |
| 3046 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3047 | if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3048 | return getDerived().TransformExpr(Init); |
| 3049 | |
| 3050 | // Revert value-initialization back to empty parens. |
| 3051 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 3052 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3053 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3054 | Parens.getEnd()); |
| 3055 | } |
| 3056 | |
| 3057 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 3058 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3059 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3060 | SourceLocation()); |
| 3061 | |
| 3062 | // Revert initialization by constructor back to a parenthesized or braced list |
| 3063 | // of expressions. Any other form of initializer can just be reused directly. |
| 3064 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3065 | return getDerived().TransformExpr(Init); |
| 3066 | |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3067 | // If the initialization implicitly converted an initializer list to a |
| 3068 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 3069 | if (Construct && Construct->isStdInitListInitialization()) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3070 | return TransformInitializer(Construct->getArg(0), NotCopyInit); |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3071 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3072 | SmallVector<Expr*, 8> NewArgs; |
| 3073 | bool ArgChanged = false; |
| 3074 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3075 | /*IsCall*/true, NewArgs, &ArgChanged)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3076 | return ExprError(); |
| 3077 | |
| 3078 | // If this was list initialization, revert to list form. |
| 3079 | if (Construct->isListInitialization()) |
| 3080 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 3081 | Construct->getLocEnd(), |
| 3082 | Construct->getType()); |
| 3083 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3084 | // Build a ParenListExpr to represent anything else. |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 3085 | SourceRange Parens = Construct->getParenOrBraceRange(); |
Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 3086 | if (Parens.isInvalid()) { |
| 3087 | // This was a variable declaration's initialization for which no initializer |
| 3088 | // was specified. |
| 3089 | assert(NewArgs.empty() && |
| 3090 | "no parens or braces but have direct init with arguments?"); |
| 3091 | return ExprEmpty(); |
| 3092 | } |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3093 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 3094 | Parens.getEnd()); |
| 3095 | } |
| 3096 | |
| 3097 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3098 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 3099 | unsigned NumInputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3100 | bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3101 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3102 | bool *ArgChanged) { |
| 3103 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 3104 | // If requested, drop call arguments that need to be dropped. |
| 3105 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 3106 | if (ArgChanged) |
| 3107 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3108 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3109 | break; |
| 3110 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3111 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3112 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 3113 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3114 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3115 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3116 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3117 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3118 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3119 | // Determine whether the set of unexpanded parameter packs can and should |
| 3120 | // be expanded. |
| 3121 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3122 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3123 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 3124 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3125 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 3126 | Pattern->getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3127 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3128 | Expand, RetainExpansion, |
| 3129 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3130 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3131 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3132 | if (!Expand) { |
| 3133 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3134 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3135 | // expansion. |
| 3136 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3137 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 3138 | if (OutPattern.isInvalid()) |
| 3139 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3140 | |
| 3141 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3142 | Expansion->getEllipsisLoc(), |
| 3143 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3144 | if (Out.isInvalid()) |
| 3145 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3146 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3147 | if (ArgChanged) |
| 3148 | *ArgChanged = true; |
| 3149 | Outputs.push_back(Out.get()); |
| 3150 | continue; |
| 3151 | } |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 3152 | |
| 3153 | // Record right away that the argument was changed. This needs |
| 3154 | // to happen even if the array expands to nothing. |
| 3155 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3156 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3157 | // The transform has determined that we should perform an elementwise |
| 3158 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3159 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3160 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3161 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3162 | if (Out.isInvalid()) |
| 3163 | return true; |
| 3164 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3165 | // FIXME: Can this happen? We should not try to expand the pack |
| 3166 | // in this case. |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3167 | if (Out.get()->containsUnexpandedParameterPack()) { |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3168 | Out = getDerived().RebuildPackExpansion( |
| 3169 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3170 | if (Out.isInvalid()) |
| 3171 | return true; |
| 3172 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3173 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3174 | Outputs.push_back(Out.get()); |
| 3175 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3176 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3177 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3178 | // forgetting the partially-substituted parameter pack. |
| 3179 | if (RetainExpansion) { |
| 3180 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3181 | |
| 3182 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3183 | if (Out.isInvalid()) |
| 3184 | return true; |
| 3185 | |
| 3186 | Out = getDerived().RebuildPackExpansion( |
| 3187 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3188 | if (Out.isInvalid()) |
| 3189 | return true; |
| 3190 | |
| 3191 | Outputs.push_back(Out.get()); |
| 3192 | } |
| 3193 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3194 | continue; |
| 3195 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3196 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3197 | ExprResult Result = |
| 3198 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3199 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3200 | if (Result.isInvalid()) |
| 3201 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3202 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3203 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3204 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3205 | |
| 3206 | Outputs.push_back(Result.get()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3207 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3208 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3209 | return false; |
| 3210 | } |
| 3211 | |
| 3212 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3213 | NestedNameSpecifierLoc |
| 3214 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3215 | NestedNameSpecifierLoc NNS, |
| 3216 | QualType ObjectType, |
| 3217 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3218 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3219 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3220 | Qualifier = Qualifier.getPrefix()) |
| 3221 | Qualifiers.push_back(Qualifier); |
| 3222 | |
| 3223 | CXXScopeSpec SS; |
| 3224 | while (!Qualifiers.empty()) { |
| 3225 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3226 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3227 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3228 | switch (QNNS->getKind()) { |
| 3229 | case NestedNameSpecifier::Identifier: |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3230 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3231 | *QNNS->getAsIdentifier(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3232 | Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3233 | Q.getLocalEndLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3234 | ObjectType, false, SS, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3235 | FirstQualifierInScope, false)) |
| 3236 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3237 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3238 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3239 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3240 | case NestedNameSpecifier::Namespace: { |
| 3241 | NamespaceDecl *NS |
| 3242 | = cast_or_null<NamespaceDecl>( |
| 3243 | getDerived().TransformDecl( |
| 3244 | Q.getLocalBeginLoc(), |
| 3245 | QNNS->getAsNamespace())); |
| 3246 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3247 | break; |
| 3248 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3249 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3250 | case NestedNameSpecifier::NamespaceAlias: { |
| 3251 | NamespaceAliasDecl *Alias |
| 3252 | = cast_or_null<NamespaceAliasDecl>( |
| 3253 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3254 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3255 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3256 | Q.getLocalEndLoc()); |
| 3257 | break; |
| 3258 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3259 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3260 | case NestedNameSpecifier::Global: |
| 3261 | // There is no meaningful transformation that one could perform on the |
| 3262 | // global scope. |
| 3263 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3264 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3265 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 3266 | case NestedNameSpecifier::Super: { |
| 3267 | CXXRecordDecl *RD = |
| 3268 | cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 3269 | SourceLocation(), QNNS->getAsRecordDecl())); |
| 3270 | SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); |
| 3271 | break; |
| 3272 | } |
| 3273 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3274 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3275 | case NestedNameSpecifier::TypeSpec: { |
| 3276 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3277 | FirstQualifierInScope, SS); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3278 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3279 | if (!TL) |
| 3280 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3281 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3282 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3283 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3284 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3285 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3286 | "Can't get cv-qualifiers here"); |
Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3287 | if (TL.getType()->isEnumeralType()) |
| 3288 | SemaRef.Diag(TL.getBeginLoc(), |
| 3289 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3290 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3291 | Q.getLocalEndLoc()); |
| 3292 | break; |
| 3293 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3294 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3295 | // error because a previous error should have already been emitted. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3296 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3297 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3298 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3299 | << TL.getType() << SS.getRange(); |
| 3300 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3301 | return NestedNameSpecifierLoc(); |
| 3302 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3303 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3304 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3305 | // 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] | 3306 | FirstQualifierInScope = nullptr; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3307 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3308 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3309 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3310 | // 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] | 3311 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3312 | !getDerived().AlwaysRebuild()) |
| 3313 | return NNS; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3314 | |
| 3315 | // If we can re-use the source-location data from the original |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3316 | // nested-name-specifier, do so. |
| 3317 | if (SS.location_size() == NNS.getDataLength() && |
| 3318 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3319 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3320 | |
| 3321 | // Allocate new nested-name-specifier location information. |
| 3322 | return SS.getWithLocInContext(SemaRef.Context); |
| 3323 | } |
| 3324 | |
| 3325 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3326 | DeclarationNameInfo |
| 3327 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3328 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3329 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3330 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3331 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3332 | |
| 3333 | switch (Name.getNameKind()) { |
| 3334 | case DeclarationName::Identifier: |
| 3335 | case DeclarationName::ObjCZeroArgSelector: |
| 3336 | case DeclarationName::ObjCOneArgSelector: |
| 3337 | case DeclarationName::ObjCMultiArgSelector: |
| 3338 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3339 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3340 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3341 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3343 | case DeclarationName::CXXConstructorName: |
| 3344 | case DeclarationName::CXXDestructorName: |
| 3345 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3346 | TypeSourceInfo *NewTInfo; |
| 3347 | CanQualType NewCanTy; |
| 3348 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3349 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3350 | if (!NewTInfo) |
| 3351 | return DeclarationNameInfo(); |
| 3352 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3353 | } |
| 3354 | else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3355 | NewTInfo = nullptr; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3356 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3357 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3358 | if (NewT.isNull()) |
| 3359 | return DeclarationNameInfo(); |
| 3360 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3361 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3363 | DeclarationName NewName |
| 3364 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3365 | NewCanTy); |
| 3366 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3367 | NewNameInfo.setName(NewName); |
| 3368 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3369 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3373 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3377 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3378 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3379 | TemplateName Name, |
| 3380 | SourceLocation NameLoc, |
| 3381 | QualType ObjectType, |
| 3382 | NamedDecl *FirstQualifierInScope) { |
| 3383 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3384 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3385 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3386 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3387 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3388 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3389 | Template)); |
| 3390 | if (!TransTemplate) |
| 3391 | return TemplateName(); |
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 (!getDerived().AlwaysRebuild() && |
| 3394 | SS.getScopeRep() == QTN->getQualifier() && |
| 3395 | TransTemplate == Template) |
| 3396 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3397 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3398 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3399 | TransTemplate); |
| 3400 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3401 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3402 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3403 | if (SS.getScopeRep()) { |
| 3404 | // These apply to the scope specifier, not the template. |
| 3405 | ObjectType = QualType(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3406 | FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3409 | if (!getDerived().AlwaysRebuild() && |
| 3410 | SS.getScopeRep() == DTN->getQualifier() && |
| 3411 | ObjectType.isNull()) |
| 3412 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3413 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3414 | if (DTN->isIdentifier()) { |
| 3415 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3416 | *DTN->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3417 | NameLoc, |
| 3418 | ObjectType, |
| 3419 | FirstQualifierInScope); |
| 3420 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3421 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3422 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3423 | ObjectType); |
| 3424 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3425 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3426 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3427 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3428 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3429 | Template)); |
| 3430 | if (!TransTemplate) |
| 3431 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3432 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3433 | if (!getDerived().AlwaysRebuild() && |
| 3434 | TransTemplate == Template) |
| 3435 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3436 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3437 | return TemplateName(TransTemplate); |
| 3438 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3439 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3440 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3441 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3442 | TemplateTemplateParmDecl *TransParam |
| 3443 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3444 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3445 | if (!TransParam) |
| 3446 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3447 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3448 | if (!getDerived().AlwaysRebuild() && |
| 3449 | TransParam == SubstPack->getParameterPack()) |
| 3450 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3451 | |
| 3452 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3453 | SubstPack->getArgumentPack()); |
| 3454 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3455 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3456 | // These should be getting filtered out before they reach the AST. |
| 3457 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3461 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3462 | const TemplateArgument &Arg, |
| 3463 | TemplateArgumentLoc &Output) { |
| 3464 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3465 | switch (Arg.getKind()) { |
| 3466 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3467 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3468 | break; |
| 3469 | |
| 3470 | case TemplateArgument::Type: |
| 3471 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3472 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3473 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3474 | break; |
| 3475 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3476 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3477 | case TemplateArgument::TemplateExpansion: { |
| 3478 | NestedNameSpecifierLocBuilder Builder; |
| 3479 | TemplateName Template = Arg.getAsTemplate(); |
| 3480 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3481 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3482 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3483 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3484 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3485 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3486 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3487 | Builder.getWithLocInContext(SemaRef.Context), |
| 3488 | Loc); |
| 3489 | else |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3490 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3491 | Builder.getWithLocInContext(SemaRef.Context), |
| 3492 | Loc, Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3493 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3494 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3495 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3496 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3497 | case TemplateArgument::Expression: |
| 3498 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3499 | break; |
| 3500 | |
| 3501 | case TemplateArgument::Declaration: |
| 3502 | case TemplateArgument::Integral: |
| 3503 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3504 | case TemplateArgument::NullPtr: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3505 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3506 | break; |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | template<typename Derived> |
| 3511 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3512 | const TemplateArgumentLoc &Input, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3513 | TemplateArgumentLoc &Output, bool Uneval) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3514 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3515 | switch (Arg.getKind()) { |
| 3516 | case TemplateArgument::Null: |
| 3517 | case TemplateArgument::Integral: |
Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3518 | case TemplateArgument::Pack: |
| 3519 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3520 | case TemplateArgument::NullPtr: |
| 3521 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3522 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3523 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3524 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3525 | if (!DI) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3526 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3527 | |
| 3528 | DI = getDerived().TransformType(DI); |
| 3529 | if (!DI) return true; |
| 3530 | |
| 3531 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3532 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3533 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3534 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3535 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3536 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3537 | if (QualifierLoc) { |
| 3538 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3539 | if (!QualifierLoc) |
| 3540 | return true; |
| 3541 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3542 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3543 | CXXScopeSpec SS; |
| 3544 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3545 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3546 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3547 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3548 | if (Template.isNull()) |
| 3549 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3550 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3551 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3552 | Input.getTemplateNameLoc()); |
| 3553 | return false; |
| 3554 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3555 | |
| 3556 | case TemplateArgument::TemplateExpansion: |
| 3557 | llvm_unreachable("Caller should expand pack expansions"); |
| 3558 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3559 | case TemplateArgument::Expression: { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3560 | // Template argument expressions are constant expressions. |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3561 | EnterExpressionEvaluationContext Unevaluated( |
| 3562 | getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3563 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3564 | Expr *InputExpr = Input.getSourceExpression(); |
| 3565 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3566 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3567 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3568 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3569 | if (E.isInvalid()) return true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3570 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3571 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3572 | } |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3575 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3576 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3577 | } |
| 3578 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3579 | /// \brief Iterator adaptor that invents template argument location information |
| 3580 | /// for each of the template arguments in its underlying iterator. |
| 3581 | template<typename Derived, typename InputIterator> |
| 3582 | class TemplateArgumentLocInventIterator { |
| 3583 | TreeTransform<Derived> &Self; |
| 3584 | InputIterator Iter; |
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 | public: |
| 3587 | typedef TemplateArgumentLoc value_type; |
| 3588 | typedef TemplateArgumentLoc reference; |
| 3589 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3590 | difference_type; |
| 3591 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3592 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3593 | class pointer { |
| 3594 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3595 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3596 | public: |
| 3597 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3598 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3599 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3600 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3601 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 3602 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3603 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3604 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3605 | InputIterator Iter) |
| 3606 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3607 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3608 | TemplateArgumentLocInventIterator &operator++() { |
| 3609 | ++Iter; |
| 3610 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3611 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3612 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3613 | TemplateArgumentLocInventIterator operator++(int) { |
| 3614 | TemplateArgumentLocInventIterator Old(*this); |
| 3615 | ++(*this); |
| 3616 | return Old; |
| 3617 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3618 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3619 | reference operator*() const { |
| 3620 | TemplateArgumentLoc Result; |
| 3621 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3622 | return Result; |
| 3623 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3624 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3625 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3626 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3627 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3628 | const TemplateArgumentLocInventIterator &Y) { |
| 3629 | return X.Iter == Y.Iter; |
| 3630 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3631 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3632 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3633 | const TemplateArgumentLocInventIterator &Y) { |
| 3634 | return X.Iter != Y.Iter; |
| 3635 | } |
| 3636 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3637 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3638 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3639 | template<typename InputIterator> |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3640 | bool TreeTransform<Derived>::TransformTemplateArguments( |
| 3641 | InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, |
| 3642 | bool Uneval) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3643 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3644 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3645 | TemplateArgumentLoc In = *First; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3646 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3647 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3648 | // Unpack argument packs, which we translate them into separate |
| 3649 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3650 | // FIXME: We could do much better if we could guarantee that the |
| 3651 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3652 | // all of the template arguments in the argument pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3653 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3654 | TemplateArgument::pack_iterator> |
| 3655 | PackLocIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3656 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3657 | In.getArgument().pack_begin()), |
| 3658 | PackLocIterator(*this, |
| 3659 | In.getArgument().pack_end()), |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3660 | Outputs, Uneval)) |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3661 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3662 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3663 | continue; |
| 3664 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3665 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3666 | if (In.getArgument().isPackExpansion()) { |
| 3667 | // We have a pack expansion, for which we will be substituting into |
| 3668 | // the pattern. |
| 3669 | SourceLocation Ellipsis; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3670 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3671 | TemplateArgumentLoc Pattern |
Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3672 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3673 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3674 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3675 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3676 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3677 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3678 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3679 | // Determine whether the set of unexpanded parameter packs can and should |
| 3680 | // be expanded. |
| 3681 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3682 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3683 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3684 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3685 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3686 | Unexpanded, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3687 | Expand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3688 | RetainExpansion, |
| 3689 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3690 | return true; |
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 | if (!Expand) { |
| 3693 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3694 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3695 | // expansion. |
| 3696 | TemplateArgumentLoc OutPattern; |
| 3697 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3698 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3699 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3700 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3701 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3702 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3703 | if (Out.getArgument().isNull()) |
| 3704 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3705 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3706 | Outputs.addArgument(Out); |
| 3707 | continue; |
| 3708 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3709 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3710 | // The transform has determined that we should perform an elementwise |
| 3711 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3712 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3713 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3714 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3715 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3716 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3717 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3718 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3719 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3720 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3721 | if (Out.getArgument().isNull()) |
| 3722 | return true; |
| 3723 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3724 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3725 | Outputs.addArgument(Out); |
| 3726 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3727 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3728 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3729 | // forgetting the partially-substituted parameter pack. |
| 3730 | if (RetainExpansion) { |
| 3731 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3732 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3733 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3734 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3735 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3736 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3737 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3738 | if (Out.getArgument().isNull()) |
| 3739 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3740 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3741 | Outputs.addArgument(Out); |
| 3742 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3743 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3744 | continue; |
| 3745 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3746 | |
| 3747 | // The simple case: |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3748 | if (getDerived().TransformTemplateArgument(In, Out, Uneval)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3749 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3750 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3751 | Outputs.addArgument(Out); |
| 3752 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3753 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3754 | return false; |
| 3755 | |
| 3756 | } |
| 3757 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3758 | //===----------------------------------------------------------------------===// |
| 3759 | // Type transformation |
| 3760 | //===----------------------------------------------------------------------===// |
| 3761 | |
| 3762 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3763 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3764 | if (getDerived().AlreadyTransformed(T)) |
| 3765 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3766 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3767 | // Temporary workaround. All of these transformations should |
| 3768 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3769 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3770 | getDerived().getBaseLocation()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3771 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3772 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3773 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3774 | if (!NewDI) |
| 3775 | return QualType(); |
| 3776 | |
| 3777 | return NewDI->getType(); |
| 3778 | } |
| 3779 | |
| 3780 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3781 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3782 | // Refine the base location to the type's location. |
| 3783 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3784 | getDerived().getBaseEntity()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3785 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3786 | return DI; |
| 3787 | |
| 3788 | TypeLocBuilder TLB; |
| 3789 | |
| 3790 | TypeLoc TL = DI->getTypeLoc(); |
| 3791 | TLB.reserve(TL.getFullDataSize()); |
| 3792 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3793 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3794 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3795 | return nullptr; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3796 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3797 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | template<typename Derived> |
| 3801 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3802 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3803 | switch (T.getTypeLocClass()) { |
| 3804 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3805 | #define TYPELOC(CLASS, PARENT) \ |
| 3806 | case TypeLoc::CLASS: \ |
| 3807 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3808 | T.castAs<CLASS##TypeLoc>()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3809 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3812 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3816 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3817 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3818 | /// types). This is the right thing for template instantiation, but |
| 3819 | /// probably not for other clients. |
| 3820 | template<typename Derived> |
| 3821 | QualType |
| 3822 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3823 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3824 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3825 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3826 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3827 | if (Result.isNull()) |
| 3828 | return QualType(); |
| 3829 | |
| 3830 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3831 | // FIXME: this is the right thing for template instantiation, but |
| 3832 | // probably not for other clients. |
| 3833 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3834 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3835 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3836 | // 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] | 3837 | // resulting type. |
| 3838 | if (Quals.hasObjCLifetime()) { |
| 3839 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3840 | Quals.removeObjCLifetime(); |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3841 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3842 | // Objective-C ARC: |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3843 | // A lifetime qualifier applied to a substituted template parameter |
| 3844 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3845 | const AutoType *AutoTy; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3846 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3847 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3848 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3849 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3850 | Qs.removeObjCLifetime(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3851 | Replacement |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3852 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3853 | Qs); |
| 3854 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3855 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3856 | Replacement); |
| 3857 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3858 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3859 | // 'auto' types behave the same way as template parameters. |
| 3860 | QualType Deduced = AutoTy->getDeducedType(); |
| 3861 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3862 | Qs.removeObjCLifetime(); |
| 3863 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3864 | Qs); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 3865 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(), |
| 3866 | AutoTy->isDependentType()); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3867 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3868 | } else { |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3869 | // Otherwise, complain about the addition of a qualifier to an |
| 3870 | // already-qualified type. |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3871 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3872 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3873 | << Result << R; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3874 | |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3875 | Quals.removeObjCLifetime(); |
| 3876 | } |
| 3877 | } |
| 3878 | } |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3879 | if (!Quals.empty()) { |
| 3880 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3881 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3882 | if (Result.hasLocalQualifiers()) |
| 3883 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3884 | // No location information to preserve. |
| 3885 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3886 | |
| 3887 | return Result; |
| 3888 | } |
| 3889 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3890 | template<typename Derived> |
| 3891 | TypeLoc |
| 3892 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3893 | QualType ObjectType, |
| 3894 | NamedDecl *UnqualLookup, |
| 3895 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3896 | if (getDerived().AlreadyTransformed(TL.getType())) |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3897 | return TL; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3898 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3899 | TypeSourceInfo *TSI = |
| 3900 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 3901 | if (TSI) |
| 3902 | return TSI->getTypeLoc(); |
| 3903 | return TypeLoc(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3904 | } |
| 3905 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3906 | template<typename Derived> |
| 3907 | TypeSourceInfo * |
| 3908 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3909 | QualType ObjectType, |
| 3910 | NamedDecl *UnqualLookup, |
| 3911 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3912 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3913 | return TSInfo; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3914 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3915 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 3916 | UnqualLookup, SS); |
| 3917 | } |
| 3918 | |
| 3919 | template <typename Derived> |
| 3920 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 3921 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 3922 | CXXScopeSpec &SS) { |
| 3923 | QualType T = TL.getType(); |
| 3924 | assert(!getDerived().AlreadyTransformed(T)); |
| 3925 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3926 | TypeLocBuilder TLB; |
| 3927 | QualType Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3928 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3929 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3930 | TemplateSpecializationTypeLoc SpecTL = |
| 3931 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3932 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3933 | TemplateName Template |
| 3934 | = getDerived().TransformTemplateName(SS, |
| 3935 | SpecTL.getTypePtr()->getTemplateName(), |
| 3936 | SpecTL.getTemplateNameLoc(), |
| 3937 | ObjectType, UnqualLookup); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3938 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3939 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3940 | |
| 3941 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3942 | Template); |
| 3943 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3944 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3945 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3946 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3947 | TemplateName Template |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3948 | = getDerived().RebuildTemplateName(SS, |
| 3949 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3950 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3951 | ObjectType, UnqualLookup); |
| 3952 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3953 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3954 | |
| 3955 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3956 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3957 | Template, |
| 3958 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3959 | } else { |
| 3960 | // Nothing special needs to be done for these. |
| 3961 | Result = getDerived().TransformType(TLB, TL); |
| 3962 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3963 | |
| 3964 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3965 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3966 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3967 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3968 | } |
| 3969 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3970 | template <class TyLoc> static inline |
| 3971 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3972 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3973 | NewT.setNameLoc(T.getNameLoc()); |
| 3974 | return T.getType(); |
| 3975 | } |
| 3976 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3977 | template<typename Derived> |
| 3978 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3979 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3980 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3981 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3982 | if (T.needsExtraLocalData()) |
| 3983 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3984 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3985 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3986 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3987 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3988 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3989 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3990 | // FIXME: recurse? |
| 3991 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3992 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3993 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3994 | template <typename Derived> |
| 3995 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 3996 | AdjustedTypeLoc TL) { |
| 3997 | // Adjustments applied during transformation are handled elsewhere. |
| 3998 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3999 | } |
| 4000 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4001 | template<typename Derived> |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 4002 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 4003 | DecayedTypeLoc TL) { |
| 4004 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4005 | if (OriginalType.isNull()) |
| 4006 | return QualType(); |
| 4007 | |
| 4008 | QualType Result = TL.getType(); |
| 4009 | if (getDerived().AlwaysRebuild() || |
| 4010 | OriginalType != TL.getOriginalLoc().getType()) |
| 4011 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 4012 | TLB.push<DecayedTypeLoc>(Result); |
| 4013 | // Nothing to set for DecayedTypeLoc. |
| 4014 | return Result; |
| 4015 | } |
| 4016 | |
| 4017 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4018 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4019 | PointerTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4020 | QualType PointeeType |
| 4021 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4022 | if (PointeeType.isNull()) |
| 4023 | return QualType(); |
| 4024 | |
| 4025 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4026 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4027 | // A dependent pointer type 'T *' has is being transformed such |
| 4028 | // that an Objective-C class type is being replaced for 'T'. The |
| 4029 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 4030 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4031 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4032 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4033 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 4034 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4035 | return Result; |
| 4036 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4037 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4038 | if (getDerived().AlwaysRebuild() || |
| 4039 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4040 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 4041 | if (Result.isNull()) |
| 4042 | return QualType(); |
| 4043 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4044 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4045 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4046 | // pointing to. |
| 4047 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4048 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4049 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 4050 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4051 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4052 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4053 | |
| 4054 | template<typename Derived> |
| 4055 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4056 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4057 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4058 | QualType PointeeType |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4059 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4060 | if (PointeeType.isNull()) |
| 4061 | return QualType(); |
| 4062 | |
| 4063 | QualType Result = TL.getType(); |
| 4064 | if (getDerived().AlwaysRebuild() || |
| 4065 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4066 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4067 | TL.getSigilLoc()); |
| 4068 | if (Result.isNull()) |
| 4069 | return QualType(); |
| 4070 | } |
| 4071 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 4072 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4073 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 4074 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4075 | } |
| 4076 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4077 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 4078 | /// don't care whether the type itself is an l-value type or an r-value |
| 4079 | /// type; we only care if the type was *written* as an l-value type |
| 4080 | /// or an r-value type. |
| 4081 | template<typename Derived> |
| 4082 | QualType |
| 4083 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4084 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4085 | const ReferenceType *T = TL.getTypePtr(); |
| 4086 | |
| 4087 | // Note that this works with the pointee-as-written. |
| 4088 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4089 | if (PointeeType.isNull()) |
| 4090 | return QualType(); |
| 4091 | |
| 4092 | QualType Result = TL.getType(); |
| 4093 | if (getDerived().AlwaysRebuild() || |
| 4094 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 4095 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 4096 | T->isSpelledAsLValue(), |
| 4097 | TL.getSigilLoc()); |
| 4098 | if (Result.isNull()) |
| 4099 | return QualType(); |
| 4100 | } |
| 4101 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4102 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4103 | // referring to. |
| 4104 | TLB.TypeWasModifiedSafely( |
| 4105 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 4106 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4107 | // r-value references can be rebuilt as l-value references. |
| 4108 | ReferenceTypeLoc NewTL; |
| 4109 | if (isa<LValueReferenceType>(Result)) |
| 4110 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 4111 | else |
| 4112 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 4113 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 4114 | |
| 4115 | return Result; |
| 4116 | } |
| 4117 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4118 | template<typename Derived> |
| 4119 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4120 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4121 | LValueReferenceTypeLoc TL) { |
| 4122 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4123 | } |
| 4124 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | template<typename Derived> |
| 4126 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4127 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4128 | RValueReferenceTypeLoc TL) { |
| 4129 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4132 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4134 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4135 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4136 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4137 | if (PointeeType.isNull()) |
| 4138 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4139 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4140 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4141 | TypeSourceInfo *NewClsTInfo = nullptr; |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4142 | if (OldClsTInfo) { |
| 4143 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 4144 | if (!NewClsTInfo) |
| 4145 | return QualType(); |
| 4146 | } |
| 4147 | |
| 4148 | const MemberPointerType *T = TL.getTypePtr(); |
| 4149 | QualType OldClsType = QualType(T->getClass(), 0); |
| 4150 | QualType NewClsType; |
| 4151 | if (NewClsTInfo) |
| 4152 | NewClsType = NewClsTInfo->getType(); |
| 4153 | else { |
| 4154 | NewClsType = getDerived().TransformType(OldClsType); |
| 4155 | if (NewClsType.isNull()) |
| 4156 | return QualType(); |
| 4157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4159 | QualType Result = TL.getType(); |
| 4160 | if (getDerived().AlwaysRebuild() || |
| 4161 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4162 | NewClsType != OldClsType) { |
| 4163 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4164 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4165 | if (Result.isNull()) |
| 4166 | return QualType(); |
| 4167 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4168 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4169 | // If we had to adjust the pointee type when building a member pointer, make |
| 4170 | // sure to push TypeLoc info for it. |
| 4171 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 4172 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 4173 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 4174 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 4175 | } |
| 4176 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4177 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 4178 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4179 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4180 | |
| 4181 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4182 | } |
| 4183 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4184 | template<typename Derived> |
| 4185 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4186 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4187 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4188 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4189 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4190 | if (ElementType.isNull()) |
| 4191 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4192 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4193 | QualType Result = TL.getType(); |
| 4194 | if (getDerived().AlwaysRebuild() || |
| 4195 | ElementType != T->getElementType()) { |
| 4196 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4197 | T->getSizeModifier(), |
| 4198 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4199 | T->getIndexTypeCVRQualifiers(), |
| 4200 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4201 | if (Result.isNull()) |
| 4202 | return QualType(); |
| 4203 | } |
Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4204 | |
| 4205 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4206 | // a ConstantArrayType is allowed to have an element type which is a |
| 4207 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4208 | // types have the same location layout. |
| 4209 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4210 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4211 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4212 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4213 | Expr *Size = TL.getSizeExpr(); |
| 4214 | if (Size) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4215 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4216 | Sema::ConstantEvaluated); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4217 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4218 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4219 | } |
| 4220 | NewTL.setSizeExpr(Size); |
| 4221 | |
| 4222 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4223 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4224 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4225 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4226 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4227 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4228 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4229 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4230 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4231 | if (ElementType.isNull()) |
| 4232 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4233 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4234 | QualType Result = TL.getType(); |
| 4235 | if (getDerived().AlwaysRebuild() || |
| 4236 | ElementType != T->getElementType()) { |
| 4237 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4238 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4239 | T->getIndexTypeCVRQualifiers(), |
| 4240 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4241 | if (Result.isNull()) |
| 4242 | return QualType(); |
| 4243 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4244 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4245 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4246 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4247 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4248 | NewTL.setSizeExpr(nullptr); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4249 | |
| 4250 | return Result; |
| 4251 | } |
| 4252 | |
| 4253 | template<typename Derived> |
| 4254 | QualType |
| 4255 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4256 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4257 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4258 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4259 | if (ElementType.isNull()) |
| 4260 | return QualType(); |
| 4261 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4262 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4263 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 4264 | if (SizeResult.isInvalid()) |
| 4265 | return QualType(); |
| 4266 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4267 | Expr *Size = SizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4268 | |
| 4269 | QualType Result = TL.getType(); |
| 4270 | if (getDerived().AlwaysRebuild() || |
| 4271 | ElementType != T->getElementType() || |
| 4272 | Size != T->getSizeExpr()) { |
| 4273 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4274 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4275 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4276 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4277 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4278 | if (Result.isNull()) |
| 4279 | return QualType(); |
| 4280 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4281 | |
Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4282 | // We might have constant size array now, but fortunately it has the same |
| 4283 | // location layout. |
| 4284 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4285 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4286 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4287 | NewTL.setSizeExpr(Size); |
| 4288 | |
| 4289 | return Result; |
| 4290 | } |
| 4291 | |
| 4292 | template<typename Derived> |
| 4293 | QualType |
| 4294 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4295 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4296 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4297 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4298 | if (ElementType.isNull()) |
| 4299 | return QualType(); |
| 4300 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4301 | // Array bounds are constant expressions. |
| 4302 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4303 | Sema::ConstantEvaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4304 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4305 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4306 | Expr *origSize = TL.getSizeExpr(); |
| 4307 | if (!origSize) origSize = T->getSizeExpr(); |
| 4308 | |
| 4309 | ExprResult sizeResult |
| 4310 | = getDerived().TransformExpr(origSize); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4311 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4312 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4313 | return QualType(); |
| 4314 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4315 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4316 | |
| 4317 | QualType Result = TL.getType(); |
| 4318 | if (getDerived().AlwaysRebuild() || |
| 4319 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4320 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4321 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4322 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4323 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4324 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4325 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4326 | if (Result.isNull()) |
| 4327 | return QualType(); |
| 4328 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4329 | |
| 4330 | // We might have any sort of array type now, but fortunately they |
| 4331 | // all have the same location layout. |
| 4332 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4333 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4334 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4335 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4336 | |
| 4337 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4338 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | |
| 4340 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4341 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4342 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4343 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4344 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4345 | |
| 4346 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4347 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4348 | if (ElementType.isNull()) |
| 4349 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4350 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4351 | // Vector sizes are constant expressions. |
| 4352 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4353 | Sema::ConstantEvaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4354 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4355 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4356 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4357 | if (Size.isInvalid()) |
| 4358 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4359 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4360 | QualType Result = TL.getType(); |
| 4361 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4362 | ElementType != T->getElementType() || |
| 4363 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4364 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4365 | Size.get(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4366 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4367 | if (Result.isNull()) |
| 4368 | return QualType(); |
| 4369 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4370 | |
| 4371 | // Result might be dependent or not. |
| 4372 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4373 | DependentSizedExtVectorTypeLoc NewTL |
| 4374 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4375 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4376 | } else { |
| 4377 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4378 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4379 | } |
| 4380 | |
| 4381 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4383 | |
| 4384 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4385 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4386 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4387 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4388 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4389 | if (ElementType.isNull()) |
| 4390 | return QualType(); |
| 4391 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4392 | QualType Result = TL.getType(); |
| 4393 | if (getDerived().AlwaysRebuild() || |
| 4394 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4395 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4396 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4397 | if (Result.isNull()) |
| 4398 | return QualType(); |
| 4399 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4400 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4401 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4402 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4403 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4404 | return Result; |
| 4405 | } |
| 4406 | |
| 4407 | template<typename Derived> |
| 4408 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4409 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4410 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4411 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4412 | if (ElementType.isNull()) |
| 4413 | return QualType(); |
| 4414 | |
| 4415 | QualType Result = TL.getType(); |
| 4416 | if (getDerived().AlwaysRebuild() || |
| 4417 | ElementType != T->getElementType()) { |
| 4418 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4419 | T->getNumElements(), |
| 4420 | /*FIXME*/ SourceLocation()); |
| 4421 | if (Result.isNull()) |
| 4422 | return QualType(); |
| 4423 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4424 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4425 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4426 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4427 | |
| 4428 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4431 | template <typename Derived> |
| 4432 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4433 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4434 | bool ExpectParameterPack) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4435 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4436 | TypeSourceInfo *NewDI = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4437 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4438 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4439 | // 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] | 4440 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4441 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4442 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4443 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4444 | TypeLocBuilder TLB; |
| 4445 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4446 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4447 | |
| 4448 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4449 | OldExpansionTL.getPatternLoc()); |
| 4450 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4451 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4452 | |
| 4453 | Result = RebuildPackExpansionType(Result, |
| 4454 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4455 | OldExpansionTL.getEllipsisLoc(), |
| 4456 | NumExpansions); |
| 4457 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4458 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4459 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4460 | PackExpansionTypeLoc NewExpansionTL |
| 4461 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4462 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4463 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4464 | } else |
| 4465 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4466 | if (!NewDI) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4467 | return nullptr; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4468 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4469 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4470 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4471 | |
| 4472 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4473 | OldParm->getDeclContext(), |
| 4474 | OldParm->getInnerLocStart(), |
| 4475 | OldParm->getLocation(), |
| 4476 | OldParm->getIdentifier(), |
| 4477 | NewDI->getType(), |
| 4478 | NewDI, |
| 4479 | OldParm->getStorageClass(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4480 | /* DefArg */ nullptr); |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4481 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4482 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4483 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | template<typename Derived> |
| 4487 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4488 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4489 | ParmVarDecl **Params, unsigned NumParams, |
| 4490 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4491 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4492 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4493 | int indexAdjustment = 0; |
| 4494 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4495 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4496 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4497 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4498 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4499 | Optional<unsigned> NumExpansions; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4500 | ParmVarDecl *NewParm = nullptr; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4501 | if (OldParm->isParameterPack()) { |
| 4502 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4503 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4504 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4505 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4506 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4507 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4508 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4509 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4510 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4511 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4512 | // Determine whether we should expand the parameter packs. |
| 4513 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4514 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4515 | Optional<unsigned> OrigNumExpansions = |
| 4516 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4517 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4518 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4519 | Pattern.getSourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4520 | Unexpanded, |
| 4521 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4522 | RetainExpansion, |
| 4523 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4524 | return true; |
| 4525 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4526 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4527 | if (ShouldExpand) { |
| 4528 | // Expand the function parameter pack into multiple, separate |
| 4529 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4530 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4531 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4532 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4533 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4534 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4535 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4536 | OrigNumExpansions, |
| 4537 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4538 | if (!NewParm) |
| 4539 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4540 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4541 | OutParamTypes.push_back(NewParm->getType()); |
| 4542 | if (PVars) |
| 4543 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4544 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4545 | |
| 4546 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4547 | // forgetting the partially-substituted parameter pack. |
| 4548 | if (RetainExpansion) { |
| 4549 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4550 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4551 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4552 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4553 | OrigNumExpansions, |
| 4554 | /*ExpectParameterPack=*/false); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4555 | if (!NewParm) |
| 4556 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4557 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4558 | OutParamTypes.push_back(NewParm->getType()); |
| 4559 | if (PVars) |
| 4560 | PVars->push_back(NewParm); |
| 4561 | } |
| 4562 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4563 | // The next parameter should have the same adjustment as the |
| 4564 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4565 | // on every push. Also, if we push nothing, the adjustment should |
| 4566 | // go down by one. |
| 4567 | indexAdjustment--; |
| 4568 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4569 | // We're done with the pack expansion. |
| 4570 | continue; |
| 4571 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4572 | |
| 4573 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4574 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4575 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4576 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4577 | indexAdjustment, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4578 | NumExpansions, |
| 4579 | /*ExpectParameterPack=*/true); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4580 | } else { |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4581 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4582 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4583 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4584 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4585 | if (!NewParm) |
| 4586 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4587 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4588 | OutParamTypes.push_back(NewParm->getType()); |
| 4589 | if (PVars) |
| 4590 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4591 | continue; |
| 4592 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4593 | |
| 4594 | // Deal with the possibility that we don't have a parameter |
| 4595 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4596 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4597 | bool IsPackExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4598 | Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4599 | QualType NewType; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4600 | if (const PackExpansionType *Expansion |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4601 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4602 | // We have a function parameter pack that may need to be expanded. |
| 4603 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4604 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4605 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4606 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4607 | // Determine whether we should expand the parameter packs. |
| 4608 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4609 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4610 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4611 | Unexpanded, |
| 4612 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4613 | RetainExpansion, |
| 4614 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4615 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4616 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4617 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4618 | if (ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4619 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4620 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4621 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4622 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4623 | QualType NewType = getDerived().TransformType(Pattern); |
| 4624 | if (NewType.isNull()) |
| 4625 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4626 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4627 | OutParamTypes.push_back(NewType); |
| 4628 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4629 | PVars->push_back(nullptr); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4630 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4631 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4632 | // We're done with the pack expansion. |
| 4633 | continue; |
| 4634 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4635 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4636 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4637 | // forgetting the partially-substituted parameter pack. |
| 4638 | if (RetainExpansion) { |
| 4639 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4640 | QualType NewType = getDerived().TransformType(Pattern); |
| 4641 | if (NewType.isNull()) |
| 4642 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4643 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4644 | OutParamTypes.push_back(NewType); |
| 4645 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4646 | PVars->push_back(nullptr); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4647 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4648 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4649 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4650 | // expansion. |
| 4651 | OldType = Expansion->getPattern(); |
| 4652 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4653 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4654 | NewType = getDerived().TransformType(OldType); |
| 4655 | } else { |
| 4656 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4657 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4658 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4659 | if (NewType.isNull()) |
| 4660 | return true; |
| 4661 | |
| 4662 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4663 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4664 | NumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4665 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4666 | OutParamTypes.push_back(NewType); |
| 4667 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4668 | PVars->push_back(nullptr); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4669 | } |
| 4670 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4671 | #ifndef NDEBUG |
| 4672 | if (PVars) { |
| 4673 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4674 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4675 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4676 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4677 | #endif |
| 4678 | |
| 4679 | return false; |
| 4680 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4681 | |
| 4682 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4683 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4684 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4685 | FunctionProtoTypeLoc TL) { |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4686 | SmallVector<QualType, 4> ExceptionStorage; |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 4687 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4688 | return getDerived().TransformFunctionProtoType( |
| 4689 | TLB, TL, nullptr, 0, |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 4690 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 4691 | return This->TransformExceptionSpec(TL.getBeginLoc(), ESI, |
| 4692 | ExceptionStorage, Changed); |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4693 | }); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4696 | template<typename Derived> template<typename Fn> |
| 4697 | QualType TreeTransform<Derived>::TransformFunctionProtoType( |
| 4698 | TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, |
| 4699 | unsigned ThisTypeQuals, Fn TransformExceptionSpec) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4700 | // Transform the parameters and return type. |
| 4701 | // |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4702 | // 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] | 4703 | // When the function has a trailing return type, we instantiate the |
| 4704 | // parameters before the return type, since the return type can then refer |
| 4705 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4706 | // |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4707 | SmallVector<QualType, 4> ParamTypes; |
| 4708 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4709 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4710 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4711 | QualType ResultType; |
| 4712 | |
Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4713 | if (T->hasTrailingReturn()) { |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4714 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4715 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4716 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4717 | return QualType(); |
| 4718 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4719 | { |
| 4720 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4721 | // If a declaration declares a member function or member function |
| 4722 | // 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] | 4723 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4724 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4725 | // declarator. |
| 4726 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4727 | |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4728 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4729 | if (ResultType.isNull()) |
| 4730 | return QualType(); |
| 4731 | } |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4732 | } |
| 4733 | else { |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4734 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4735 | if (ResultType.isNull()) |
| 4736 | return QualType(); |
| 4737 | |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4738 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4739 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4740 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4741 | return QualType(); |
| 4742 | } |
| 4743 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4744 | FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); |
| 4745 | |
| 4746 | bool EPIChanged = false; |
| 4747 | if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) |
| 4748 | return QualType(); |
| 4749 | |
| 4750 | // FIXME: Need to transform ConsumedParameters for variadic template |
| 4751 | // expansion. |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4752 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4753 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4754 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
Benjamin Kramer | e1c08b0 | 2015-08-18 08:10:39 +0000 | [diff] [blame] | 4755 | T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) { |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4756 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4757 | if (Result.isNull()) |
| 4758 | return QualType(); |
| 4759 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4761 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4762 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4763 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4764 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4765 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4766 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 4767 | NewTL.setParam(i, ParamDecls[i]); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4768 | |
| 4769 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4771 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4772 | template<typename Derived> |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4773 | bool TreeTransform<Derived>::TransformExceptionSpec( |
| 4774 | SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, |
| 4775 | SmallVectorImpl<QualType> &Exceptions, bool &Changed) { |
| 4776 | assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); |
| 4777 | |
| 4778 | // Instantiate a dynamic noexcept expression, if any. |
| 4779 | if (ESI.Type == EST_ComputedNoexcept) { |
| 4780 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 4781 | Sema::ConstantEvaluated); |
| 4782 | ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); |
| 4783 | if (NoexceptExpr.isInvalid()) |
| 4784 | return true; |
| 4785 | |
| 4786 | NoexceptExpr = getSema().CheckBooleanCondition( |
| 4787 | NoexceptExpr.get(), NoexceptExpr.get()->getLocStart()); |
| 4788 | if (NoexceptExpr.isInvalid()) |
| 4789 | return true; |
| 4790 | |
| 4791 | if (!NoexceptExpr.get()->isValueDependent()) { |
| 4792 | NoexceptExpr = getSema().VerifyIntegerConstantExpression( |
| 4793 | NoexceptExpr.get(), nullptr, |
| 4794 | diag::err_noexcept_needs_constant_expression, |
| 4795 | /*AllowFold*/false); |
| 4796 | if (NoexceptExpr.isInvalid()) |
| 4797 | return true; |
| 4798 | } |
| 4799 | |
| 4800 | if (ESI.NoexceptExpr != NoexceptExpr.get()) |
| 4801 | Changed = true; |
| 4802 | ESI.NoexceptExpr = NoexceptExpr.get(); |
| 4803 | } |
| 4804 | |
| 4805 | if (ESI.Type != EST_Dynamic) |
| 4806 | return false; |
| 4807 | |
| 4808 | // Instantiate a dynamic exception specification's type. |
| 4809 | for (QualType T : ESI.Exceptions) { |
| 4810 | if (const PackExpansionType *PackExpansion = |
| 4811 | T->getAs<PackExpansionType>()) { |
| 4812 | Changed = true; |
| 4813 | |
| 4814 | // We have a pack expansion. Instantiate it. |
| 4815 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 4816 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 4817 | Unexpanded); |
| 4818 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 4819 | |
| 4820 | // Determine whether the set of unexpanded parameter packs can and |
| 4821 | // should |
| 4822 | // be expanded. |
| 4823 | bool Expand = false; |
| 4824 | bool RetainExpansion = false; |
| 4825 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 4826 | // FIXME: Track the location of the ellipsis (and track source location |
| 4827 | // information for the types in the exception specification in general). |
| 4828 | if (getDerived().TryExpandParameterPacks( |
| 4829 | Loc, SourceRange(), Unexpanded, Expand, |
| 4830 | RetainExpansion, NumExpansions)) |
| 4831 | return true; |
| 4832 | |
| 4833 | if (!Expand) { |
| 4834 | // We can't expand this pack expansion into separate arguments yet; |
| 4835 | // just substitute into the pattern and create a new pack expansion |
| 4836 | // type. |
| 4837 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4838 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 4839 | if (U.isNull()) |
| 4840 | return true; |
| 4841 | |
| 4842 | U = SemaRef.Context.getPackExpansionType(U, NumExpansions); |
| 4843 | Exceptions.push_back(U); |
| 4844 | continue; |
| 4845 | } |
| 4846 | |
| 4847 | // Substitute into the pack expansion pattern for each slice of the |
| 4848 | // pack. |
| 4849 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 4850 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 4851 | |
| 4852 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 4853 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 4854 | return true; |
| 4855 | |
| 4856 | Exceptions.push_back(U); |
| 4857 | } |
| 4858 | } else { |
| 4859 | QualType U = getDerived().TransformType(T); |
| 4860 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 4861 | return true; |
| 4862 | if (T != U) |
| 4863 | Changed = true; |
| 4864 | |
| 4865 | Exceptions.push_back(U); |
| 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | ESI.Exceptions = Exceptions; |
| 4870 | return false; |
| 4871 | } |
| 4872 | |
| 4873 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4874 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4875 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4876 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4877 | const FunctionNoProtoType *T = TL.getTypePtr(); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4878 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4879 | if (ResultType.isNull()) |
| 4880 | return QualType(); |
| 4881 | |
| 4882 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4883 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4884 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4885 | |
| 4886 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4887 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4888 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4889 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4890 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4891 | |
| 4892 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4893 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4894 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4895 | template<typename Derived> QualType |
| 4896 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4897 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4898 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4899 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4900 | if (!D) |
| 4901 | return QualType(); |
| 4902 | |
| 4903 | QualType Result = TL.getType(); |
| 4904 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4905 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4906 | if (Result.isNull()) |
| 4907 | return QualType(); |
| 4908 | } |
| 4909 | |
| 4910 | // We might get an arbitrary type spec type back. We should at |
| 4911 | // least always get a type spec type, though. |
| 4912 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4913 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4914 | |
| 4915 | return Result; |
| 4916 | } |
| 4917 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4918 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4919 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4920 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4921 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4922 | TypedefNameDecl *Typedef |
| 4923 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4924 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4925 | if (!Typedef) |
| 4926 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4927 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4928 | QualType Result = TL.getType(); |
| 4929 | if (getDerived().AlwaysRebuild() || |
| 4930 | Typedef != T->getDecl()) { |
| 4931 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4932 | if (Result.isNull()) |
| 4933 | return QualType(); |
| 4934 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4936 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4937 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4938 | |
| 4939 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4940 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4941 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4942 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4943 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4944 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4945 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4946 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4947 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4948 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4949 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4950 | if (E.isInvalid()) |
| 4951 | return QualType(); |
| 4952 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4953 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4954 | if (E.isInvalid()) |
| 4955 | return QualType(); |
| 4956 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4957 | QualType Result = TL.getType(); |
| 4958 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4959 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4960 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4961 | if (Result.isNull()) |
| 4962 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4963 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4964 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4965 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4966 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4967 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4968 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4969 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4970 | |
| 4971 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4972 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4973 | |
| 4974 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4975 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4976 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4977 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4978 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4979 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4980 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4981 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4982 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4983 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4984 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4985 | if (Result.isNull()) |
| 4986 | return QualType(); |
| 4987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4989 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4990 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4991 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4992 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4993 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4994 | |
| 4995 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4996 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4997 | |
| 4998 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4999 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5000 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5001 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5002 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5003 | // decltype expressions are not potentially evaluated contexts |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5004 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 5005 | nullptr, /*IsDecltype=*/ true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5006 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5007 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5008 | if (E.isInvalid()) |
| 5009 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5011 | E = getSema().ActOnDecltypeExpression(E.get()); |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 5012 | if (E.isInvalid()) |
| 5013 | return QualType(); |
| 5014 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5015 | QualType Result = TL.getType(); |
| 5016 | if (getDerived().AlwaysRebuild() || |
| 5017 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5018 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5019 | if (Result.isNull()) |
| 5020 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5021 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5022 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5023 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5024 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 5025 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5026 | |
| 5027 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 5031 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 5032 | TypeLocBuilder &TLB, |
| 5033 | UnaryTransformTypeLoc TL) { |
| 5034 | QualType Result = TL.getType(); |
| 5035 | if (Result->isDependentType()) { |
| 5036 | const UnaryTransformType *T = TL.getTypePtr(); |
| 5037 | QualType NewBase = |
| 5038 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 5039 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 5040 | T->getUTTKind(), |
| 5041 | TL.getKWLoc()); |
| 5042 | if (Result.isNull()) |
| 5043 | return QualType(); |
| 5044 | } |
| 5045 | |
| 5046 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 5047 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5048 | NewTL.setParensRange(TL.getParensRange()); |
| 5049 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 5050 | return Result; |
| 5051 | } |
| 5052 | |
| 5053 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5054 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 5055 | AutoTypeLoc TL) { |
| 5056 | const AutoType *T = TL.getTypePtr(); |
| 5057 | QualType OldDeduced = T->getDeducedType(); |
| 5058 | QualType NewDeduced; |
| 5059 | if (!OldDeduced.isNull()) { |
| 5060 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5061 | if (NewDeduced.isNull()) |
| 5062 | return QualType(); |
| 5063 | } |
| 5064 | |
| 5065 | QualType Result = TL.getType(); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5066 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 5067 | T->isDependentType()) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 5068 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5069 | if (Result.isNull()) |
| 5070 | return QualType(); |
| 5071 | } |
| 5072 | |
| 5073 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 5074 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5075 | |
| 5076 | return Result; |
| 5077 | } |
| 5078 | |
| 5079 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5080 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5081 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5082 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5083 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5084 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5085 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5086 | if (!Record) |
| 5087 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5088 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5089 | QualType Result = TL.getType(); |
| 5090 | if (getDerived().AlwaysRebuild() || |
| 5091 | Record != T->getDecl()) { |
| 5092 | Result = getDerived().RebuildRecordType(Record); |
| 5093 | if (Result.isNull()) |
| 5094 | return QualType(); |
| 5095 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5096 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5097 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 5098 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5099 | |
| 5100 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5101 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5102 | |
| 5103 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5104 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5105 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5106 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5107 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5108 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5109 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5110 | if (!Enum) |
| 5111 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5112 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5113 | QualType Result = TL.getType(); |
| 5114 | if (getDerived().AlwaysRebuild() || |
| 5115 | Enum != T->getDecl()) { |
| 5116 | Result = getDerived().RebuildEnumType(Enum); |
| 5117 | if (Result.isNull()) |
| 5118 | return QualType(); |
| 5119 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5120 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5121 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 5122 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5123 | |
| 5124 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5125 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 5126 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5127 | template<typename Derived> |
| 5128 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 5129 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5130 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5131 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 5132 | TL.getTypePtr()->getDecl()); |
| 5133 | if (!D) return QualType(); |
| 5134 | |
| 5135 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 5136 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 5137 | return T; |
| 5138 | } |
| 5139 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5140 | template<typename Derived> |
| 5141 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5142 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5143 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5144 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5145 | } |
| 5146 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5147 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5148 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5149 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5150 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5151 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5152 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5153 | // Substitute into the replacement type, which itself might involve something |
| 5154 | // that needs to be transformed. This only tends to occur with default |
| 5155 | // template arguments of template template parameters. |
| 5156 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 5157 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 5158 | if (Replacement.isNull()) |
| 5159 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5160 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5161 | // Always canonicalize the replacement type. |
| 5162 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 5163 | QualType Result |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5164 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5165 | Replacement); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5166 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5167 | // Propagate type-source information. |
| 5168 | SubstTemplateTypeParmTypeLoc NewTL |
| 5169 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 5170 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5171 | return Result; |
| 5172 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 5176 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 5177 | TypeLocBuilder &TLB, |
| 5178 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 5179 | return TransformTypeSpecType(TLB, TL); |
| 5180 | } |
| 5181 | |
| 5182 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5183 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5184 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5185 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5186 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 5187 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5188 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 5189 | // because we can't have a dependent nested-name-specifier anyway. |
| 5190 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5191 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5192 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 5193 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5194 | if (Template.isNull()) |
| 5195 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5196 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5197 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 5198 | } |
| 5199 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 5200 | template<typename Derived> |
| 5201 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 5202 | AtomicTypeLoc TL) { |
| 5203 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5204 | if (ValueType.isNull()) |
| 5205 | return QualType(); |
| 5206 | |
| 5207 | QualType Result = TL.getType(); |
| 5208 | if (getDerived().AlwaysRebuild() || |
| 5209 | ValueType != TL.getValueLoc().getType()) { |
| 5210 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 5211 | if (Result.isNull()) |
| 5212 | return QualType(); |
| 5213 | } |
| 5214 | |
| 5215 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 5216 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5217 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5218 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5219 | |
| 5220 | return Result; |
| 5221 | } |
| 5222 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5223 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5224 | /// container that provides a \c getArgLoc() member function. |
| 5225 | /// |
| 5226 | /// This iterator is intended to be used with the iterator form of |
| 5227 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 5228 | template<typename ArgLocContainer> |
| 5229 | class TemplateArgumentLocContainerIterator { |
| 5230 | ArgLocContainer *Container; |
| 5231 | unsigned Index; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5232 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5233 | public: |
| 5234 | typedef TemplateArgumentLoc value_type; |
| 5235 | typedef TemplateArgumentLoc reference; |
| 5236 | typedef int difference_type; |
| 5237 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5238 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5239 | class pointer { |
| 5240 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5241 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5242 | public: |
| 5243 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
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 | const TemplateArgumentLoc *operator->() const { |
| 5246 | return &Arg; |
| 5247 | } |
| 5248 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5249 | |
| 5250 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 5251 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5252 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5253 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 5254 | unsigned Index) |
| 5255 | : Container(&Container), Index(Index) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5256 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5257 | TemplateArgumentLocContainerIterator &operator++() { |
| 5258 | ++Index; |
| 5259 | return *this; |
| 5260 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5261 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5262 | TemplateArgumentLocContainerIterator operator++(int) { |
| 5263 | TemplateArgumentLocContainerIterator Old(*this); |
| 5264 | ++(*this); |
| 5265 | return Old; |
| 5266 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5267 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5268 | TemplateArgumentLoc operator*() const { |
| 5269 | return Container->getArgLoc(Index); |
| 5270 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5271 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5272 | pointer operator->() const { |
| 5273 | return pointer(Container->getArgLoc(Index)); |
| 5274 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5275 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5276 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5277 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5278 | return X.Container == Y.Container && X.Index == Y.Index; |
| 5279 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5280 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5281 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5282 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5283 | return !(X == Y); |
| 5284 | } |
| 5285 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5286 | |
| 5287 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5288 | template <typename Derived> |
| 5289 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 5290 | TypeLocBuilder &TLB, |
| 5291 | TemplateSpecializationTypeLoc TL, |
| 5292 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5293 | TemplateArgumentListInfo NewTemplateArgs; |
| 5294 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5295 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5296 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 5297 | ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5298 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5299 | ArgIterator(TL, TL.getNumArgs()), |
| 5300 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 5301 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5302 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5303 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 5304 | |
| 5305 | QualType Result = |
| 5306 | getDerived().RebuildTemplateSpecializationType(Template, |
| 5307 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5308 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5309 | |
| 5310 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5311 | // Specializations of template template parameters are represented as |
| 5312 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 5313 | // within a dependent context can transform them into |
| 5314 | // DependentTemplateSpecializationTypes. |
| 5315 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5316 | DependentTemplateSpecializationTypeLoc NewTL |
| 5317 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5318 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5319 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5320 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5321 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5322 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5323 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5324 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5325 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5326 | return Result; |
| 5327 | } |
| 5328 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5329 | TemplateSpecializationTypeLoc NewTL |
| 5330 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5331 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5332 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5333 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5334 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5335 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5336 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5337 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5338 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5339 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5341 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5342 | template <typename Derived> |
| 5343 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 5344 | TypeLocBuilder &TLB, |
| 5345 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 5346 | TemplateName Template, |
| 5347 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5348 | TemplateArgumentListInfo NewTemplateArgs; |
| 5349 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5350 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 5351 | typedef TemplateArgumentLocContainerIterator< |
| 5352 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5353 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5354 | ArgIterator(TL, TL.getNumArgs()), |
| 5355 | NewTemplateArgs)) |
| 5356 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5357 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5358 | // 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] | 5359 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5360 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 5361 | QualType Result |
| 5362 | = getSema().Context.getDependentTemplateSpecializationType( |
| 5363 | TL.getTypePtr()->getKeyword(), |
| 5364 | DTN->getQualifier(), |
| 5365 | DTN->getIdentifier(), |
| 5366 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5367 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5368 | DependentTemplateSpecializationTypeLoc NewTL |
| 5369 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5370 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5371 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5372 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5373 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5374 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5375 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5376 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5377 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5378 | return Result; |
| 5379 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5380 | |
| 5381 | QualType Result |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5382 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5383 | TL.getTemplateNameLoc(), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5384 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5385 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5386 | if (!Result.isNull()) { |
| 5387 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 5388 | TemplateSpecializationTypeLoc NewTL |
| 5389 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5390 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5391 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5392 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5393 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5394 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5395 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5396 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5397 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5398 | return Result; |
| 5399 | } |
| 5400 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5401 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5402 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5403 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5404 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5405 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5406 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5407 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5408 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5409 | if (TL.getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5410 | QualifierLoc |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5411 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5412 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5413 | return QualType(); |
| 5414 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5415 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5416 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 5417 | if (NamedT.isNull()) |
| 5418 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 5419 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5420 | // C++0x [dcl.type.elab]p2: |
| 5421 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 5422 | // resolves to an alias template specialization, the |
| 5423 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5424 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 5425 | if (const TemplateSpecializationType *TST = |
| 5426 | NamedT->getAs<TemplateSpecializationType>()) { |
| 5427 | TemplateName Template = TST->getTemplateName(); |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 5428 | if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( |
| 5429 | Template.getAsTemplateDecl())) { |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5430 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 5431 | diag::err_tag_reference_non_tag) << 4; |
| 5432 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 5433 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5434 | } |
| 5435 | } |
| 5436 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5437 | QualType Result = TL.getType(); |
| 5438 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5439 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5440 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5441 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5442 | T->getKeyword(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5443 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5444 | if (Result.isNull()) |
| 5445 | return QualType(); |
| 5446 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5447 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5448 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5449 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5450 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5451 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5452 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5453 | |
| 5454 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5455 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5456 | TypeLocBuilder &TLB, |
| 5457 | AttributedTypeLoc TL) { |
| 5458 | const AttributedType *oldType = TL.getTypePtr(); |
| 5459 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5460 | if (modifiedType.isNull()) |
| 5461 | return QualType(); |
| 5462 | |
| 5463 | QualType result = TL.getType(); |
| 5464 | |
| 5465 | // FIXME: dependent operand expressions? |
| 5466 | if (getDerived().AlwaysRebuild() || |
| 5467 | modifiedType != oldType->getModifiedType()) { |
| 5468 | // TODO: this is really lame; we should really be rebuilding the |
| 5469 | // equivalent type from first principles. |
| 5470 | QualType equivalentType |
| 5471 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5472 | if (equivalentType.isNull()) |
| 5473 | return QualType(); |
Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 5474 | |
| 5475 | // Check whether we can add nullability; it is only represented as |
| 5476 | // type sugar, and therefore cannot be diagnosed in any other way. |
| 5477 | if (auto nullability = oldType->getImmediateNullability()) { |
| 5478 | if (!modifiedType->canHaveNullability()) { |
| 5479 | SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer) |
Douglas Gregor | aea7afd | 2015-06-24 22:02:08 +0000 | [diff] [blame] | 5480 | << DiagNullabilityKind(*nullability, false) << modifiedType; |
Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 5481 | return QualType(); |
| 5482 | } |
| 5483 | } |
| 5484 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5485 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5486 | modifiedType, |
| 5487 | equivalentType); |
| 5488 | } |
| 5489 | |
| 5490 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5491 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5492 | if (TL.hasAttrOperand()) |
| 5493 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5494 | if (TL.hasAttrExprOperand()) |
| 5495 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5496 | else if (TL.hasAttrEnumOperand()) |
| 5497 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5498 | |
| 5499 | return result; |
| 5500 | } |
| 5501 | |
| 5502 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5503 | QualType |
| 5504 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5505 | ParenTypeLoc TL) { |
| 5506 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5507 | if (Inner.isNull()) |
| 5508 | return QualType(); |
| 5509 | |
| 5510 | QualType Result = TL.getType(); |
| 5511 | if (getDerived().AlwaysRebuild() || |
| 5512 | Inner != TL.getInnerLoc().getType()) { |
| 5513 | Result = getDerived().RebuildParenType(Inner); |
| 5514 | if (Result.isNull()) |
| 5515 | return QualType(); |
| 5516 | } |
| 5517 | |
| 5518 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5519 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5520 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5521 | return Result; |
| 5522 | } |
| 5523 | |
| 5524 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5525 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5526 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5527 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5528 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5529 | NestedNameSpecifierLoc QualifierLoc |
| 5530 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5531 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5532 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5533 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5534 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5535 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5536 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5537 | QualifierLoc, |
| 5538 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5539 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5540 | if (Result.isNull()) |
| 5541 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5542 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5543 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5544 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5545 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5546 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5547 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5548 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5549 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5550 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5551 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5552 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5553 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5554 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5555 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5556 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5557 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5558 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5559 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5560 | QualType TreeTransform<Derived>:: |
| 5561 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5562 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5563 | NestedNameSpecifierLoc QualifierLoc; |
| 5564 | if (TL.getQualifierLoc()) { |
| 5565 | QualifierLoc |
| 5566 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5567 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5568 | return QualType(); |
| 5569 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5570 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5571 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5572 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | template<typename Derived> |
| 5576 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5577 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5578 | DependentTemplateSpecializationTypeLoc TL, |
| 5579 | NestedNameSpecifierLoc QualifierLoc) { |
| 5580 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5581 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5582 | TemplateArgumentListInfo NewTemplateArgs; |
| 5583 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5584 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5585 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5586 | typedef TemplateArgumentLocContainerIterator< |
| 5587 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5588 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5589 | ArgIterator(TL, TL.getNumArgs()), |
| 5590 | NewTemplateArgs)) |
| 5591 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5592 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5593 | QualType Result |
| 5594 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5595 | QualifierLoc, |
| 5596 | T->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5597 | TL.getTemplateNameLoc(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5598 | NewTemplateArgs); |
| 5599 | if (Result.isNull()) |
| 5600 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5601 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5602 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5603 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5604 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5605 | // Copy information relevant to the template specialization. |
| 5606 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5607 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5608 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5609 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5610 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5611 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5612 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5613 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5614 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5615 | // Copy information relevant to the elaborated type. |
| 5616 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5617 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5618 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5619 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5620 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5621 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5622 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5623 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5624 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5625 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5626 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5627 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5628 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5629 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5630 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5631 | TemplateSpecializationTypeLoc SpecTL |
| 5632 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5633 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5634 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5635 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5636 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5637 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5638 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5639 | } |
| 5640 | return Result; |
| 5641 | } |
| 5642 | |
| 5643 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5644 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5645 | PackExpansionTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5646 | QualType Pattern |
| 5647 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5648 | if (Pattern.isNull()) |
| 5649 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5650 | |
| 5651 | QualType Result = TL.getType(); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5652 | if (getDerived().AlwaysRebuild() || |
| 5653 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5654 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5655 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5656 | TL.getEllipsisLoc(), |
| 5657 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5658 | if (Result.isNull()) |
| 5659 | return QualType(); |
| 5660 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5661 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5662 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5663 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5664 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5668 | QualType |
| 5669 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5670 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5671 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5672 | TLB.pushFullCopy(TL); |
| 5673 | return TL.getType(); |
| 5674 | } |
| 5675 | |
| 5676 | template<typename Derived> |
| 5677 | QualType |
| 5678 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5679 | ObjCObjectTypeLoc TL) { |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 5680 | // Transform base type. |
| 5681 | QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); |
| 5682 | if (BaseType.isNull()) |
| 5683 | return QualType(); |
| 5684 | |
| 5685 | bool AnyChanged = BaseType != TL.getBaseLoc().getType(); |
| 5686 | |
| 5687 | // Transform type arguments. |
| 5688 | SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; |
| 5689 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { |
| 5690 | TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); |
| 5691 | TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); |
| 5692 | QualType TypeArg = TypeArgInfo->getType(); |
| 5693 | if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { |
| 5694 | AnyChanged = true; |
| 5695 | |
| 5696 | // We have a pack expansion. Instantiate it. |
| 5697 | const auto *PackExpansion = PackExpansionLoc.getType() |
| 5698 | ->castAs<PackExpansionType>(); |
| 5699 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5700 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 5701 | Unexpanded); |
| 5702 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 5703 | |
| 5704 | // Determine whether the set of unexpanded parameter packs can |
| 5705 | // and should be expanded. |
| 5706 | TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); |
| 5707 | bool Expand = false; |
| 5708 | bool RetainExpansion = false; |
| 5709 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 5710 | if (getDerived().TryExpandParameterPacks( |
| 5711 | PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), |
| 5712 | Unexpanded, Expand, RetainExpansion, NumExpansions)) |
| 5713 | return QualType(); |
| 5714 | |
| 5715 | if (!Expand) { |
| 5716 | // We can't expand this pack expansion into separate arguments yet; |
| 5717 | // just substitute into the pattern and create a new pack expansion |
| 5718 | // type. |
| 5719 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5720 | |
| 5721 | TypeLocBuilder TypeArgBuilder; |
| 5722 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 5723 | QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, |
| 5724 | PatternLoc); |
| 5725 | if (NewPatternType.isNull()) |
| 5726 | return QualType(); |
| 5727 | |
| 5728 | QualType NewExpansionType = SemaRef.Context.getPackExpansionType( |
| 5729 | NewPatternType, NumExpansions); |
| 5730 | auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); |
| 5731 | NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); |
| 5732 | NewTypeArgInfos.push_back( |
| 5733 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); |
| 5734 | continue; |
| 5735 | } |
| 5736 | |
| 5737 | // Substitute into the pack expansion pattern for each slice of the |
| 5738 | // pack. |
| 5739 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 5740 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 5741 | |
| 5742 | TypeLocBuilder TypeArgBuilder; |
| 5743 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 5744 | |
| 5745 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, |
| 5746 | PatternLoc); |
| 5747 | if (NewTypeArg.isNull()) |
| 5748 | return QualType(); |
| 5749 | |
| 5750 | NewTypeArgInfos.push_back( |
| 5751 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 5752 | } |
| 5753 | |
| 5754 | continue; |
| 5755 | } |
| 5756 | |
| 5757 | TypeLocBuilder TypeArgBuilder; |
| 5758 | TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); |
| 5759 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc); |
| 5760 | if (NewTypeArg.isNull()) |
| 5761 | return QualType(); |
| 5762 | |
| 5763 | // If nothing changed, just keep the old TypeSourceInfo. |
| 5764 | if (NewTypeArg == TypeArg) { |
| 5765 | NewTypeArgInfos.push_back(TypeArgInfo); |
| 5766 | continue; |
| 5767 | } |
| 5768 | |
| 5769 | NewTypeArgInfos.push_back( |
| 5770 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 5771 | AnyChanged = true; |
| 5772 | } |
| 5773 | |
| 5774 | QualType Result = TL.getType(); |
| 5775 | if (getDerived().AlwaysRebuild() || AnyChanged) { |
| 5776 | // Rebuild the type. |
| 5777 | Result = getDerived().RebuildObjCObjectType( |
| 5778 | BaseType, |
| 5779 | TL.getLocStart(), |
| 5780 | TL.getTypeArgsLAngleLoc(), |
| 5781 | NewTypeArgInfos, |
| 5782 | TL.getTypeArgsRAngleLoc(), |
| 5783 | TL.getProtocolLAngleLoc(), |
| 5784 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), |
| 5785 | TL.getNumProtocols()), |
| 5786 | TL.getProtocolLocs(), |
| 5787 | TL.getProtocolRAngleLoc()); |
| 5788 | |
| 5789 | if (Result.isNull()) |
| 5790 | return QualType(); |
| 5791 | } |
| 5792 | |
| 5793 | ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); |
| 5794 | assert(TL.hasBaseTypeAsWritten() && "Can't be dependent"); |
| 5795 | NewT.setHasBaseTypeAsWritten(true); |
| 5796 | NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); |
| 5797 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) |
| 5798 | NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); |
| 5799 | NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); |
| 5800 | NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 5801 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 5802 | NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 5803 | NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 5804 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5806 | |
| 5807 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5808 | QualType |
| 5809 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5810 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 5811 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 5812 | if (PointeeType.isNull()) |
| 5813 | return QualType(); |
| 5814 | |
| 5815 | QualType Result = TL.getType(); |
| 5816 | if (getDerived().AlwaysRebuild() || |
| 5817 | PointeeType != TL.getPointeeLoc().getType()) { |
| 5818 | Result = getDerived().RebuildObjCObjectPointerType(PointeeType, |
| 5819 | TL.getStarLoc()); |
| 5820 | if (Result.isNull()) |
| 5821 | return QualType(); |
| 5822 | } |
| 5823 | |
| 5824 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 5825 | NewT.setStarLoc(TL.getStarLoc()); |
| 5826 | return Result; |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5827 | } |
| 5828 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5829 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5830 | // Statement transformation |
| 5831 | //===----------------------------------------------------------------------===// |
| 5832 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5833 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5834 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5835 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5839 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5840 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5841 | return getDerived().TransformCompoundStmt(S, false); |
| 5842 | } |
| 5843 | |
| 5844 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5845 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5846 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5847 | bool IsStmtExpr) { |
Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5848 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5849 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5850 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5851 | bool SubStmtChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5852 | SmallVector<Stmt*, 8> Statements; |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5853 | for (auto *B : S->body()) { |
| 5854 | StmtResult Result = getDerived().TransformStmt(B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5855 | if (Result.isInvalid()) { |
| 5856 | // Immediately fail if this was a DeclStmt, since it's very |
| 5857 | // likely that this will cause problems for future statements. |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5858 | if (isa<DeclStmt>(B)) |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5859 | return StmtError(); |
| 5860 | |
| 5861 | // Otherwise, just keep processing substatements and fail later. |
| 5862 | SubStmtInvalid = true; |
| 5863 | continue; |
| 5864 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5865 | |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5866 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5867 | Statements.push_back(Result.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5868 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5869 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5870 | if (SubStmtInvalid) |
| 5871 | return StmtError(); |
| 5872 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5873 | if (!getDerived().AlwaysRebuild() && |
| 5874 | !SubStmtChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5875 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5876 | |
| 5877 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5878 | Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5879 | S->getRBracLoc(), |
| 5880 | IsStmtExpr); |
| 5881 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5882 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5883 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5884 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5885 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5886 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5887 | { |
Eli Friedman | 1f4f9dd | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5888 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5889 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5890 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5891 | // Transform the left-hand case value. |
| 5892 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5893 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5894 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5895 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5896 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5897 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5898 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5899 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5900 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5901 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5902 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5903 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5904 | // Build the case statement. |
| 5905 | // Case statements are always rebuilt so that they will attached to their |
| 5906 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5907 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5908 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5909 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5910 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5911 | S->getColonLoc()); |
| 5912 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5913 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5914 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5915 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5916 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5917 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5918 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5919 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5920 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5921 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5925 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5926 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5927 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5928 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5929 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5930 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5931 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5932 | // Default statements are always rebuilt |
| 5933 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5934 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5935 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5936 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5937 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5938 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5939 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5940 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5941 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5942 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5943 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5944 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5945 | S->getDecl()); |
| 5946 | if (!LD) |
| 5947 | return StmtError(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5948 | |
| 5949 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5950 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5951 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5952 | cast<LabelDecl>(LD), SourceLocation(), |
| 5953 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5954 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5955 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5956 | template <typename Derived> |
| 5957 | const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 5958 | if (!R) |
| 5959 | return R; |
| 5960 | |
| 5961 | switch (R->getKind()) { |
| 5962 | // Transform attributes with a pragma spelling by calling TransformXXXAttr. |
| 5963 | #define ATTR(X) |
| 5964 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 5965 | case attr::X: \ |
| 5966 | return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 5967 | #include "clang/Basic/AttrList.inc" |
| 5968 | default: |
| 5969 | return R; |
| 5970 | } |
| 5971 | } |
| 5972 | |
| 5973 | template <typename Derived> |
| 5974 | StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5975 | bool AttrsChanged = false; |
| 5976 | SmallVector<const Attr *, 1> Attrs; |
| 5977 | |
| 5978 | // Visit attributes and keep track if any are transformed. |
| 5979 | for (const auto *I : S->getAttrs()) { |
| 5980 | const Attr *R = getDerived().TransformAttr(I); |
| 5981 | AttrsChanged |= (I != R); |
| 5982 | Attrs.push_back(R); |
| 5983 | } |
| 5984 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5985 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5986 | if (SubStmt.isInvalid()) |
| 5987 | return StmtError(); |
| 5988 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5989 | if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5990 | return S; |
| 5991 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5992 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5993 | SubStmt.get()); |
| 5994 | } |
| 5995 | |
| 5996 | template<typename Derived> |
| 5997 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5998 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5999 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6000 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6001 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 6002 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6003 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 6004 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 6005 | getDerived().TransformDefinition( |
| 6006 | S->getConditionVariable()->getLocation(), |
| 6007 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 6008 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6009 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6010 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 6011 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6012 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6013 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6014 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6015 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6016 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6017 | if (S->getCond()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6018 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 6019 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6020 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6021 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6022 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6023 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6024 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6025 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6026 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6027 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6028 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6029 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6030 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6031 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6032 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6033 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6034 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6035 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6036 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6037 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6038 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6039 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6040 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6041 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6042 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6043 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6044 | Then.get() == S->getThen() && |
| 6045 | Else.get() == S->getElse()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6046 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6047 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6048 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 6049 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6050 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6054 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6055 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6056 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6057 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6058 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 6059 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6060 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 6061 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 6062 | getDerived().TransformDefinition( |
| 6063 | S->getConditionVariable()->getLocation(), |
| 6064 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 6065 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6066 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6067 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 6068 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6069 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6070 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6071 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6073 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6074 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6075 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6076 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 6077 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6078 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6079 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6080 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6081 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6082 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6083 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6084 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6085 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6086 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6087 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 6088 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6090 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6091 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6092 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6093 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6094 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6095 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6096 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 6097 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6098 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 6099 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 6100 | getDerived().TransformDefinition( |
| 6101 | S->getConditionVariable()->getLocation(), |
| 6102 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 6103 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6104 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6105 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 6106 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6107 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6108 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6109 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6110 | |
| 6111 | if (S->getCond()) { |
| 6112 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6113 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 6114 | S->getWhileLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 6115 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6116 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6117 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6118 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6119 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6120 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6121 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6122 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6123 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6124 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6125 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6126 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6127 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6128 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6129 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6130 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6131 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6132 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6133 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6134 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6135 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6136 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6137 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6138 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6139 | } |
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 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6142 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6143 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6144 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6145 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6146 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6147 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6148 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6149 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6150 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6151 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6152 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6153 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6154 | if (!getDerived().AlwaysRebuild() && |
| 6155 | Cond.get() == S->getCond() && |
| 6156 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6157 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6158 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6159 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 6160 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6161 | S->getRParenLoc()); |
| 6162 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6163 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6164 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6165 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6166 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6167 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6168 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6169 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6170 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6171 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6172 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6173 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6174 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6175 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6176 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6177 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 6178 | getDerived().TransformDefinition( |
| 6179 | S->getConditionVariable()->getLocation(), |
| 6180 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6181 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6182 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6183 | } else { |
| 6184 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6185 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6186 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6187 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6188 | |
| 6189 | if (S->getCond()) { |
| 6190 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6191 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 6192 | S->getForLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 6193 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6194 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6195 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6196 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6197 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 6198 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 6199 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6200 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6201 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6202 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6203 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6204 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6205 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6206 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6207 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6208 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6209 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 6210 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6211 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6212 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6213 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6214 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6215 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6216 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6217 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6218 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6219 | if (!getDerived().AlwaysRebuild() && |
| 6220 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6221 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6222 | Inc.get() == S->getInc() && |
| 6223 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6224 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6225 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6226 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6227 | Init.get(), FullCond, ConditionVar, |
| 6228 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6232 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6233 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6234 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 6235 | S->getLabel()); |
| 6236 | if (!LD) |
| 6237 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6238 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6239 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6240 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6241 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6245 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6246 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6247 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6248 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6249 | return StmtError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6250 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6251 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6252 | if (!getDerived().AlwaysRebuild() && |
| 6253 | Target.get() == S->getTarget()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6254 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6255 | |
| 6256 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6257 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6261 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6262 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6263 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6264 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6265 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6266 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6267 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6268 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6269 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6270 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6271 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6272 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6273 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6274 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Richard Smith | 3b71752 | 2014-08-21 20:51:13 +0000 | [diff] [blame] | 6275 | ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 6276 | /*NotCopyInit*/false); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6277 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6278 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6279 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6280 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6281 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6282 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6283 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6284 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6285 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6286 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6287 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6288 | bool DeclChanged = false; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6289 | SmallVector<Decl *, 4> Decls; |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 6290 | for (auto *D : S->decls()) { |
| 6291 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6292 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6293 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6294 | |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 6295 | if (Transformed != D) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6296 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6297 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6298 | Decls.push_back(Transformed); |
| 6299 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6300 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6301 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6302 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6303 | |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 6304 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6305 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6306 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6307 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6308 | StmtResult |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 6309 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6310 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6311 | SmallVector<Expr*, 8> Constraints; |
| 6312 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6313 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 6314 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6315 | ExprResult AsmString; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6316 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6317 | |
| 6318 | bool ExprsChanged = false; |
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 | // Go through the outputs. |
| 6321 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 6322 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6323 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6324 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6325 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6326 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6327 | // Transform the output expr. |
| 6328 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6329 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6330 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6331 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6332 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6333 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6334 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6335 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6336 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6337 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6338 | // Go through the inputs. |
| 6339 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 6340 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6341 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6342 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6343 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6344 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6345 | // Transform the input expr. |
| 6346 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6347 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6348 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6349 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6350 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6351 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6352 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6353 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6354 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6355 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6356 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6357 | return S; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6358 | |
| 6359 | // Go through the clobbers. |
| 6360 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 6361 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6362 | |
| 6363 | // No need to transform the asm string literal. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6364 | AsmString = S->getAsmString(); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 6365 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 6366 | S->isVolatile(), S->getNumOutputs(), |
| 6367 | S->getNumInputs(), Names.data(), |
| 6368 | Constraints, Exprs, AsmString.get(), |
| 6369 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6370 | } |
| 6371 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6372 | template<typename Derived> |
| 6373 | StmtResult |
| 6374 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 6375 | ArrayRef<Token> AsmToks = |
| 6376 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 6377 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6378 | bool HadError = false, HadChange = false; |
| 6379 | |
| 6380 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 6381 | SmallVector<Expr*, 8> TransformedExprs; |
| 6382 | TransformedExprs.reserve(SrcExprs.size()); |
| 6383 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 6384 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 6385 | if (!Result.isUsable()) { |
| 6386 | HadError = true; |
| 6387 | } else { |
| 6388 | HadChange |= (Result.get() != SrcExprs[i]); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6389 | TransformedExprs.push_back(Result.get()); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6390 | } |
| 6391 | } |
| 6392 | |
| 6393 | if (HadError) return StmtError(); |
| 6394 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 6395 | return Owned(S); |
| 6396 | |
Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 6397 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6398 | AsmToks, S->getAsmString(), |
| 6399 | S->getNumOutputs(), S->getNumInputs(), |
| 6400 | S->getAllConstraints(), S->getClobbers(), |
| 6401 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6402 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6403 | |
| 6404 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6405 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6406 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6407 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6408 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6409 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6410 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6411 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6412 | // Transform the @catch statements (if present). |
| 6413 | bool AnyCatchChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6414 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6415 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6416 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6417 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6418 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6419 | if (Catch.get() != S->getCatchStmt(I)) |
| 6420 | AnyCatchChanged = true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6421 | CatchStmts.push_back(Catch.get()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6422 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6423 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6424 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6425 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6426 | if (S->getFinallyStmt()) { |
| 6427 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 6428 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6429 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | // If nothing changed, just retain this statement. |
| 6433 | if (!getDerived().AlwaysRebuild() && |
| 6434 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6435 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6436 | Finally.get() == S->getFinallyStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6437 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6438 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6439 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6440 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6441 | CatchStmts, Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6442 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6443 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6444 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6445 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6446 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6447 | // Transform the @catch parameter, if there is one. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6448 | VarDecl *Var = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6449 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6450 | TypeSourceInfo *TSInfo = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6451 | if (FromVar->getTypeSourceInfo()) { |
| 6452 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 6453 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6454 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6455 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6456 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6457 | QualType T; |
| 6458 | if (TSInfo) |
| 6459 | T = TSInfo->getType(); |
| 6460 | else { |
| 6461 | T = getDerived().TransformType(FromVar->getType()); |
| 6462 | if (T.isNull()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6463 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6464 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6465 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6466 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 6467 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6468 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6469 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6470 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6471 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6472 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6473 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6474 | |
| 6475 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6476 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6477 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6478 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6479 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6480 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6481 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6482 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6483 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6484 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6485 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6486 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6487 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6488 | // If nothing changed, just retain this statement. |
| 6489 | if (!getDerived().AlwaysRebuild() && |
| 6490 | Body.get() == S->getFinallyBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6491 | return S; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6492 | |
| 6493 | // Build a new statement. |
| 6494 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6495 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6496 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6497 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6498 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6499 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6500 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6501 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6502 | if (S->getThrowExpr()) { |
| 6503 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 6504 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6505 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6506 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6507 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6508 | if (!getDerived().AlwaysRebuild() && |
| 6509 | Operand.get() == S->getThrowExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6510 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6511 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6512 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6513 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6515 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6516 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6517 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6518 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6519 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6520 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6521 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6522 | return StmtError(); |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 6523 | Object = |
| 6524 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 6525 | Object.get()); |
| 6526 | if (Object.isInvalid()) |
| 6527 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6528 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6529 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6530 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6531 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6532 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6533 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6534 | // If nothing change, just retain the current statement. |
| 6535 | if (!getDerived().AlwaysRebuild() && |
| 6536 | Object.get() == S->getSynchExpr() && |
| 6537 | Body.get() == S->getSynchBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6538 | return S; |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6539 | |
| 6540 | // Build a new statement. |
| 6541 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6542 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6543 | } |
| 6544 | |
| 6545 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6546 | StmtResult |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6547 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 6548 | ObjCAutoreleasePoolStmt *S) { |
| 6549 | // Transform the body. |
| 6550 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 6551 | if (Body.isInvalid()) |
| 6552 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6553 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6554 | // If nothing changed, just retain this statement. |
| 6555 | if (!getDerived().AlwaysRebuild() && |
| 6556 | Body.get() == S->getSubStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6557 | return S; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6558 | |
| 6559 | // Build a new statement. |
| 6560 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 6561 | S->getAtLoc(), Body.get()); |
| 6562 | } |
| 6563 | |
| 6564 | template<typename Derived> |
| 6565 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6566 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6567 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6568 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6569 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6570 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6571 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6572 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6573 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6574 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6575 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6576 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6577 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6578 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6579 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6580 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6581 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6582 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6583 | // If nothing changed, just retain this statement. |
| 6584 | if (!getDerived().AlwaysRebuild() && |
| 6585 | Element.get() == S->getElement() && |
| 6586 | Collection.get() == S->getCollection() && |
| 6587 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6588 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6589 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6590 | // Build a new statement. |
| 6591 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6592 | Element.get(), |
| 6593 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6594 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6595 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6596 | } |
| 6597 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6598 | template <typename Derived> |
| 6599 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6600 | // Transform the exception declaration, if any. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6601 | VarDecl *Var = nullptr; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6602 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 6603 | TypeSourceInfo *T = |
| 6604 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 6605 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6606 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6607 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6608 | Var = getDerived().RebuildExceptionDecl( |
| 6609 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 6610 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6611 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6612 | return StmtError(); |
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 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6615 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6616 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6617 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6618 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6619 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6620 | if (!getDerived().AlwaysRebuild() && !Var && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6621 | Handler.get() == S->getHandlerBlock()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6622 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6623 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6624 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6625 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6626 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6627 | template <typename Derived> |
| 6628 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6629 | // Transform the try block itself. |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6630 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6631 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6632 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6633 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6634 | // Transform the handlers. |
| 6635 | bool HandlerChanged = false; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6636 | SmallVector<Stmt *, 8> Handlers; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6637 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6638 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6639 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6640 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6641 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6642 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6643 | Handlers.push_back(Handler.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6644 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6645 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6646 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6647 | !HandlerChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6648 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6649 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6650 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6651 | Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6652 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6653 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6654 | template<typename Derived> |
| 6655 | StmtResult |
| 6656 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6657 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6658 | if (Range.isInvalid()) |
| 6659 | return StmtError(); |
| 6660 | |
| 6661 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6662 | if (BeginEnd.isInvalid()) |
| 6663 | return StmtError(); |
| 6664 | |
| 6665 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6666 | if (Cond.isInvalid()) |
| 6667 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6668 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6669 | Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc()); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6670 | if (Cond.isInvalid()) |
| 6671 | return StmtError(); |
| 6672 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6673 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6674 | |
| 6675 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6676 | if (Inc.isInvalid()) |
| 6677 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6678 | if (Inc.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6679 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6680 | |
| 6681 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6682 | if (LoopVar.isInvalid()) |
| 6683 | return StmtError(); |
| 6684 | |
| 6685 | StmtResult NewStmt = S; |
| 6686 | if (getDerived().AlwaysRebuild() || |
| 6687 | Range.get() != S->getRangeStmt() || |
| 6688 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6689 | Cond.get() != S->getCond() || |
| 6690 | Inc.get() != S->getInc() || |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6691 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6692 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6693 | S->getColonLoc(), Range.get(), |
| 6694 | BeginEnd.get(), Cond.get(), |
| 6695 | Inc.get(), LoopVar.get(), |
| 6696 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6697 | if (NewStmt.isInvalid()) |
| 6698 | return StmtError(); |
| 6699 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6700 | |
| 6701 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6702 | if (Body.isInvalid()) |
| 6703 | return StmtError(); |
| 6704 | |
| 6705 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6706 | // 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] | 6707 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6708 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6709 | S->getColonLoc(), Range.get(), |
| 6710 | BeginEnd.get(), Cond.get(), |
| 6711 | Inc.get(), LoopVar.get(), |
| 6712 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6713 | if (NewStmt.isInvalid()) |
| 6714 | return StmtError(); |
| 6715 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6716 | |
| 6717 | if (NewStmt.get() == S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6718 | return S; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6719 | |
| 6720 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6721 | } |
| 6722 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6723 | template<typename Derived> |
| 6724 | StmtResult |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6725 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6726 | MSDependentExistsStmt *S) { |
| 6727 | // Transform the nested-name-specifier, if any. |
| 6728 | NestedNameSpecifierLoc QualifierLoc; |
| 6729 | if (S->getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6730 | QualifierLoc |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6731 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6732 | if (!QualifierLoc) |
| 6733 | return StmtError(); |
| 6734 | } |
| 6735 | |
| 6736 | // Transform the declaration name. |
| 6737 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6738 | if (NameInfo.getName()) { |
| 6739 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6740 | if (!NameInfo.getName()) |
| 6741 | return StmtError(); |
| 6742 | } |
| 6743 | |
| 6744 | // Check whether anything changed. |
| 6745 | if (!getDerived().AlwaysRebuild() && |
| 6746 | QualifierLoc == S->getQualifierLoc() && |
| 6747 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6748 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6749 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6750 | // Determine whether this name exists, if we can. |
| 6751 | CXXScopeSpec SS; |
| 6752 | SS.Adopt(QualifierLoc); |
| 6753 | bool Dependent = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6754 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6755 | case Sema::IER_Exists: |
| 6756 | if (S->isIfExists()) |
| 6757 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6758 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6759 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6760 | |
| 6761 | case Sema::IER_DoesNotExist: |
| 6762 | if (S->isIfNotExists()) |
| 6763 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6764 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6765 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6766 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6767 | case Sema::IER_Dependent: |
| 6768 | Dependent = true; |
| 6769 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6770 | |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6771 | case Sema::IER_Error: |
| 6772 | return StmtError(); |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6773 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6774 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6775 | // We need to continue with the instantiation, so do so now. |
| 6776 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6777 | if (SubStmt.isInvalid()) |
| 6778 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6779 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6780 | // If we have resolved the name, just transform to the substatement. |
| 6781 | if (!Dependent) |
| 6782 | return SubStmt; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6783 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6784 | // The name is still dependent, so build a dependent expression again. |
| 6785 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6786 | S->isIfExists(), |
| 6787 | QualifierLoc, |
| 6788 | NameInfo, |
| 6789 | SubStmt.get()); |
| 6790 | } |
| 6791 | |
| 6792 | template<typename Derived> |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6793 | ExprResult |
| 6794 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6795 | NestedNameSpecifierLoc QualifierLoc; |
| 6796 | if (E->getQualifierLoc()) { |
| 6797 | QualifierLoc |
| 6798 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6799 | if (!QualifierLoc) |
| 6800 | return ExprError(); |
| 6801 | } |
| 6802 | |
| 6803 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6804 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6805 | if (!PD) |
| 6806 | return ExprError(); |
| 6807 | |
| 6808 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6809 | if (Base.isInvalid()) |
| 6810 | return ExprError(); |
| 6811 | |
| 6812 | return new (SemaRef.getASTContext()) |
| 6813 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6814 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6815 | QualifierLoc, E->getMemberLoc()); |
| 6816 | } |
| 6817 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6818 | template <typename Derived> |
| 6819 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6820 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6821 | if (TryBlock.isInvalid()) |
| 6822 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6823 | |
| 6824 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6825 | if (Handler.isInvalid()) |
| 6826 | return StmtError(); |
| 6827 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6828 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 6829 | Handler.get() == S->getHandler()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6830 | return S; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6831 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 6832 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 6833 | TryBlock.get(), Handler.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6834 | } |
| 6835 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6836 | template <typename Derived> |
| 6837 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6838 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6839 | if (Block.isInvalid()) |
| 6840 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6841 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6842 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6843 | } |
| 6844 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6845 | template <typename Derived> |
| 6846 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6847 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6848 | if (FilterExpr.isInvalid()) |
| 6849 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6850 | |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6851 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6852 | if (Block.isInvalid()) |
| 6853 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6854 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6855 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 6856 | Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6857 | } |
| 6858 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6859 | template <typename Derived> |
| 6860 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6861 | if (isa<SEHFinallyStmt>(Handler)) |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6862 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6863 | else |
| 6864 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6865 | } |
| 6866 | |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 6867 | template<typename Derived> |
| 6868 | StmtResult |
| 6869 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 6870 | return S; |
| 6871 | } |
| 6872 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6873 | //===----------------------------------------------------------------------===// |
| 6874 | // OpenMP directive transformation |
| 6875 | //===----------------------------------------------------------------------===// |
| 6876 | template <typename Derived> |
| 6877 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 6878 | OMPExecutableDirective *D) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6879 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6880 | // Transform the clauses |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6881 | llvm::SmallVector<OMPClause *, 16> TClauses; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6882 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6883 | TClauses.reserve(Clauses.size()); |
| 6884 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6885 | I != E; ++I) { |
| 6886 | if (*I) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 6887 | getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6888 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 6889 | getDerived().getSema().EndOpenMPClause(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6890 | if (Clause) |
| 6891 | TClauses.push_back(Clause); |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6892 | } else { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 6893 | TClauses.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6894 | } |
| 6895 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6896 | StmtResult AssociatedStmt; |
| 6897 | if (D->hasAssociatedStmt()) { |
| 6898 | if (!D->getAssociatedStmt()) { |
| 6899 | return StmtError(); |
| 6900 | } |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 6901 | getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), |
| 6902 | /*CurScope=*/nullptr); |
| 6903 | StmtResult Body; |
| 6904 | { |
| 6905 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 6906 | Body = getDerived().TransformStmt( |
| 6907 | cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt()); |
| 6908 | } |
| 6909 | AssociatedStmt = |
| 6910 | getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6911 | if (AssociatedStmt.isInvalid()) { |
| 6912 | return StmtError(); |
| 6913 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6914 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6915 | if (TClauses.size() != Clauses.size()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6916 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6917 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6918 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6919 | // Transform directive name for 'omp critical' directive. |
| 6920 | DeclarationNameInfo DirName; |
| 6921 | if (D->getDirectiveKind() == OMPD_critical) { |
| 6922 | DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 6923 | DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 6924 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6925 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
| 6926 | if (D->getDirectiveKind() == OMPD_cancellation_point) { |
| 6927 | CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6928 | } else if (D->getDirectiveKind() == OMPD_cancel) { |
| 6929 | CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6930 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6931 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6932 | return getDerived().RebuildOMPExecutableDirective( |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6933 | D->getDirectiveKind(), DirName, CancelRegion, TClauses, |
| 6934 | AssociatedStmt.get(), D->getLocStart(), D->getLocEnd()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6935 | } |
| 6936 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6937 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6938 | StmtResult |
| 6939 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 6940 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6941 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| 6942 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6943 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6944 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6945 | return Res; |
| 6946 | } |
| 6947 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6948 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6949 | StmtResult |
| 6950 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 6951 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6952 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| 6953 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6954 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6955 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6956 | return Res; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6957 | } |
| 6958 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6959 | template <typename Derived> |
| 6960 | StmtResult |
| 6961 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 6962 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6963 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| 6964 | D->getLocStart()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6965 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6966 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6967 | return Res; |
| 6968 | } |
| 6969 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6970 | template <typename Derived> |
| 6971 | StmtResult |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 6972 | TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 6973 | DeclarationNameInfo DirName; |
| 6974 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, |
| 6975 | D->getLocStart()); |
| 6976 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6977 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6978 | return Res; |
| 6979 | } |
| 6980 | |
| 6981 | template <typename Derived> |
| 6982 | StmtResult |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6983 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 6984 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6985 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| 6986 | D->getLocStart()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6987 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6988 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6989 | return Res; |
| 6990 | } |
| 6991 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6992 | template <typename Derived> |
| 6993 | StmtResult |
| 6994 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 6995 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6996 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| 6997 | D->getLocStart()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6998 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6999 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7000 | return Res; |
| 7001 | } |
| 7002 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7003 | template <typename Derived> |
| 7004 | StmtResult |
| 7005 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 7006 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7007 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| 7008 | D->getLocStart()); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7009 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7010 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7011 | return Res; |
| 7012 | } |
| 7013 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7014 | template <typename Derived> |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 7015 | StmtResult |
| 7016 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 7017 | DeclarationNameInfo DirName; |
| 7018 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| 7019 | D->getLocStart()); |
| 7020 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7021 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7022 | return Res; |
| 7023 | } |
| 7024 | |
| 7025 | template <typename Derived> |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7026 | StmtResult |
| 7027 | TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 7028 | getDerived().getSema().StartOpenMPDSABlock( |
| 7029 | OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart()); |
| 7030 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7031 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7032 | return Res; |
| 7033 | } |
| 7034 | |
| 7035 | template <typename Derived> |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7036 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 7037 | OMPParallelForDirective *D) { |
| 7038 | DeclarationNameInfo DirName; |
| 7039 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| 7040 | nullptr, D->getLocStart()); |
| 7041 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7042 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7043 | return Res; |
| 7044 | } |
| 7045 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7046 | template <typename Derived> |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 7047 | StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 7048 | OMPParallelForSimdDirective *D) { |
| 7049 | DeclarationNameInfo DirName; |
| 7050 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, |
| 7051 | nullptr, D->getLocStart()); |
| 7052 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7053 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7054 | return Res; |
| 7055 | } |
| 7056 | |
| 7057 | template <typename Derived> |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7058 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 7059 | OMPParallelSectionsDirective *D) { |
| 7060 | DeclarationNameInfo DirName; |
| 7061 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| 7062 | nullptr, D->getLocStart()); |
| 7063 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7064 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7065 | return Res; |
| 7066 | } |
| 7067 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7068 | template <typename Derived> |
| 7069 | StmtResult |
| 7070 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 7071 | DeclarationNameInfo DirName; |
| 7072 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| 7073 | D->getLocStart()); |
| 7074 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7075 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7076 | return Res; |
| 7077 | } |
| 7078 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7079 | template <typename Derived> |
| 7080 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 7081 | OMPTaskyieldDirective *D) { |
| 7082 | DeclarationNameInfo DirName; |
| 7083 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| 7084 | D->getLocStart()); |
| 7085 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7086 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7087 | return Res; |
| 7088 | } |
| 7089 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 7090 | template <typename Derived> |
| 7091 | StmtResult |
| 7092 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 7093 | DeclarationNameInfo DirName; |
| 7094 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| 7095 | D->getLocStart()); |
| 7096 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7097 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7098 | return Res; |
| 7099 | } |
| 7100 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 7101 | template <typename Derived> |
| 7102 | StmtResult |
| 7103 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 7104 | DeclarationNameInfo DirName; |
| 7105 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| 7106 | D->getLocStart()); |
| 7107 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7108 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7109 | return Res; |
| 7110 | } |
| 7111 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7112 | template <typename Derived> |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 7113 | StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( |
| 7114 | OMPTaskgroupDirective *D) { |
| 7115 | DeclarationNameInfo DirName; |
| 7116 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, |
| 7117 | D->getLocStart()); |
| 7118 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7119 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7120 | return Res; |
| 7121 | } |
| 7122 | |
| 7123 | template <typename Derived> |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7124 | StmtResult |
| 7125 | TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 7126 | DeclarationNameInfo DirName; |
| 7127 | getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, |
| 7128 | D->getLocStart()); |
| 7129 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7130 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7131 | return Res; |
| 7132 | } |
| 7133 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 7134 | template <typename Derived> |
| 7135 | StmtResult |
| 7136 | TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 7137 | DeclarationNameInfo DirName; |
| 7138 | getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, |
| 7139 | D->getLocStart()); |
| 7140 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7141 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7142 | return Res; |
| 7143 | } |
| 7144 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 7145 | template <typename Derived> |
| 7146 | StmtResult |
| 7147 | TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 7148 | DeclarationNameInfo DirName; |
| 7149 | getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, |
| 7150 | D->getLocStart()); |
| 7151 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7152 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7153 | return Res; |
| 7154 | } |
| 7155 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 7156 | template <typename Derived> |
| 7157 | StmtResult |
| 7158 | TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 7159 | DeclarationNameInfo DirName; |
| 7160 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, |
| 7161 | D->getLocStart()); |
| 7162 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7163 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7164 | return Res; |
| 7165 | } |
| 7166 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7167 | template <typename Derived> |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 7168 | StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( |
| 7169 | OMPTargetDataDirective *D) { |
| 7170 | DeclarationNameInfo DirName; |
| 7171 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, |
| 7172 | D->getLocStart()); |
| 7173 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7174 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7175 | return Res; |
| 7176 | } |
| 7177 | |
| 7178 | template <typename Derived> |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7179 | StmtResult |
| 7180 | TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 7181 | DeclarationNameInfo DirName; |
| 7182 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, |
| 7183 | D->getLocStart()); |
| 7184 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7185 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7186 | return Res; |
| 7187 | } |
| 7188 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7189 | template <typename Derived> |
| 7190 | StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( |
| 7191 | OMPCancellationPointDirective *D) { |
| 7192 | DeclarationNameInfo DirName; |
| 7193 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, |
| 7194 | nullptr, D->getLocStart()); |
| 7195 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7196 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7197 | return Res; |
| 7198 | } |
| 7199 | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7200 | template <typename Derived> |
| 7201 | StmtResult |
| 7202 | TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { |
| 7203 | DeclarationNameInfo DirName; |
| 7204 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, |
| 7205 | D->getLocStart()); |
| 7206 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7207 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7208 | return Res; |
| 7209 | } |
| 7210 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7211 | //===----------------------------------------------------------------------===// |
| 7212 | // OpenMP clause transformation |
| 7213 | //===----------------------------------------------------------------------===// |
| 7214 | template <typename Derived> |
| 7215 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 7216 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 7217 | if (Cond.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7218 | return nullptr; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7219 | return getDerived().RebuildOMPIfClause( |
| 7220 | C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(), |
| 7221 | C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd()); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7222 | } |
| 7223 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7224 | template <typename Derived> |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7225 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 7226 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 7227 | if (Cond.isInvalid()) |
| 7228 | return nullptr; |
| 7229 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(), |
| 7230 | C->getLParenLoc(), C->getLocEnd()); |
| 7231 | } |
| 7232 | |
| 7233 | template <typename Derived> |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7234 | OMPClause * |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7235 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 7236 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 7237 | if (NumThreads.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7238 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7239 | return getDerived().RebuildOMPNumThreadsClause( |
| 7240 | NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7241 | } |
| 7242 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7243 | template <typename Derived> |
| 7244 | OMPClause * |
| 7245 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 7246 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 7247 | if (E.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7248 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7249 | return getDerived().RebuildOMPSafelenClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7250 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7251 | } |
| 7252 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7253 | template <typename Derived> |
| 7254 | OMPClause * |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7255 | TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { |
| 7256 | ExprResult E = getDerived().TransformExpr(C->getSimdlen()); |
| 7257 | if (E.isInvalid()) |
| 7258 | return nullptr; |
| 7259 | return getDerived().RebuildOMPSimdlenClause( |
| 7260 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7261 | } |
| 7262 | |
| 7263 | template <typename Derived> |
| 7264 | OMPClause * |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7265 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 7266 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 7267 | if (E.isInvalid()) |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 7268 | return nullptr; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7269 | return getDerived().RebuildOMPCollapseClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7270 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7271 | } |
| 7272 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7273 | template <typename Derived> |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7274 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7275 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7276 | return getDerived().RebuildOMPDefaultClause( |
| 7277 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(), |
| 7278 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7279 | } |
| 7280 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7281 | template <typename Derived> |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7282 | OMPClause * |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7283 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7284 | return getDerived().RebuildOMPProcBindClause( |
| 7285 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(), |
| 7286 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7287 | } |
| 7288 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7289 | template <typename Derived> |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7290 | OMPClause * |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7291 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 7292 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 7293 | if (E.isInvalid()) |
| 7294 | return nullptr; |
| 7295 | return getDerived().RebuildOMPScheduleClause( |
| 7296 | C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(), |
| 7297 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd()); |
| 7298 | } |
| 7299 | |
| 7300 | template <typename Derived> |
| 7301 | OMPClause * |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7302 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7303 | ExprResult E; |
| 7304 | if (auto *Num = C->getNumForLoops()) { |
| 7305 | E = getDerived().TransformExpr(Num); |
| 7306 | if (E.isInvalid()) |
| 7307 | return nullptr; |
| 7308 | } |
| 7309 | return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(), |
| 7310 | C->getLParenLoc(), E.get()); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7311 | } |
| 7312 | |
| 7313 | template <typename Derived> |
| 7314 | OMPClause * |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7315 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 7316 | // No need to rebuild this clause, no template-dependent parameters. |
| 7317 | return C; |
| 7318 | } |
| 7319 | |
| 7320 | template <typename Derived> |
| 7321 | OMPClause * |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7322 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 7323 | // No need to rebuild this clause, no template-dependent parameters. |
| 7324 | return C; |
| 7325 | } |
| 7326 | |
| 7327 | template <typename Derived> |
| 7328 | OMPClause * |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7329 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 7330 | // No need to rebuild this clause, no template-dependent parameters. |
| 7331 | return C; |
| 7332 | } |
| 7333 | |
| 7334 | template <typename Derived> |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7335 | OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 7336 | // No need to rebuild this clause, no template-dependent parameters. |
| 7337 | return C; |
| 7338 | } |
| 7339 | |
| 7340 | template <typename Derived> |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7341 | OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 7342 | // No need to rebuild this clause, no template-dependent parameters. |
| 7343 | return C; |
| 7344 | } |
| 7345 | |
| 7346 | template <typename Derived> |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7347 | OMPClause * |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7348 | TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 7349 | // No need to rebuild this clause, no template-dependent parameters. |
| 7350 | return C; |
| 7351 | } |
| 7352 | |
| 7353 | template <typename Derived> |
| 7354 | OMPClause * |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7355 | TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 7356 | // No need to rebuild this clause, no template-dependent parameters. |
| 7357 | return C; |
| 7358 | } |
| 7359 | |
| 7360 | template <typename Derived> |
| 7361 | OMPClause * |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7362 | TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 7363 | // No need to rebuild this clause, no template-dependent parameters. |
| 7364 | return C; |
| 7365 | } |
| 7366 | |
| 7367 | template <typename Derived> |
| 7368 | OMPClause * |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7369 | TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { |
| 7370 | // No need to rebuild this clause, no template-dependent parameters. |
| 7371 | return C; |
| 7372 | } |
| 7373 | |
| 7374 | template <typename Derived> |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7375 | OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { |
| 7376 | // No need to rebuild this clause, no template-dependent parameters. |
| 7377 | return C; |
| 7378 | } |
| 7379 | |
| 7380 | template <typename Derived> |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7381 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7382 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7383 | llvm::SmallVector<Expr *, 16> Vars; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7384 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7385 | for (auto *VE : C->varlists()) { |
| 7386 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7387 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7388 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7389 | Vars.push_back(EVar.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7390 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7391 | return getDerived().RebuildOMPPrivateClause( |
| 7392 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7393 | } |
| 7394 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7395 | template <typename Derived> |
| 7396 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 7397 | OMPFirstprivateClause *C) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7398 | llvm::SmallVector<Expr *, 16> Vars; |
| 7399 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7400 | for (auto *VE : C->varlists()) { |
| 7401 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7402 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7403 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7404 | Vars.push_back(EVar.get()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7405 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7406 | return getDerived().RebuildOMPFirstprivateClause( |
| 7407 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7408 | } |
| 7409 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7410 | template <typename Derived> |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7411 | OMPClause * |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7412 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *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()) |
| 7418 | return nullptr; |
| 7419 | Vars.push_back(EVar.get()); |
| 7420 | } |
| 7421 | return getDerived().RebuildOMPLastprivateClause( |
| 7422 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7423 | } |
| 7424 | |
| 7425 | template <typename Derived> |
| 7426 | OMPClause * |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7427 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 7428 | llvm::SmallVector<Expr *, 16> Vars; |
| 7429 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7430 | for (auto *VE : C->varlists()) { |
| 7431 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7432 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7433 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7434 | Vars.push_back(EVar.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7435 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7436 | return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(), |
| 7437 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7438 | } |
| 7439 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7440 | template <typename Derived> |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7441 | OMPClause * |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7442 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 7443 | llvm::SmallVector<Expr *, 16> Vars; |
| 7444 | Vars.reserve(C->varlist_size()); |
| 7445 | for (auto *VE : C->varlists()) { |
| 7446 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7447 | if (EVar.isInvalid()) |
| 7448 | return nullptr; |
| 7449 | Vars.push_back(EVar.get()); |
| 7450 | } |
| 7451 | CXXScopeSpec ReductionIdScopeSpec; |
| 7452 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 7453 | |
| 7454 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 7455 | if (NameInfo.getName()) { |
| 7456 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7457 | if (!NameInfo.getName()) |
| 7458 | return nullptr; |
| 7459 | } |
| 7460 | return getDerived().RebuildOMPReductionClause( |
| 7461 | Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(), |
| 7462 | C->getLocEnd(), ReductionIdScopeSpec, NameInfo); |
| 7463 | } |
| 7464 | |
| 7465 | template <typename Derived> |
| 7466 | OMPClause * |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7467 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 7468 | llvm::SmallVector<Expr *, 16> Vars; |
| 7469 | Vars.reserve(C->varlist_size()); |
| 7470 | for (auto *VE : C->varlists()) { |
| 7471 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7472 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7473 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7474 | Vars.push_back(EVar.get()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7475 | } |
| 7476 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 7477 | if (Step.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7478 | return nullptr; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7479 | return getDerived().RebuildOMPLinearClause( |
| 7480 | Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(), |
| 7481 | C->getModifierLoc(), C->getColonLoc(), C->getLocEnd()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7482 | } |
| 7483 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7484 | template <typename Derived> |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7485 | OMPClause * |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7486 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 7487 | llvm::SmallVector<Expr *, 16> Vars; |
| 7488 | Vars.reserve(C->varlist_size()); |
| 7489 | for (auto *VE : C->varlists()) { |
| 7490 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7491 | if (EVar.isInvalid()) |
| 7492 | return nullptr; |
| 7493 | Vars.push_back(EVar.get()); |
| 7494 | } |
| 7495 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 7496 | if (Alignment.isInvalid()) |
| 7497 | return nullptr; |
| 7498 | return getDerived().RebuildOMPAlignedClause( |
| 7499 | Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(), |
| 7500 | C->getColonLoc(), C->getLocEnd()); |
| 7501 | } |
| 7502 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7503 | template <typename Derived> |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7504 | OMPClause * |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7505 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 7506 | llvm::SmallVector<Expr *, 16> Vars; |
| 7507 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7508 | for (auto *VE : C->varlists()) { |
| 7509 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7510 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7511 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7512 | Vars.push_back(EVar.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7513 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7514 | return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(), |
| 7515 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7516 | } |
| 7517 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7518 | template <typename Derived> |
| 7519 | OMPClause * |
| 7520 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 7521 | llvm::SmallVector<Expr *, 16> Vars; |
| 7522 | Vars.reserve(C->varlist_size()); |
| 7523 | for (auto *VE : C->varlists()) { |
| 7524 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7525 | if (EVar.isInvalid()) |
| 7526 | return nullptr; |
| 7527 | Vars.push_back(EVar.get()); |
| 7528 | } |
| 7529 | return getDerived().RebuildOMPCopyprivateClause( |
| 7530 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7531 | } |
| 7532 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7533 | template <typename Derived> |
| 7534 | OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 7535 | llvm::SmallVector<Expr *, 16> Vars; |
| 7536 | Vars.reserve(C->varlist_size()); |
| 7537 | for (auto *VE : C->varlists()) { |
| 7538 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7539 | if (EVar.isInvalid()) |
| 7540 | return nullptr; |
| 7541 | Vars.push_back(EVar.get()); |
| 7542 | } |
| 7543 | return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(), |
| 7544 | C->getLParenLoc(), C->getLocEnd()); |
| 7545 | } |
| 7546 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7547 | template <typename Derived> |
| 7548 | OMPClause * |
| 7549 | TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { |
| 7550 | llvm::SmallVector<Expr *, 16> Vars; |
| 7551 | Vars.reserve(C->varlist_size()); |
| 7552 | for (auto *VE : C->varlists()) { |
| 7553 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7554 | if (EVar.isInvalid()) |
| 7555 | return nullptr; |
| 7556 | Vars.push_back(EVar.get()); |
| 7557 | } |
| 7558 | return getDerived().RebuildOMPDependClause( |
| 7559 | C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars, |
| 7560 | C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7561 | } |
| 7562 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7563 | template <typename Derived> |
| 7564 | OMPClause * |
| 7565 | TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { |
| 7566 | ExprResult E = getDerived().TransformExpr(C->getDevice()); |
| 7567 | if (E.isInvalid()) |
| 7568 | return nullptr; |
| 7569 | return getDerived().RebuildOMPDeviceClause( |
| 7570 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7571 | } |
| 7572 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7573 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7574 | // Expression transformation |
| 7575 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7576 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7577 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7578 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 7579 | if (!E->isTypeDependent()) |
| 7580 | return E; |
| 7581 | |
| 7582 | return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| 7583 | E->getIdentType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7585 | |
| 7586 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7587 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7588 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7589 | NestedNameSpecifierLoc QualifierLoc; |
| 7590 | if (E->getQualifierLoc()) { |
| 7591 | QualifierLoc |
| 7592 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7593 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7594 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7595 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7596 | |
| 7597 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7598 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7599 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7600 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7601 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7602 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 7603 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 7604 | if (NameInfo.getName()) { |
| 7605 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7606 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7607 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 7608 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7609 | |
| 7610 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7611 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7612 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7613 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7614 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7615 | |
| 7616 | // Mark it referenced in the new context regardless. |
| 7617 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7618 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7619 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7620 | return E; |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7621 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7622 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7623 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7624 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7625 | TemplateArgs = &TransArgs; |
| 7626 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 7627 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7628 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7629 | E->getNumTemplateArgs(), |
| 7630 | TransArgs)) |
| 7631 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7632 | } |
| 7633 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7634 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7635 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7636 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7638 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7639 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7640 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7641 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7642 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7643 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7644 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7645 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7646 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7647 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7650 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7651 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7652 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7653 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7654 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7655 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7656 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7657 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7658 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7659 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7660 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7661 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7662 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7663 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7664 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7665 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7666 | } |
| 7667 | |
| 7668 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7669 | ExprResult |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 7670 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 7671 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 7672 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 7673 | return SemaRef.MaybeBindToTemporary(E); |
| 7674 | } |
| 7675 | |
| 7676 | template<typename Derived> |
| 7677 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7678 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 7679 | ExprResult ControllingExpr = |
| 7680 | getDerived().TransformExpr(E->getControllingExpr()); |
| 7681 | if (ControllingExpr.isInvalid()) |
| 7682 | return ExprError(); |
| 7683 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7684 | SmallVector<Expr *, 4> AssocExprs; |
| 7685 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7686 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 7687 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 7688 | if (TS) { |
| 7689 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 7690 | if (!AssocType) |
| 7691 | return ExprError(); |
| 7692 | AssocTypes.push_back(AssocType); |
| 7693 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7694 | AssocTypes.push_back(nullptr); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7695 | } |
| 7696 | |
| 7697 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 7698 | if (AssocExpr.isInvalid()) |
| 7699 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7700 | AssocExprs.push_back(AssocExpr.get()); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7701 | } |
| 7702 | |
| 7703 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 7704 | E->getDefaultLoc(), |
| 7705 | E->getRParenLoc(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7706 | ControllingExpr.get(), |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 7707 | AssocTypes, |
| 7708 | AssocExprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7709 | } |
| 7710 | |
| 7711 | template<typename Derived> |
| 7712 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7713 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7714 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7715 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7716 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7717 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7718 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7719 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7720 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7721 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7722 | E->getRParen()); |
| 7723 | } |
| 7724 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7725 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 7726 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 7727 | /// object available. |
| 7728 | template<typename Derived> |
| 7729 | ExprResult |
| 7730 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 7731 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7732 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7733 | else |
| 7734 | return getDerived().TransformExpr(E); |
| 7735 | } |
| 7736 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7737 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7738 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7739 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 7740 | ExprResult SubExpr; |
| 7741 | if (E->getOpcode() == UO_AddrOf) |
| 7742 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 7743 | else |
| 7744 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7745 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7746 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7747 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7748 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7749 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7751 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 7752 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7753 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7754 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7755 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7756 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7757 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7758 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 7759 | // Transform the type. |
| 7760 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7761 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7762 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7763 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7764 | // Transform all of the components into components similar to what the |
| 7765 | // parser uses. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7766 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 7767 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 7768 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7769 | // template code that we don't care. |
| 7770 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7771 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7772 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7773 | SmallVector<Component, 4> Components; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7774 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 7775 | const Node &ON = E->getComponent(I); |
| 7776 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 7777 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 7778 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 7779 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7780 | switch (ON.getKind()) { |
| 7781 | case Node::Array: { |
| 7782 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7783 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7784 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7785 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7786 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7787 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 7788 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7789 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7790 | break; |
| 7791 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7792 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7793 | case Node::Field: |
| 7794 | case Node::Identifier: |
| 7795 | Comp.isBrackets = false; |
| 7796 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 7797 | if (!Comp.U.IdentInfo) |
| 7798 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7799 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7800 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7801 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 7802 | case Node::Base: |
| 7803 | // Will be recomputed during the rebuild. |
| 7804 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7805 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7806 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7807 | Components.push_back(Comp); |
| 7808 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7809 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7810 | // If nothing changed, retain the existing expression. |
| 7811 | if (!getDerived().AlwaysRebuild() && |
| 7812 | Type == E->getTypeSourceInfo() && |
| 7813 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7814 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7815 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7816 | // Build a new offsetof expression. |
| 7817 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame^] | 7818 | Components, E->getRParenLoc()); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7819 | } |
| 7820 | |
| 7821 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7822 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7823 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
Hubert Tong | 2cded44 | 2015-09-01 22:50:31 +0000 | [diff] [blame] | 7824 | assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7825 | "opaque value expression requires transformation"); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7826 | return E; |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7827 | } |
| 7828 | |
| 7829 | template<typename Derived> |
| 7830 | ExprResult |
Kaelyn Takata | e1f49d5 | 2014-10-27 18:07:20 +0000 | [diff] [blame] | 7831 | TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { |
| 7832 | return E; |
| 7833 | } |
| 7834 | |
| 7835 | template<typename Derived> |
| 7836 | ExprResult |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7837 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 7838 | // Rebuild the syntactic form. The original syntactic form has |
| 7839 | // opaque-value expressions in it, so strip those away and rebuild |
| 7840 | // the result. This is a really awful way of doing this, but the |
| 7841 | // better solution (rebuilding the semantic expressions and |
| 7842 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 7843 | // TreeTransform to not strip away implicit conversions. |
| 7844 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 7845 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7846 | if (result.isInvalid()) return ExprError(); |
| 7847 | |
| 7848 | // If that gives us a pseudo-object result back, the pseudo-object |
| 7849 | // expression must have been an lvalue-to-rvalue conversion which we |
| 7850 | // should reapply. |
| 7851 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7852 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7853 | |
| 7854 | return result; |
| 7855 | } |
| 7856 | |
| 7857 | template<typename Derived> |
| 7858 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7859 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 7860 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7861 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7862 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7863 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7864 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7865 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7866 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7867 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7868 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7869 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7870 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7871 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 7872 | E->getKind(), |
| 7873 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7874 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7875 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7876 | // C++0x [expr.sizeof]p1: |
| 7877 | // The operand is either an expression, which is an unevaluated operand |
| 7878 | // [...] |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7879 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7880 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7881 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7882 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 7883 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 7884 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 7885 | ExprResult SubExpr; |
| 7886 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 7887 | if (auto *DRE = |
| 7888 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 7889 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 7890 | PE, DRE, false, &RecoveryTSI); |
| 7891 | else |
| 7892 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 7893 | |
| 7894 | if (RecoveryTSI) { |
| 7895 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 7896 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 7897 | } else if (SubExpr.isInvalid()) |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7898 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7899 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7900 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7901 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7902 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7903 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 7904 | E->getOperatorLoc(), |
| 7905 | E->getKind(), |
| 7906 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7907 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7908 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7909 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7910 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7911 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7912 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7913 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7914 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7915 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7916 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7917 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7918 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7919 | |
| 7920 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7921 | if (!getDerived().AlwaysRebuild() && |
| 7922 | LHS.get() == E->getLHS() && |
| 7923 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7924 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7925 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7926 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7927 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7928 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7929 | E->getRBracketLoc()); |
| 7930 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7931 | |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7932 | template <typename Derived> |
| 7933 | ExprResult |
| 7934 | TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) { |
| 7935 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 7936 | if (Base.isInvalid()) |
| 7937 | return ExprError(); |
| 7938 | |
| 7939 | ExprResult LowerBound; |
| 7940 | if (E->getLowerBound()) { |
| 7941 | LowerBound = getDerived().TransformExpr(E->getLowerBound()); |
| 7942 | if (LowerBound.isInvalid()) |
| 7943 | return ExprError(); |
| 7944 | } |
| 7945 | |
| 7946 | ExprResult Length; |
| 7947 | if (E->getLength()) { |
| 7948 | Length = getDerived().TransformExpr(E->getLength()); |
| 7949 | if (Length.isInvalid()) |
| 7950 | return ExprError(); |
| 7951 | } |
| 7952 | |
| 7953 | if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 7954 | LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength()) |
| 7955 | return E; |
| 7956 | |
| 7957 | return getDerived().RebuildOMPArraySectionExpr( |
| 7958 | Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(), |
| 7959 | Length.get(), E->getRBracketLoc()); |
| 7960 | } |
| 7961 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7962 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7963 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7964 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7965 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7966 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7967 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7968 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7969 | |
| 7970 | // Transform arguments. |
| 7971 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7972 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7973 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7974 | &ArgChanged)) |
| 7975 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7976 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7977 | if (!getDerived().AlwaysRebuild() && |
| 7978 | Callee.get() == E->getCallee() && |
| 7979 | !ArgChanged) |
Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 7980 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7981 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7982 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7983 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7984 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7985 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7986 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7987 | E->getRParenLoc()); |
| 7988 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7989 | |
| 7990 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7991 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7992 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7993 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7994 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7995 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7996 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7997 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7998 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7999 | QualifierLoc |
| 8000 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8001 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8002 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8003 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 8004 | } |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8005 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8006 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 8007 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8008 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 8009 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8010 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8011 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8012 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 8013 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 8014 | if (FoundDecl == E->getMemberDecl()) { |
| 8015 | FoundDecl = Member; |
| 8016 | } else { |
| 8017 | FoundDecl = cast_or_null<NamedDecl>( |
| 8018 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 8019 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8020 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 8021 | } |
| 8022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8023 | if (!getDerived().AlwaysRebuild() && |
| 8024 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8025 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 8026 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 8027 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8028 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8029 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 8030 | // Mark it referenced in the new context regardless. |
| 8031 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8032 | SemaRef.MarkMemberReferenced(E); |
| 8033 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8034 | return E; |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 8035 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8036 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8037 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8038 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8039 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 8040 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8041 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8042 | E->getNumTemplateArgs(), |
| 8043 | TransArgs)) |
| 8044 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 8045 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8047 | // FIXME: Bogus source location for the operator |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 8048 | SourceLocation FakeOperatorLoc = |
| 8049 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8050 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8051 | // FIXME: to do this check properly, we will need to preserve the |
| 8052 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8053 | // base (and therefore couldn't do the check) and a |
| 8054 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8055 | NamedDecl *FirstQualifierInScope = nullptr; |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8056 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8057 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8058 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8059 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8060 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8061 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 8062 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 8063 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8064 | (E->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8065 | ? &TransArgs : nullptr), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8066 | FirstQualifierInScope); |
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 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8072 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8073 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8074 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8075 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8076 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8077 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8078 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8079 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8080 | if (!getDerived().AlwaysRebuild() && |
| 8081 | LHS.get() == E->getLHS() && |
| 8082 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8083 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8084 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 8085 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 8086 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 8087 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8088 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8089 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8090 | } |
| 8091 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8092 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8093 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8094 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8095 | CompoundAssignOperator *E) { |
| 8096 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8098 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8099 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8100 | ExprResult TreeTransform<Derived>:: |
| 8101 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 8102 | // Just rebuild the common and RHS expressions and see whether we |
| 8103 | // get any changes. |
| 8104 | |
| 8105 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 8106 | if (commonExpr.isInvalid()) |
| 8107 | return ExprError(); |
| 8108 | |
| 8109 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 8110 | if (rhs.isInvalid()) |
| 8111 | return ExprError(); |
| 8112 | |
| 8113 | if (!getDerived().AlwaysRebuild() && |
| 8114 | commonExpr.get() == e->getCommon() && |
| 8115 | rhs.get() == e->getFalseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8116 | return e; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8117 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8118 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8119 | e->getQuestionLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8120 | nullptr, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8121 | e->getColonLoc(), |
| 8122 | rhs.get()); |
| 8123 | } |
| 8124 | |
| 8125 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8126 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8127 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8128 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8129 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8130 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8131 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8132 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8133 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8134 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8135 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8136 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8137 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8138 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8139 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8140 | if (!getDerived().AlwaysRebuild() && |
| 8141 | Cond.get() == E->getCond() && |
| 8142 | LHS.get() == E->getLHS() && |
| 8143 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8144 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8145 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8146 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 8147 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8148 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 8149 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8150 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8151 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8152 | |
| 8153 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8154 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8155 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 8156 | // Implicit casts are eliminated during transformation, since they |
| 8157 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8158 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8161 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8162 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8163 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8164 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8165 | if (!Type) |
| 8166 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8167 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8168 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8169 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8170 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8171 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8172 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8173 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8174 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8175 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8176 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8177 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 8178 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8179 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8180 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8181 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8182 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8183 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8184 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8185 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8186 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8187 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 8188 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 8189 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8190 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8191 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8192 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8193 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8194 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8195 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8196 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8197 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8198 | Init.get() == E->getInitializer()) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8199 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8200 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 8201 | // Note: the expression type doesn't necessarily match the |
| 8202 | // type-as-written, but that's okay, because it should always be |
| 8203 | // derivable from the initializer. |
| 8204 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8205 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8206 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8207 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8208 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8209 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8210 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8211 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8212 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8213 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8214 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8215 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8216 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8217 | if (!getDerived().AlwaysRebuild() && |
| 8218 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8219 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8220 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8221 | // FIXME: Bad source location |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 8222 | SourceLocation FakeOperatorLoc = |
| 8223 | SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8224 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8225 | E->getAccessorLoc(), |
| 8226 | E->getAccessor()); |
| 8227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8228 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8229 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8230 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8231 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 8232 | if (InitListExpr *Syntactic = E->getSyntacticForm()) |
| 8233 | E = Syntactic; |
| 8234 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8235 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8236 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8237 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8238 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8239 | Inits, &InitChanged)) |
| 8240 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8241 | |
Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 8242 | if (!getDerived().AlwaysRebuild() && !InitChanged) { |
| 8243 | // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr |
| 8244 | // in some cases. We can't reuse it in general, because the syntactic and |
| 8245 | // semantic forms are linked, and we can't know that semantic form will |
| 8246 | // match even if the syntactic form does. |
| 8247 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8248 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8249 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 8250 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8251 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8252 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8253 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8254 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8255 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8256 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8257 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 8258 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8259 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8260 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8261 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8262 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 8263 | // transform the designators. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8264 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8265 | bool ExprChanged = false; |
| 8266 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 8267 | DEnd = E->designators_end(); |
| 8268 | D != DEnd; ++D) { |
| 8269 | if (D->isFieldDesignator()) { |
| 8270 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 8271 | D->getDotLoc(), |
| 8272 | D->getFieldLoc())); |
| 8273 | continue; |
| 8274 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8275 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8276 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8277 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8278 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8279 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8280 | |
| 8281 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8282 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8283 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8284 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8285 | ArrayExprs.push_back(Index.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8286 | continue; |
| 8287 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8288 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8289 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8290 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8291 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 8292 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8293 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8294 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8295 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8296 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8297 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8298 | |
| 8299 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8300 | End.get(), |
| 8301 | D->getLBracketLoc(), |
| 8302 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8304 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 8305 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8306 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8307 | ArrayExprs.push_back(Start.get()); |
| 8308 | ArrayExprs.push_back(End.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8310 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8311 | if (!getDerived().AlwaysRebuild() && |
| 8312 | Init.get() == E->getInit() && |
| 8313 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8314 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8315 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8316 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8317 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8318 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8319 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8320 | |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 8321 | // Seems that if TransformInitListExpr() only works on the syntactic form of an |
| 8322 | // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. |
| 8323 | template<typename Derived> |
| 8324 | ExprResult |
| 8325 | TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( |
| 8326 | DesignatedInitUpdateExpr *E) { |
| 8327 | llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " |
| 8328 | "initializer"); |
| 8329 | return ExprError(); |
| 8330 | } |
| 8331 | |
| 8332 | template<typename Derived> |
| 8333 | ExprResult |
| 8334 | TreeTransform<Derived>::TransformNoInitExpr( |
| 8335 | NoInitExpr *E) { |
| 8336 | llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); |
| 8337 | return ExprError(); |
| 8338 | } |
| 8339 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8340 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8341 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8342 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8343 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 8344 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8345 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 8346 | // FIXME: Will we ever have proper type location here? Will we actually |
| 8347 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8348 | QualType T = getDerived().TransformType(E->getType()); |
| 8349 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8350 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8351 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8352 | if (!getDerived().AlwaysRebuild() && |
| 8353 | T == E->getType()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8354 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8355 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8356 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 8357 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8358 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8359 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8360 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8361 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 8362 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 8363 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8364 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8365 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8366 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8367 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8368 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 8371 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8372 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8373 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8374 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8375 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 8376 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8377 | } |
| 8378 | |
| 8379 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8380 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8381 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8382 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8383 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8384 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 8385 | &ArgumentChanged)) |
| 8386 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8387 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8388 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8389 | Inits, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8390 | E->getRParenLoc()); |
| 8391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8392 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8393 | /// \brief Transform an address-of-label expression. |
| 8394 | /// |
| 8395 | /// By default, the transformation of an address-of-label expression always |
| 8396 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 8397 | /// the corresponding label statement by semantic analysis. |
| 8398 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8399 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8400 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 8401 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 8402 | E->getLabel()); |
| 8403 | if (!LD) |
| 8404 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8405 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8406 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 8407 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8408 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8409 | |
| 8410 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8411 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8412 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8413 | SemaRef.ActOnStartStmtExpr(); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8414 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8415 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8416 | if (SubStmt.isInvalid()) { |
| 8417 | SemaRef.ActOnStmtExprError(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8418 | return ExprError(); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8419 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8420 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8421 | if (!getDerived().AlwaysRebuild() && |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8422 | SubStmt.get() == E->getSubStmt()) { |
| 8423 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 8424 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8425 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8427 | |
| 8428 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8429 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8430 | E->getRParenLoc()); |
| 8431 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8432 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8433 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8434 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8435 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8436 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8437 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8438 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8439 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8440 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8441 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8442 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8443 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8444 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8445 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8446 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8447 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8448 | if (!getDerived().AlwaysRebuild() && |
| 8449 | Cond.get() == E->getCond() && |
| 8450 | LHS.get() == E->getLHS() && |
| 8451 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8452 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8453 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8454 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8455 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8456 | E->getRParenLoc()); |
| 8457 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8458 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8459 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8460 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8461 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8462 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8463 | } |
| 8464 | |
| 8465 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8466 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8467 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8468 | switch (E->getOperator()) { |
| 8469 | case OO_New: |
| 8470 | case OO_Delete: |
| 8471 | case OO_Array_New: |
| 8472 | case OO_Array_Delete: |
| 8473 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8474 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8475 | case OO_Call: { |
| 8476 | // This is a call to an object's operator(). |
| 8477 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 8478 | |
| 8479 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8480 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8481 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8482 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8483 | |
| 8484 | // FIXME: Poor location information |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 8485 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| 8486 | static_cast<Expr *>(Object.get())->getLocEnd()); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8487 | |
| 8488 | // Transform the call arguments. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8489 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8490 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8491 | Args)) |
| 8492 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8493 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8494 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8495 | Args, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8496 | E->getLocEnd()); |
| 8497 | } |
| 8498 | |
| 8499 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 8500 | case OO_##Name: |
| 8501 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 8502 | #include "clang/Basic/OperatorKinds.def" |
| 8503 | case OO_Subscript: |
| 8504 | // Handled below. |
| 8505 | break; |
| 8506 | |
| 8507 | case OO_Conditional: |
| 8508 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8509 | |
| 8510 | case OO_None: |
| 8511 | case NUM_OVERLOADED_OPERATORS: |
| 8512 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8513 | } |
| 8514 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8515 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8516 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8517 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8518 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8519 | ExprResult First; |
| 8520 | if (E->getOperator() == OO_Amp) |
| 8521 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 8522 | else |
| 8523 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8524 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8525 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8526 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8527 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8528 | if (E->getNumArgs() == 2) { |
| 8529 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 8530 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8531 | return ExprError(); |
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 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8534 | if (!getDerived().AlwaysRebuild() && |
| 8535 | Callee.get() == E->getCallee() && |
| 8536 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8537 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8538 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8539 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 8540 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 8541 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 8542 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8543 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 8544 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8545 | Callee.get(), |
| 8546 | First.get(), |
| 8547 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8548 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8549 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8550 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8551 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8552 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 8553 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8554 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8555 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8556 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8557 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8558 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 8559 | // Transform the callee. |
| 8560 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 8561 | if (Callee.isInvalid()) |
| 8562 | return ExprError(); |
| 8563 | |
| 8564 | // Transform exec config. |
| 8565 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 8566 | if (EC.isInvalid()) |
| 8567 | return ExprError(); |
| 8568 | |
| 8569 | // Transform arguments. |
| 8570 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8571 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8572 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8573 | &ArgChanged)) |
| 8574 | return ExprError(); |
| 8575 | |
| 8576 | if (!getDerived().AlwaysRebuild() && |
| 8577 | Callee.get() == E->getCallee() && |
| 8578 | !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8579 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8580 | |
| 8581 | // FIXME: Wrong source location information for the '('. |
| 8582 | SourceLocation FakeLParenLoc |
| 8583 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 8584 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8585 | Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8586 | E->getRParenLoc(), EC.get()); |
| 8587 | } |
| 8588 | |
| 8589 | template<typename Derived> |
| 8590 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8591 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8592 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8593 | if (!Type) |
| 8594 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8595 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8596 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8597 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8598 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8599 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8600 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8601 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8602 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8603 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8604 | return E; |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 8605 | return getDerived().RebuildCXXNamedCastExpr( |
| 8606 | E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 8607 | Type, E->getAngleBrackets().getEnd(), |
| 8608 | // FIXME. this should be '(' location |
| 8609 | E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8610 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8611 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8612 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8613 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8614 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 8615 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8616 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8617 | |
| 8618 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8619 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8620 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 8621 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8622 | } |
| 8623 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8624 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8625 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8626 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8627 | CXXReinterpretCastExpr *E) { |
| 8628 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8629 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8630 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8631 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8632 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8633 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 8634 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8636 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8637 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8638 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8639 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8640 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8641 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8642 | if (!Type) |
| 8643 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8644 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8645 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8646 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8647 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8648 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8650 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8651 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8652 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8653 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8654 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8655 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 8656 | E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8657 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8658 | E->getRParenLoc()); |
| 8659 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8660 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8661 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8662 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8663 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8664 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8665 | TypeSourceInfo *TInfo |
| 8666 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 8667 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8668 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8669 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8670 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8671 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8672 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8673 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8674 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 8675 | E->getLocStart(), |
| 8676 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8677 | E->getLocEnd()); |
| 8678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8679 | |
Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 8680 | // We don't know whether the subexpression is potentially evaluated until |
| 8681 | // after we perform semantic analysis. We speculatively assume it is |
| 8682 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8683 | // potentially evaluated. |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 8684 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 8685 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8686 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8687 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8688 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8689 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8690 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8691 | if (!getDerived().AlwaysRebuild() && |
| 8692 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8693 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8694 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8695 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 8696 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8697 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8698 | E->getLocEnd()); |
| 8699 | } |
| 8700 | |
| 8701 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8702 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8703 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 8704 | if (E->isTypeOperand()) { |
| 8705 | TypeSourceInfo *TInfo |
| 8706 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 8707 | if (!TInfo) |
| 8708 | return ExprError(); |
| 8709 | |
| 8710 | if (!getDerived().AlwaysRebuild() && |
| 8711 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8712 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8713 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 8714 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8715 | E->getLocStart(), |
| 8716 | TInfo, |
| 8717 | E->getLocEnd()); |
| 8718 | } |
| 8719 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8720 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8721 | |
| 8722 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 8723 | if (SubExpr.isInvalid()) |
| 8724 | return ExprError(); |
| 8725 | |
| 8726 | if (!getDerived().AlwaysRebuild() && |
| 8727 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8728 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8729 | |
| 8730 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 8731 | E->getLocStart(), |
| 8732 | SubExpr.get(), |
| 8733 | E->getLocEnd()); |
| 8734 | } |
| 8735 | |
| 8736 | template<typename Derived> |
| 8737 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8738 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8739 | return E; |
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 |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8744 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8745 | CXXNullPtrLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8746 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8747 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8748 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8749 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8750 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8751 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 8752 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8753 | |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8754 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 8755 | // Make sure that we capture 'this'. |
| 8756 | getSema().CheckCXXThisCapture(E->getLocStart()); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8757 | return E; |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8758 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8759 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 8760 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8761 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8762 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8763 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8764 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8765 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8766 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8767 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8768 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8769 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8770 | if (!getDerived().AlwaysRebuild() && |
| 8771 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8772 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8773 | |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 8774 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 8775 | E->isThrownVariableInScope()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8776 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8777 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8778 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8779 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8780 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8781 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8782 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8783 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8784 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8785 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8786 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 8787 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8788 | Param == E->getParam()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8789 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8790 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 8791 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8792 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8793 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8794 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8795 | ExprResult |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8796 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 8797 | FieldDecl *Field |
| 8798 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8799 | E->getField())); |
| 8800 | if (!Field) |
| 8801 | return ExprError(); |
| 8802 | |
| 8803 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8804 | return E; |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8805 | |
| 8806 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 8807 | } |
| 8808 | |
| 8809 | template<typename Derived> |
| 8810 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8811 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 8812 | CXXScalarValueInitExpr *E) { |
| 8813 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8814 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8815 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8816 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8817 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8818 | T == E->getTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8819 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8820 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8821 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8822 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 8823 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8824 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8825 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8826 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8827 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8828 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8829 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8830 | TypeSourceInfo *AllocTypeInfo |
| 8831 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 8832 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8833 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8834 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8835 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8836 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8837 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8838 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8839 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8840 | // Transform the placement arguments (if any). |
| 8841 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8842 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8843 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8844 | E->getNumPlacementArgs(), true, |
| 8845 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8846 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8847 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8848 | // Transform the initializer (if any). |
| 8849 | Expr *OldInit = E->getInitializer(); |
| 8850 | ExprResult NewInit; |
| 8851 | if (OldInit) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 8852 | NewInit = getDerived().TransformInitializer(OldInit, true); |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8853 | if (NewInit.isInvalid()) |
| 8854 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8855 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8856 | // Transform new operator and delete operator. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8857 | FunctionDecl *OperatorNew = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8858 | if (E->getOperatorNew()) { |
| 8859 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8860 | getDerived().TransformDecl(E->getLocStart(), |
| 8861 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8862 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8863 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8864 | } |
| 8865 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8866 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8867 | if (E->getOperatorDelete()) { |
| 8868 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8869 | getDerived().TransformDecl(E->getLocStart(), |
| 8870 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8871 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8872 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8873 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8874 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8875 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8876 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8877 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8878 | NewInit.get() == OldInit && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8879 | OperatorNew == E->getOperatorNew() && |
| 8880 | OperatorDelete == E->getOperatorDelete() && |
| 8881 | !ArgumentChanged) { |
| 8882 | // Mark any declarations we need as referenced. |
| 8883 | // FIXME: instantiation-specific. |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8884 | if (OperatorNew) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8885 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8886 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8887 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8888 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8889 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8890 | QualType ElementType |
| 8891 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 8892 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 8893 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 8894 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8895 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8896 | } |
| 8897 | } |
| 8898 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8899 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8900 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8901 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8902 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8903 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8904 | if (!ArraySize.get()) { |
| 8905 | // If no array size was specified, but the new expression was |
| 8906 | // instantiated with an array type (e.g., "new T" where T is |
| 8907 | // instantiated with "int[4]"), extract the outer bound from the |
| 8908 | // array type as our array size. We do this with constant and |
| 8909 | // dependently-sized array types. |
| 8910 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 8911 | if (!ArrayT) { |
| 8912 | // Do nothing |
| 8913 | } else if (const ConstantArrayType *ConsArrayT |
| 8914 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8915 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 8916 | SemaRef.Context.getSizeType(), |
| 8917 | /*FIXME:*/ E->getLocStart()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8918 | AllocType = ConsArrayT->getElementType(); |
| 8919 | } else if (const DependentSizedArrayType *DepArrayT |
| 8920 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 8921 | if (DepArrayT->getSizeExpr()) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8922 | ArraySize = DepArrayT->getSizeExpr(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8923 | AllocType = DepArrayT->getElementType(); |
| 8924 | } |
| 8925 | } |
| 8926 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8928 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 8929 | E->isGlobalNew(), |
| 8930 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8931 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8932 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 8933 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8934 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8935 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8936 | ArraySize.get(), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8937 | E->getDirectInitRange(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8938 | NewInit.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8939 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8940 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8941 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8942 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8943 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8944 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8945 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8946 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8947 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8948 | // Transform the delete operator, if known. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8949 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8950 | if (E->getOperatorDelete()) { |
| 8951 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8952 | getDerived().TransformDecl(E->getLocStart(), |
| 8953 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8954 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8955 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8956 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8957 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8958 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8959 | Operand.get() == E->getArgument() && |
| 8960 | OperatorDelete == E->getOperatorDelete()) { |
| 8961 | // Mark any declarations we need as referenced. |
| 8962 | // FIXME: instantiation-specific. |
| 8963 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8964 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8965 | |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8966 | if (!E->getArgument()->isTypeDependent()) { |
| 8967 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 8968 | E->getDestroyedType()); |
| 8969 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 8970 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8971 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8972 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8973 | } |
| 8974 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8975 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8976 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8977 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8978 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8979 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 8980 | E->isGlobalDelete(), |
| 8981 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8982 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8983 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8984 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8985 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8986 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8987 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8988 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8989 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8990 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8991 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8992 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8993 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8994 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8995 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8996 | E->getOperatorLoc(), |
| 8997 | E->isArrow()? tok::arrow : tok::period, |
| 8998 | ObjectTypePtr, |
| 8999 | MayBePseudoDestructor); |
| 9000 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9001 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9002 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9003 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9004 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 9005 | if (QualifierLoc) { |
| 9006 | QualifierLoc |
| 9007 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 9008 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9009 | return ExprError(); |
| 9010 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9011 | CXXScopeSpec SS; |
| 9012 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9013 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9014 | PseudoDestructorTypeStorage Destroyed; |
| 9015 | if (E->getDestroyedTypeInfo()) { |
| 9016 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9017 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9018 | ObjectType, nullptr, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9019 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9020 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9021 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 9022 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9023 | // We aren't likely to be able to resolve the identifier down to a type |
| 9024 | // now anyway, so just retain the identifier. |
| 9025 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 9026 | E->getDestroyedTypeLoc()); |
| 9027 | } else { |
| 9028 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9029 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9030 | *E->getDestroyedTypeIdentifier(), |
| 9031 | E->getDestroyedTypeLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9032 | /*Scope=*/nullptr, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9033 | SS, ObjectTypePtr, |
| 9034 | false); |
| 9035 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9036 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9037 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9038 | Destroyed |
| 9039 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 9040 | E->getDestroyedTypeLoc()); |
| 9041 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9042 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9043 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9044 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 9045 | CXXScopeSpec EmptySS; |
| 9046 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9047 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9048 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9049 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9050 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9051 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9052 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9053 | E->getOperatorLoc(), |
| 9054 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9055 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9056 | ScopeTypeInfo, |
| 9057 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9058 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9059 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9060 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9061 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9062 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9063 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9064 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9065 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9066 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 9067 | Sema::LookupOrdinaryName); |
| 9068 | |
| 9069 | // Transform all the decls. |
| 9070 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 9071 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9072 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 9073 | getDerived().TransformDecl(Old->getNameLoc(), |
| 9074 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9075 | if (!InstD) { |
| 9076 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 9077 | // This can happen because of dependent hiding. |
| 9078 | if (isa<UsingShadowDecl>(*I)) |
| 9079 | continue; |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9080 | else { |
| 9081 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9082 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9083 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9084 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9085 | |
| 9086 | // Expand using declarations. |
| 9087 | if (isa<UsingDecl>(InstD)) { |
| 9088 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 9089 | for (auto *I : UD->shadows()) |
| 9090 | R.addDecl(I); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9091 | continue; |
| 9092 | } |
| 9093 | |
| 9094 | R.addDecl(InstD); |
| 9095 | } |
| 9096 | |
| 9097 | // Resolve a kind, but don't do any further analysis. If it's |
| 9098 | // ambiguous, the callee needs to deal with it. |
| 9099 | R.resolveKind(); |
| 9100 | |
| 9101 | // Rebuild the nested-name qualifier, if present. |
| 9102 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9103 | if (Old->getQualifierLoc()) { |
| 9104 | NestedNameSpecifierLoc QualifierLoc |
| 9105 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 9106 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9107 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9108 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9109 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9110 | } |
| 9111 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9112 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9113 | CXXRecordDecl *NamingClass |
| 9114 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 9115 | Old->getNameLoc(), |
| 9116 | Old->getNamingClass())); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9117 | if (!NamingClass) { |
| 9118 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9119 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9120 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9121 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9122 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9123 | } |
| 9124 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9125 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 9126 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 9127 | // If we have neither explicit template arguments, nor the template keyword, |
Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 9128 | // it's a normal declaration name or member reference. |
| 9129 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { |
| 9130 | NamedDecl *D = R.getAsSingle<NamedDecl>(); |
| 9131 | // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an |
| 9132 | // instance member. In other contexts, BuildPossibleImplicitMemberExpr will |
| 9133 | // give a good diagnostic. |
| 9134 | if (D && D->isCXXInstanceMember()) { |
| 9135 | return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, |
| 9136 | /*TemplateArgs=*/nullptr, |
| 9137 | /*Scope=*/nullptr); |
| 9138 | } |
| 9139 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9140 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 9141 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9142 | |
| 9143 | // If we have template arguments, rebuild them, then rebuild the |
| 9144 | // templateid expression. |
| 9145 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 9146 | if (Old->hasExplicitTemplateArgs() && |
| 9147 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9148 | Old->getNumTemplateArgs(), |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9149 | TransArgs)) { |
| 9150 | R.clear(); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9151 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9152 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9153 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9154 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 9155 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9156 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9158 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9159 | ExprResult |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9160 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 9161 | bool ArgChanged = false; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9162 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9163 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 9164 | TypeSourceInfo *From = E->getArg(I); |
| 9165 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 9166 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9167 | TypeLocBuilder TLB; |
| 9168 | TLB.reserve(FromTL.getFullDataSize()); |
| 9169 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 9170 | if (To.isNull()) |
| 9171 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9172 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9173 | if (To == From->getType()) |
| 9174 | Args.push_back(From); |
| 9175 | else { |
| 9176 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9177 | ArgChanged = true; |
| 9178 | } |
| 9179 | continue; |
| 9180 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9181 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9182 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9183 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9184 | // We have a pack expansion. Instantiate it. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 9185 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9186 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 9187 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 9188 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9189 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9190 | // Determine whether the set of unexpanded parameter packs can and should |
| 9191 | // be expanded. |
| 9192 | bool Expand = true; |
| 9193 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9194 | Optional<unsigned> OrigNumExpansions = |
| 9195 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 9196 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9197 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 9198 | PatternTL.getSourceRange(), |
| 9199 | Unexpanded, |
| 9200 | Expand, RetainExpansion, |
| 9201 | NumExpansions)) |
| 9202 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9203 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9204 | if (!Expand) { |
| 9205 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9206 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9207 | // expansion. |
| 9208 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9209 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9210 | TypeLocBuilder TLB; |
| 9211 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 9212 | |
| 9213 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9214 | if (To.isNull()) |
| 9215 | return ExprError(); |
| 9216 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9217 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9218 | PatternTL.getSourceRange(), |
| 9219 | ExpansionTL.getEllipsisLoc(), |
| 9220 | NumExpansions); |
| 9221 | if (To.isNull()) |
| 9222 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9223 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9224 | PackExpansionTypeLoc ToExpansionTL |
| 9225 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9226 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9227 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9228 | continue; |
| 9229 | } |
| 9230 | |
| 9231 | // Expand the pack expansion by substituting for each argument in the |
| 9232 | // pack(s). |
| 9233 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9234 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 9235 | TypeLocBuilder TLB; |
| 9236 | TLB.reserve(PatternTL.getFullDataSize()); |
| 9237 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9238 | if (To.isNull()) |
| 9239 | return ExprError(); |
| 9240 | |
Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 9241 | if (To->containsUnexpandedParameterPack()) { |
| 9242 | To = getDerived().RebuildPackExpansionType(To, |
| 9243 | PatternTL.getSourceRange(), |
| 9244 | ExpansionTL.getEllipsisLoc(), |
| 9245 | NumExpansions); |
| 9246 | if (To.isNull()) |
| 9247 | return ExprError(); |
| 9248 | |
| 9249 | PackExpansionTypeLoc ToExpansionTL |
| 9250 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9251 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9252 | } |
| 9253 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9254 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9255 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9256 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9257 | if (!RetainExpansion) |
| 9258 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9259 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9260 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 9261 | // forgetting the partially-substituted parameter pack. |
| 9262 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 9263 | |
| 9264 | TypeLocBuilder TLB; |
| 9265 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9266 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9267 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9268 | if (To.isNull()) |
| 9269 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9270 | |
| 9271 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9272 | PatternTL.getSourceRange(), |
| 9273 | ExpansionTL.getEllipsisLoc(), |
| 9274 | NumExpansions); |
| 9275 | if (To.isNull()) |
| 9276 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9277 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9278 | PackExpansionTypeLoc ToExpansionTL |
| 9279 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9280 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9281 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9282 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9283 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9284 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9285 | return E; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9286 | |
| 9287 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 9288 | E->getLocStart(), |
| 9289 | Args, |
| 9290 | E->getLocEnd()); |
| 9291 | } |
| 9292 | |
| 9293 | template<typename Derived> |
| 9294 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9295 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 9296 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 9297 | if (!T) |
| 9298 | return ExprError(); |
| 9299 | |
| 9300 | if (!getDerived().AlwaysRebuild() && |
| 9301 | T == E->getQueriedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9302 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9303 | |
| 9304 | ExprResult SubExpr; |
| 9305 | { |
| 9306 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 9307 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 9308 | if (SubExpr.isInvalid()) |
| 9309 | return ExprError(); |
| 9310 | |
| 9311 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9312 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9313 | } |
| 9314 | |
| 9315 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 9316 | E->getLocStart(), |
| 9317 | T, |
| 9318 | SubExpr.get(), |
| 9319 | E->getLocEnd()); |
| 9320 | } |
| 9321 | |
| 9322 | template<typename Derived> |
| 9323 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 9324 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 9325 | ExprResult SubExpr; |
| 9326 | { |
| 9327 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 9328 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 9329 | if (SubExpr.isInvalid()) |
| 9330 | return ExprError(); |
| 9331 | |
| 9332 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9333 | return E; |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 9334 | } |
| 9335 | |
| 9336 | return getDerived().RebuildExpressionTrait( |
| 9337 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 9338 | } |
| 9339 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9340 | template <typename Derived> |
| 9341 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 9342 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 9343 | TypeSourceInfo **RecoveryTSI) { |
| 9344 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 9345 | DRE, AddrTaken, RecoveryTSI); |
| 9346 | |
| 9347 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 9348 | if (!NewDRE.isUsable()) |
| 9349 | return NewDRE; |
| 9350 | |
| 9351 | // We got an expr, wrap it up in parens. |
| 9352 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 9353 | return PE; |
| 9354 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 9355 | PE->getRParen()); |
| 9356 | } |
| 9357 | |
| 9358 | template <typename Derived> |
| 9359 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 9360 | DependentScopeDeclRefExpr *E) { |
| 9361 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 9362 | nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9363 | } |
| 9364 | |
| 9365 | template<typename Derived> |
| 9366 | ExprResult |
| 9367 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 9368 | DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9369 | bool IsAddressOfOperand, |
| 9370 | TypeSourceInfo **RecoveryTSI) { |
Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 9371 | assert(E->getQualifierLoc()); |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 9372 | NestedNameSpecifierLoc QualifierLoc |
| 9373 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 9374 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9375 | return ExprError(); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9376 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9377 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9378 | // TODO: If this is a conversion-function-id, verify that the |
| 9379 | // destination type name (if present) resolves the same way after |
| 9380 | // instantiation as it did in the local scope. |
| 9381 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9382 | DeclarationNameInfo NameInfo |
| 9383 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 9384 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9385 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9386 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9387 | if (!E->hasExplicitTemplateArgs()) { |
| 9388 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 9389 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9390 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 9391 | // if name has not changed, DNLoc has not changed either. |
| 9392 | NameInfo.getName() == E->getDeclName()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9393 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9394 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9395 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 9396 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 9397 | IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 9398 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9399 | |
| 9400 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9401 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9402 | E->getNumTemplateArgs(), |
| 9403 | TransArgs)) |
| 9404 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9405 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9406 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 9407 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 9408 | RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9409 | } |
| 9410 | |
| 9411 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9412 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9413 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9414 | // CXXConstructExprs other than for list-initialization and |
| 9415 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 9416 | // a 1-argument construction we just transform that argument. |
Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 9417 | if ((E->getNumArgs() == 1 || |
| 9418 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9419 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 9420 | !E->isListInitialization()) |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 9421 | return getDerived().TransformExpr(E->getArg(0)); |
| 9422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9423 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 9424 | |
| 9425 | QualType T = getDerived().TransformType(E->getType()); |
| 9426 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9427 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9428 | |
| 9429 | CXXConstructorDecl *Constructor |
| 9430 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9431 | getDerived().TransformDecl(E->getLocStart(), |
| 9432 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9433 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9434 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9435 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9436 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9437 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9438 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9439 | &ArgumentChanged)) |
| 9440 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9441 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9442 | if (!getDerived().AlwaysRebuild() && |
| 9443 | T == E->getType() && |
| 9444 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 9445 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9446 | // Mark the constructor as referenced. |
| 9447 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9448 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9449 | return E; |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 9450 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9451 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 9452 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 9453 | Constructor, E->isElidable(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9454 | Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 9455 | E->hadMultipleCandidates(), |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9456 | E->isListInitialization(), |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 9457 | E->isStdInitListInitialization(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 9458 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 9459 | E->getConstructionKind(), |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 9460 | E->getParenOrBraceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9461 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9462 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9463 | /// \brief Transform a C++ temporary-binding expression. |
| 9464 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9465 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 9466 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9467 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9468 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9469 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9470 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9471 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9472 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 9473 | /// \brief Transform a C++ expression that contains cleanups that should |
| 9474 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9475 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 9476 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9477 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9478 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9479 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 9480 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9481 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9482 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9483 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9484 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9485 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9486 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9487 | CXXTemporaryObjectExpr *E) { |
| 9488 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9489 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9490 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9491 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9492 | CXXConstructorDecl *Constructor |
| 9493 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9494 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9495 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9496 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9497 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9498 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9499 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9500 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9501 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9502 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9503 | &ArgumentChanged)) |
| 9504 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9505 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9506 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9507 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9508 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 9509 | !ArgumentChanged) { |
| 9510 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9511 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9512 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 9513 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9514 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9515 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9516 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 9517 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9518 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9519 | E->getLocEnd()); |
| 9520 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9521 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9522 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9523 | ExprResult |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 9524 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9525 | // Transform any init-capture expressions before entering the scope of the |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9526 | // lambda body, because they are not semantically within that scope. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9527 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9528 | SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes; |
| 9529 | InitCaptureExprsAndTypes.resize(E->explicit_capture_end() - |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9530 | E->explicit_capture_begin()); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9531 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9532 | CEnd = E->capture_end(); |
| 9533 | C != CEnd; ++C) { |
James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 9534 | if (!E->isInitCapture(C)) |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9535 | continue; |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9536 | EnterExpressionEvaluationContext EEEC(getSema(), |
| 9537 | Sema::PotentiallyEvaluated); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9538 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 9539 | C->getCapturedVar()->getInit(), |
| 9540 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9541 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9542 | if (NewExprInitResult.isInvalid()) |
| 9543 | return ExprError(); |
| 9544 | Expr *NewExprInit = NewExprInitResult.get(); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9545 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9546 | VarDecl *OldVD = C->getCapturedVar(); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9547 | QualType NewInitCaptureType = |
| 9548 | getSema().performLambdaInitCaptureInitialization(C->getLocation(), |
| 9549 | OldVD->getType()->isReferenceType(), OldVD->getIdentifier(), |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9550 | NewExprInit); |
| 9551 | NewExprInitResult = NewExprInit; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9552 | InitCaptureExprsAndTypes[C - E->capture_begin()] = |
| 9553 | std::make_pair(NewExprInitResult, NewInitCaptureType); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9554 | } |
| 9555 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9556 | // Transform the template parameters, and add them to the current |
| 9557 | // instantiation scope. The null case is handled correctly. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9558 | auto TPL = getDerived().TransformTemplateParameterList( |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9559 | E->getTemplateParameterList()); |
| 9560 | |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9561 | // Transform the type of the original lambda's call operator. |
| 9562 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 9563 | // it introduces a mapping of the original to the newly created |
| 9564 | // transformed parameters. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9565 | TypeSourceInfo *NewCallOpTSI = nullptr; |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9566 | { |
| 9567 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 9568 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 9569 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9570 | |
| 9571 | TypeLocBuilder NewCallOpTLBuilder; |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 9572 | SmallVector<QualType, 4> ExceptionStorage; |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 9573 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 9574 | QualType NewCallOpType = TransformFunctionProtoType( |
| 9575 | NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0, |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 9576 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 9577 | return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, |
| 9578 | ExceptionStorage, Changed); |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 9579 | }); |
Reid Kleckner | aac43c6 | 2014-12-15 21:07:16 +0000 | [diff] [blame] | 9580 | if (NewCallOpType.isNull()) |
| 9581 | return ExprError(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9582 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 9583 | NewCallOpType); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 9584 | } |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9585 | |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9586 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
| 9587 | Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); |
| 9588 | LSI->GLTemplateParameterList = TPL; |
| 9589 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 9590 | // Create the local class that will describe the lambda. |
| 9591 | CXXRecordDecl *Class |
| 9592 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9593 | NewCallOpTSI, |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 9594 | /*KnownDependent=*/false, |
| 9595 | E->getCaptureDefault()); |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 9596 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 9597 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9598 | // Build the call operator. |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 9599 | CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition( |
| 9600 | Class, E->getIntroducerRange(), NewCallOpTSI, |
| 9601 | E->getCallOperator()->getLocEnd(), |
| 9602 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams()); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9603 | LSI->CallOperator = NewCallOperator; |
Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 9604 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9605 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9606 | getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9607 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9608 | // Introduce the context of the call operator. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9609 | Sema::ContextRAII SavedContext(getSema(), NewCallOperator, |
Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 9610 | /*NewThisContext*/false); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9611 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9612 | // Enter the scope of the lambda. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9613 | getSema().buildLambdaScope(LSI, NewCallOperator, |
| 9614 | E->getIntroducerRange(), |
| 9615 | E->getCaptureDefault(), |
| 9616 | E->getCaptureDefaultLoc(), |
| 9617 | E->hasExplicitParameters(), |
| 9618 | E->hasExplicitResultType(), |
| 9619 | E->isMutable()); |
| 9620 | |
| 9621 | bool Invalid = false; |
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 captures. |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9624 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9625 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9626 | CEnd = E->capture_end(); |
| 9627 | C != CEnd; ++C) { |
| 9628 | // When we hit the first implicit capture, tell Sema that we've finished |
| 9629 | // the list of explicit captures. |
| 9630 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 9631 | getSema().finishLambdaExplicitCaptures(LSI); |
| 9632 | FinishedExplicitCaptures = true; |
| 9633 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9634 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9635 | // Capturing 'this' is trivial. |
| 9636 | if (C->capturesThis()) { |
| 9637 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 9638 | continue; |
| 9639 | } |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 9640 | // Captured expression will be recaptured during captured variables |
| 9641 | // rebuilding. |
| 9642 | if (C->capturesVLAType()) |
| 9643 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9644 | |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9645 | // Rebuild init-captures, including the implied field declaration. |
James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 9646 | if (E->isInitCapture(C)) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9647 | InitCaptureInfoTy InitExprTypePair = |
| 9648 | InitCaptureExprsAndTypes[C - E->capture_begin()]; |
| 9649 | ExprResult Init = InitExprTypePair.first; |
| 9650 | QualType InitQualType = InitExprTypePair.second; |
| 9651 | if (Init.isInvalid() || InitQualType.isNull()) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9652 | Invalid = true; |
| 9653 | continue; |
| 9654 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9655 | VarDecl *OldVD = C->getCapturedVar(); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9656 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 9657 | OldVD->getLocation(), InitExprTypePair.second, |
| 9658 | OldVD->getIdentifier(), Init.get()); |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9659 | if (!NewVD) |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9660 | Invalid = true; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9661 | else { |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9662 | getDerived().transformedLocalDecl(OldVD, NewVD); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9663 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9664 | getSema().buildInitCaptureField(LSI, NewVD); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9665 | continue; |
| 9666 | } |
| 9667 | |
| 9668 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 9669 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9670 | // Determine the capture kind for Sema. |
| 9671 | Sema::TryCaptureKind Kind |
| 9672 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 9673 | : C->getCaptureKind() == LCK_ByCopy |
| 9674 | ? Sema::TryCapture_ExplicitByVal |
| 9675 | : Sema::TryCapture_ExplicitByRef; |
| 9676 | SourceLocation EllipsisLoc; |
| 9677 | if (C->isPackExpansion()) { |
| 9678 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 9679 | bool ShouldExpand = false; |
| 9680 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9681 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9682 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 9683 | C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9684 | Unexpanded, |
| 9685 | ShouldExpand, RetainExpansion, |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9686 | NumExpansions)) { |
| 9687 | Invalid = true; |
| 9688 | continue; |
| 9689 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9690 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9691 | if (ShouldExpand) { |
| 9692 | // The transform has determined that we should perform an expansion; |
| 9693 | // transform and capture each of the arguments. |
| 9694 | // expansion of the pattern. Do so. |
| 9695 | VarDecl *Pack = C->getCapturedVar(); |
| 9696 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9697 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 9698 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9699 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9700 | Pack)); |
| 9701 | if (!CapturedVar) { |
| 9702 | Invalid = true; |
| 9703 | continue; |
| 9704 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9705 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9706 | // Capture the transformed variable. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9707 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 9708 | } |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9709 | |
| 9710 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 9711 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9712 | continue; |
| 9713 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9714 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9715 | EllipsisLoc = C->getEllipsisLoc(); |
| 9716 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9717 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9718 | // Transform the captured variable. |
| 9719 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9720 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9721 | C->getCapturedVar())); |
Richard Trieu | b292604 | 2014-09-02 19:32:44 +0000 | [diff] [blame] | 9722 | if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9723 | Invalid = true; |
| 9724 | continue; |
| 9725 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9726 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9727 | // Capture the transformed variable. |
Meador Inge | 4f9dee7 | 2015-06-26 00:09:55 +0000 | [diff] [blame] | 9728 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, |
| 9729 | EllipsisLoc); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9730 | } |
| 9731 | if (!FinishedExplicitCaptures) |
| 9732 | getSema().finishLambdaExplicitCaptures(LSI); |
| 9733 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9734 | // Enter a new evaluation context to insulate the lambda from any |
| 9735 | // cleanups from the enclosing full-expression. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9736 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9737 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9738 | // Instantiate the body of the lambda expression. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9739 | StmtResult Body = |
| 9740 | Invalid ? StmtError() : getDerived().TransformStmt(E->getBody()); |
| 9741 | |
| 9742 | // ActOnLambda* will pop the function scope for us. |
| 9743 | FuncScopeCleanup.disable(); |
| 9744 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9745 | if (Body.isInvalid()) { |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9746 | SavedContext.pop(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9747 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9748 | /*IsInstantiation=*/true); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9749 | return ExprError(); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9750 | } |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 9751 | |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 9752 | // Copy the LSI before ActOnFinishFunctionBody removes it. |
| 9753 | // FIXME: This is dumb. Store the lambda information somewhere that outlives |
| 9754 | // the call operator. |
| 9755 | auto LSICopy = *LSI; |
| 9756 | getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), |
| 9757 | /*IsInstantiation*/ true); |
| 9758 | SavedContext.pop(); |
| 9759 | |
| 9760 | return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(), |
| 9761 | &LSICopy); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 9762 | } |
| 9763 | |
| 9764 | template<typename Derived> |
| 9765 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9766 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9767 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9768 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9769 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9770 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9771 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9772 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9773 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9774 | Args.reserve(E->arg_size()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9775 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9776 | &ArgumentChanged)) |
| 9777 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9778 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9779 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9780 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9781 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9782 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9784 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9785 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9786 | E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9787 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9788 | E->getRParenLoc()); |
| 9789 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9790 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9791 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9792 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 9793 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9794 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9795 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9796 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9797 | Expr *OldBase; |
| 9798 | QualType BaseType; |
| 9799 | QualType ObjectType; |
| 9800 | if (!E->isImplicitAccess()) { |
| 9801 | OldBase = E->getBase(); |
| 9802 | Base = getDerived().TransformExpr(OldBase); |
| 9803 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9804 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9805 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9806 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9807 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9808 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9809 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9810 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9811 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9812 | ObjectTy, |
| 9813 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9814 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9815 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9816 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9817 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9818 | BaseType = ((Expr*) Base.get())->getType(); |
| 9819 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9820 | OldBase = nullptr; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9821 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 9822 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 9823 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9824 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9825 | // Transform the first part of the nested-name-specifier that qualifies |
| 9826 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 9827 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9828 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9829 | E->getFirstQualifierFoundInScope(), |
| 9830 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9831 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9832 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9833 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9834 | QualifierLoc |
| 9835 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 9836 | ObjectType, |
| 9837 | FirstQualifierInScope); |
| 9838 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9839 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9840 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9841 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9842 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 9843 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9844 | // TODO: If this is a conversion-function-id, verify that the |
| 9845 | // destination type name (if present) resolves the same way after |
| 9846 | // instantiation as it did in the local scope. |
| 9847 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9848 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9849 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9850 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9851 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9852 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9853 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9854 | // This is a reference to a member without an explicitly-specified |
| 9855 | // template argument list. Optimize for this common case. |
| 9856 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9857 | Base.get() == OldBase && |
| 9858 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9859 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9860 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9861 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9862 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9863 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9864 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9865 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9866 | E->isArrow(), |
| 9867 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9868 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9869 | TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9870 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9871 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9872 | /*TemplateArgs*/nullptr); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9873 | } |
| 9874 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9875 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9876 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9877 | E->getNumTemplateArgs(), |
| 9878 | TransArgs)) |
| 9879 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9880 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9881 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9882 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9883 | E->isArrow(), |
| 9884 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9885 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9886 | TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9887 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9888 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9889 | &TransArgs); |
| 9890 | } |
| 9891 | |
| 9892 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9893 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9894 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9895 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9896 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9897 | QualType BaseType; |
| 9898 | if (!Old->isImplicitAccess()) { |
| 9899 | Base = getDerived().TransformExpr(Old->getBase()); |
| 9900 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9901 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9902 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 9903 | Old->isArrow()); |
| 9904 | if (Base.isInvalid()) |
| 9905 | return ExprError(); |
| 9906 | BaseType = Base.get()->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9907 | } else { |
| 9908 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 9909 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9910 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9911 | NestedNameSpecifierLoc QualifierLoc; |
| 9912 | if (Old->getQualifierLoc()) { |
| 9913 | QualifierLoc |
| 9914 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 9915 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9916 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9917 | } |
| 9918 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9919 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 9920 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9921 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9922 | Sema::LookupOrdinaryName); |
| 9923 | |
| 9924 | // Transform all the decls. |
| 9925 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 9926 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9927 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 9928 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 9929 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9930 | if (!InstD) { |
| 9931 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 9932 | // This can happen because of dependent hiding. |
| 9933 | if (isa<UsingShadowDecl>(*I)) |
| 9934 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9935 | else { |
| 9936 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9937 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9938 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9939 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9940 | |
| 9941 | // Expand using declarations. |
| 9942 | if (isa<UsingDecl>(InstD)) { |
| 9943 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 9944 | for (auto *I : UD->shadows()) |
| 9945 | R.addDecl(I); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9946 | continue; |
| 9947 | } |
| 9948 | |
| 9949 | R.addDecl(InstD); |
| 9950 | } |
| 9951 | |
| 9952 | R.resolveKind(); |
| 9953 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9954 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 9955 | if (Old->getNamingClass()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9956 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9957 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9958 | Old->getMemberLoc(), |
| 9959 | Old->getNamingClass())); |
| 9960 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9961 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9962 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9963 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9964 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9965 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9966 | TemplateArgumentListInfo TransArgs; |
| 9967 | if (Old->hasExplicitTemplateArgs()) { |
| 9968 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 9969 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9970 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 9971 | Old->getNumTemplateArgs(), |
| 9972 | TransArgs)) |
| 9973 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9974 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9975 | |
| 9976 | // FIXME: to do this check properly, we will need to preserve the |
| 9977 | // first-qualifier-in-scope here, just in case we had a dependent |
| 9978 | // base (and therefore couldn't do the check) and a |
| 9979 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9980 | NamedDecl *FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9981 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9982 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9983 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9984 | Old->getOperatorLoc(), |
| 9985 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9986 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9987 | TemplateKWLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9988 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9989 | R, |
| 9990 | (Old->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9991 | ? &TransArgs : nullptr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9992 | } |
| 9993 | |
| 9994 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9995 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9996 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Alexis Hunt | 414e3e3 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 9997 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9998 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 9999 | if (SubExpr.isInvalid()) |
| 10000 | return ExprError(); |
| 10001 | |
| 10002 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10003 | return E; |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 10004 | |
| 10005 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 10006 | } |
| 10007 | |
| 10008 | template<typename Derived> |
| 10009 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 10010 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 10011 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 10012 | if (Pattern.isInvalid()) |
| 10013 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10014 | |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 10015 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10016 | return E; |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 10017 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 10018 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 10019 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 10020 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 10021 | |
| 10022 | template<typename Derived> |
| 10023 | ExprResult |
| 10024 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 10025 | // If E is not value-dependent, then nothing will change when we transform it. |
| 10026 | // Note: This is an instantiation-centric view. |
| 10027 | if (!E->isValueDependent()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10028 | return E; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 10029 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10030 | EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10031 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10032 | ArrayRef<TemplateArgument> PackArgs; |
| 10033 | TemplateArgument ArgStorage; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10034 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10035 | // Find the argument list to transform. |
| 10036 | if (E->isPartiallySubstituted()) { |
| 10037 | PackArgs = E->getPartialArguments(); |
| 10038 | } else if (E->isValueDependent()) { |
| 10039 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 10040 | bool ShouldExpand = false; |
| 10041 | bool RetainExpansion = false; |
| 10042 | Optional<unsigned> NumExpansions; |
| 10043 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 10044 | Unexpanded, |
| 10045 | ShouldExpand, RetainExpansion, |
| 10046 | NumExpansions)) |
| 10047 | return ExprError(); |
| 10048 | |
| 10049 | // If we need to expand the pack, build a template argument from it and |
| 10050 | // expand that. |
| 10051 | if (ShouldExpand) { |
| 10052 | auto *Pack = E->getPack(); |
| 10053 | if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { |
| 10054 | ArgStorage = getSema().Context.getPackExpansionType( |
| 10055 | getSema().Context.getTypeDeclType(TTPD), None); |
| 10056 | } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { |
| 10057 | ArgStorage = TemplateArgument(TemplateName(TTPD), None); |
| 10058 | } else { |
| 10059 | auto *VD = cast<ValueDecl>(Pack); |
| 10060 | ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(), |
| 10061 | VK_RValue, E->getPackLoc()); |
| 10062 | if (DRE.isInvalid()) |
| 10063 | return ExprError(); |
| 10064 | ArgStorage = new (getSema().Context) PackExpansionExpr( |
| 10065 | getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None); |
| 10066 | } |
| 10067 | PackArgs = ArgStorage; |
| 10068 | } |
| 10069 | } |
| 10070 | |
| 10071 | // If we're not expanding the pack, just transform the decl. |
| 10072 | if (!PackArgs.size()) { |
| 10073 | auto *Pack = cast_or_null<NamedDecl>( |
| 10074 | getDerived().TransformDecl(E->getPackLoc(), E->getPack())); |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 10075 | if (!Pack) |
| 10076 | return ExprError(); |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10077 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 10078 | E->getPackLoc(), |
| 10079 | E->getRParenLoc(), None, None); |
| 10080 | } |
| 10081 | |
| 10082 | TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), |
| 10083 | E->getPackLoc()); |
| 10084 | { |
| 10085 | TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); |
| 10086 | typedef TemplateArgumentLocInventIterator< |
| 10087 | Derived, const TemplateArgument*> PackLocIterator; |
| 10088 | if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), |
| 10089 | PackLocIterator(*this, PackArgs.end()), |
| 10090 | TransformedPackArgs, /*Uneval*/true)) |
| 10091 | return ExprError(); |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 10092 | } |
| 10093 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10094 | SmallVector<TemplateArgument, 8> Args; |
| 10095 | bool PartialSubstitution = false; |
| 10096 | for (auto &Loc : TransformedPackArgs.arguments()) { |
| 10097 | Args.push_back(Loc.getArgument()); |
| 10098 | if (Loc.getArgument().isPackExpansion()) |
| 10099 | PartialSubstitution = true; |
| 10100 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10101 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10102 | if (PartialSubstitution) |
| 10103 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 10104 | E->getPackLoc(), |
| 10105 | E->getRParenLoc(), None, Args); |
| 10106 | |
| 10107 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10108 | E->getPackLoc(), E->getRParenLoc(), |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10109 | Args.size(), None); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 10110 | } |
| 10111 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 10112 | template<typename Derived> |
| 10113 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 10114 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 10115 | SubstNonTypeTemplateParmPackExpr *E) { |
| 10116 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10117 | return E; |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 10118 | } |
| 10119 | |
| 10120 | template<typename Derived> |
| 10121 | ExprResult |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 10122 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 10123 | SubstNonTypeTemplateParmExpr *E) { |
| 10124 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10125 | return E; |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 10126 | } |
| 10127 | |
| 10128 | template<typename Derived> |
| 10129 | ExprResult |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 10130 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 10131 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10132 | return E; |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 10133 | } |
| 10134 | |
| 10135 | template<typename Derived> |
| 10136 | ExprResult |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 10137 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 10138 | MaterializeTemporaryExpr *E) { |
| 10139 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 10140 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10141 | |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 10142 | template<typename Derived> |
| 10143 | ExprResult |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 10144 | TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { |
| 10145 | Expr *Pattern = E->getPattern(); |
| 10146 | |
| 10147 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10148 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 10149 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 10150 | |
| 10151 | // Determine whether the set of unexpanded parameter packs can and should |
| 10152 | // be expanded. |
| 10153 | bool Expand = true; |
| 10154 | bool RetainExpansion = false; |
| 10155 | Optional<unsigned> NumExpansions; |
| 10156 | if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), |
| 10157 | Pattern->getSourceRange(), |
| 10158 | Unexpanded, |
| 10159 | Expand, RetainExpansion, |
| 10160 | NumExpansions)) |
| 10161 | return true; |
| 10162 | |
| 10163 | if (!Expand) { |
| 10164 | // Do not expand any packs here, just transform and rebuild a fold |
| 10165 | // expression. |
| 10166 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 10167 | |
| 10168 | ExprResult LHS = |
| 10169 | E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); |
| 10170 | if (LHS.isInvalid()) |
| 10171 | return true; |
| 10172 | |
| 10173 | ExprResult RHS = |
| 10174 | E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); |
| 10175 | if (RHS.isInvalid()) |
| 10176 | return true; |
| 10177 | |
| 10178 | if (!getDerived().AlwaysRebuild() && |
| 10179 | LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) |
| 10180 | return E; |
| 10181 | |
| 10182 | return getDerived().RebuildCXXFoldExpr( |
| 10183 | E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(), |
| 10184 | RHS.get(), E->getLocEnd()); |
| 10185 | } |
| 10186 | |
| 10187 | // The transform has determined that we should perform an elementwise |
| 10188 | // expansion of the pattern. Do so. |
| 10189 | ExprResult Result = getDerived().TransformExpr(E->getInit()); |
| 10190 | if (Result.isInvalid()) |
| 10191 | return true; |
| 10192 | bool LeftFold = E->isLeftFold(); |
| 10193 | |
| 10194 | // If we're retaining an expansion for a right fold, it is the innermost |
| 10195 | // component and takes the init (if any). |
| 10196 | if (!LeftFold && RetainExpansion) { |
| 10197 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10198 | |
| 10199 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10200 | if (Out.isInvalid()) |
| 10201 | return true; |
| 10202 | |
| 10203 | Result = getDerived().RebuildCXXFoldExpr( |
| 10204 | E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(), |
| 10205 | Result.get(), E->getLocEnd()); |
| 10206 | if (Result.isInvalid()) |
| 10207 | return true; |
| 10208 | } |
| 10209 | |
| 10210 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10211 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( |
| 10212 | getSema(), LeftFold ? I : *NumExpansions - I - 1); |
| 10213 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10214 | if (Out.isInvalid()) |
| 10215 | return true; |
| 10216 | |
| 10217 | if (Out.get()->containsUnexpandedParameterPack()) { |
| 10218 | // We still have a pack; retain a pack expansion for this slice. |
| 10219 | Result = getDerived().RebuildCXXFoldExpr( |
| 10220 | E->getLocStart(), |
| 10221 | LeftFold ? Result.get() : Out.get(), |
| 10222 | E->getOperator(), E->getEllipsisLoc(), |
| 10223 | LeftFold ? Out.get() : Result.get(), |
| 10224 | E->getLocEnd()); |
| 10225 | } else if (Result.isUsable()) { |
| 10226 | // We've got down to a single element; build a binary operator. |
| 10227 | Result = getDerived().RebuildBinaryOperator( |
| 10228 | E->getEllipsisLoc(), E->getOperator(), |
| 10229 | LeftFold ? Result.get() : Out.get(), |
| 10230 | LeftFold ? Out.get() : Result.get()); |
| 10231 | } else |
| 10232 | Result = Out; |
| 10233 | |
| 10234 | if (Result.isInvalid()) |
| 10235 | return true; |
| 10236 | } |
| 10237 | |
| 10238 | // If we're retaining an expansion for a left fold, it is the outermost |
| 10239 | // component and takes the complete expansion so far as its init (if any). |
| 10240 | if (LeftFold && RetainExpansion) { |
| 10241 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10242 | |
| 10243 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10244 | if (Out.isInvalid()) |
| 10245 | return true; |
| 10246 | |
| 10247 | Result = getDerived().RebuildCXXFoldExpr( |
| 10248 | E->getLocStart(), Result.get(), |
| 10249 | E->getOperator(), E->getEllipsisLoc(), |
| 10250 | Out.get(), E->getLocEnd()); |
| 10251 | if (Result.isInvalid()) |
| 10252 | return true; |
| 10253 | } |
| 10254 | |
| 10255 | // If we had no init and an empty pack, and we're not retaining an expansion, |
| 10256 | // then produce a fallback value or error. |
| 10257 | if (Result.isUnset()) |
| 10258 | return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), |
| 10259 | E->getOperator()); |
| 10260 | |
| 10261 | return Result; |
| 10262 | } |
| 10263 | |
| 10264 | template<typename Derived> |
| 10265 | ExprResult |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 10266 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 10267 | CXXStdInitializerListExpr *E) { |
| 10268 | return getDerived().TransformExpr(E->getSubExpr()); |
| 10269 | } |
| 10270 | |
| 10271 | template<typename Derived> |
| 10272 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10273 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10274 | return SemaRef.MaybeBindToTemporary(E); |
| 10275 | } |
| 10276 | |
| 10277 | template<typename Derived> |
| 10278 | ExprResult |
| 10279 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10280 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10281 | } |
| 10282 | |
| 10283 | template<typename Derived> |
| 10284 | ExprResult |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 10285 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 10286 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 10287 | if (SubExpr.isInvalid()) |
| 10288 | return ExprError(); |
| 10289 | |
| 10290 | if (!getDerived().AlwaysRebuild() && |
| 10291 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10292 | return E; |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 10293 | |
| 10294 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10295 | } |
| 10296 | |
| 10297 | template<typename Derived> |
| 10298 | ExprResult |
| 10299 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 10300 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10301 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10302 | bool ArgChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10303 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10304 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 10305 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10306 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10307 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 10308 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10309 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10310 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 10311 | Elements.data(), |
| 10312 | Elements.size()); |
| 10313 | } |
| 10314 | |
| 10315 | template<typename Derived> |
| 10316 | ExprResult |
| 10317 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10318 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10319 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10320 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10321 | bool ArgChanged = false; |
| 10322 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 10323 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10324 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10325 | if (OrigElement.isPackExpansion()) { |
| 10326 | // This key/value element is a pack expansion. |
| 10327 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10328 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 10329 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 10330 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 10331 | |
| 10332 | // Determine whether the set of unexpanded parameter packs can |
| 10333 | // and should be expanded. |
| 10334 | bool Expand = true; |
| 10335 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 10336 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 10337 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10338 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 10339 | OrigElement.Value->getLocEnd()); |
| 10340 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 10341 | PatternRange, |
| 10342 | Unexpanded, |
| 10343 | Expand, RetainExpansion, |
| 10344 | NumExpansions)) |
| 10345 | return ExprError(); |
| 10346 | |
| 10347 | if (!Expand) { |
| 10348 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10349 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10350 | // expansion. |
| 10351 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 10352 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10353 | if (Key.isInvalid()) |
| 10354 | return ExprError(); |
| 10355 | |
| 10356 | if (Key.get() != OrigElement.Key) |
| 10357 | ArgChanged = true; |
| 10358 | |
| 10359 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 10360 | if (Value.isInvalid()) |
| 10361 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10362 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10363 | if (Value.get() != OrigElement.Value) |
| 10364 | ArgChanged = true; |
| 10365 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10366 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10367 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 10368 | }; |
| 10369 | Elements.push_back(Expansion); |
| 10370 | continue; |
| 10371 | } |
| 10372 | |
| 10373 | // Record right away that the argument was changed. This needs |
| 10374 | // to happen even if the array expands to nothing. |
| 10375 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10376 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10377 | // The transform has determined that we should perform an elementwise |
| 10378 | // expansion of the pattern. Do so. |
| 10379 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10380 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 10381 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10382 | if (Key.isInvalid()) |
| 10383 | return ExprError(); |
| 10384 | |
| 10385 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 10386 | if (Value.isInvalid()) |
| 10387 | return ExprError(); |
| 10388 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10389 | ObjCDictionaryElement Element = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10390 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 10391 | }; |
| 10392 | |
| 10393 | // If any unexpanded parameter packs remain, we still have a |
| 10394 | // pack expansion. |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 10395 | // FIXME: Can this really happen? |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10396 | if (Key.get()->containsUnexpandedParameterPack() || |
| 10397 | Value.get()->containsUnexpandedParameterPack()) |
| 10398 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10399 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10400 | Elements.push_back(Element); |
| 10401 | } |
| 10402 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 10403 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 10404 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10405 | // We've finished with this pack expansion. |
| 10406 | continue; |
| 10407 | } |
| 10408 | |
| 10409 | // Transform and check key. |
| 10410 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10411 | if (Key.isInvalid()) |
| 10412 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10413 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10414 | if (Key.get() != OrigElement.Key) |
| 10415 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10416 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10417 | // Transform and check value. |
| 10418 | ExprResult Value |
| 10419 | = getDerived().TransformExpr(OrigElement.Value); |
| 10420 | if (Value.isInvalid()) |
| 10421 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10422 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10423 | if (Value.get() != OrigElement.Value) |
| 10424 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10425 | |
| 10426 | ObjCDictionaryElement Element = { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 10427 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10428 | }; |
| 10429 | Elements.push_back(Element); |
| 10430 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10431 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10432 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 10433 | return SemaRef.MaybeBindToTemporary(E); |
| 10434 | |
| 10435 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 10436 | Elements.data(), |
| 10437 | Elements.size()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10438 | } |
| 10439 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10440 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10441 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10442 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10443 | TypeSourceInfo *EncodedTypeInfo |
| 10444 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 10445 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10446 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10447 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10448 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10449 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10450 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10451 | |
| 10452 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10453 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10454 | E->getRParenLoc()); |
| 10455 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10456 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10457 | template<typename Derived> |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10458 | ExprResult TreeTransform<Derived>:: |
| 10459 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 10460 | // This is a kind of implicit conversion, and it needs to get dropped |
| 10461 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 10462 | // do, as well a more specific one: this expression is only valid when |
| 10463 | // it appears *immediately* as an argument expression. |
| 10464 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10465 | } |
| 10466 | |
| 10467 | template<typename Derived> |
| 10468 | ExprResult TreeTransform<Derived>:: |
| 10469 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10470 | TypeSourceInfo *TSInfo |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10471 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 10472 | if (!TSInfo) |
| 10473 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10474 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10475 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10476 | if (Result.isInvalid()) |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10477 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10478 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10479 | if (!getDerived().AlwaysRebuild() && |
| 10480 | TSInfo == E->getTypeInfoAsWritten() && |
| 10481 | Result.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10482 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10483 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10484 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10485 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10486 | Result.get()); |
| 10487 | } |
| 10488 | |
| 10489 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10490 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10491 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10492 | // Transform arguments. |
| 10493 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10494 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10495 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10496 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10497 | &ArgChanged)) |
| 10498 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10499 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10500 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 10501 | // Class message: transform the receiver type. |
| 10502 | TypeSourceInfo *ReceiverTypeInfo |
| 10503 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 10504 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10505 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10506 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10507 | // If nothing changed, just retain the existing message send. |
| 10508 | if (!getDerived().AlwaysRebuild() && |
| 10509 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10510 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10511 | |
| 10512 | // Build a new class message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 10513 | SmallVector<SourceLocation, 16> SelLocs; |
| 10514 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10515 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 10516 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 10517 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10518 | E->getMethodDecl(), |
| 10519 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10520 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10521 | E->getRightLoc()); |
| 10522 | } |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 10523 | else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || |
| 10524 | E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { |
| 10525 | // Build a new class message send to 'super'. |
| 10526 | SmallVector<SourceLocation, 16> SelLocs; |
| 10527 | E->getSelectorLocs(SelLocs); |
| 10528 | return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), |
| 10529 | E->getSelector(), |
| 10530 | SelLocs, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 10531 | E->getReceiverType(), |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 10532 | E->getMethodDecl(), |
| 10533 | E->getLeftLoc(), |
| 10534 | Args, |
| 10535 | E->getRightLoc()); |
| 10536 | } |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10537 | |
| 10538 | // Instance message: transform the receiver |
| 10539 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 10540 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10541 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10542 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 10543 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10544 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10545 | |
| 10546 | // If nothing changed, just retain the existing message send. |
| 10547 | if (!getDerived().AlwaysRebuild() && |
| 10548 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10549 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10550 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10551 | // Build a new instance message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 10552 | SmallVector<SourceLocation, 16> SelLocs; |
| 10553 | E->getSelectorLocs(SelLocs); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10554 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10555 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 10556 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10557 | E->getMethodDecl(), |
| 10558 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10559 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10560 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10561 | } |
| 10562 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10563 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10564 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10565 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10566 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10567 | } |
| 10568 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10569 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10570 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10571 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10572 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10573 | } |
| 10574 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10575 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10576 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10577 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10578 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10579 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10580 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10581 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10582 | |
| 10583 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10584 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10585 | // If nothing changed, just retain the existing expression. |
| 10586 | if (!getDerived().AlwaysRebuild() && |
| 10587 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10588 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10589 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10590 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10591 | E->getLocation(), |
| 10592 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10593 | } |
| 10594 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10595 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10596 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10597 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 10598 | // 'super' and types never change. Property never changes. Just |
| 10599 | // retain the existing expression. |
| 10600 | if (!E->isObjectReceiver()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10601 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10602 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 10603 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10604 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 10605 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10606 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10607 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 10608 | // We don't need to transform the property; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10609 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 10610 | // If nothing changed, just retain the existing expression. |
| 10611 | if (!getDerived().AlwaysRebuild() && |
| 10612 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10613 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10614 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 10615 | if (E->isExplicitProperty()) |
| 10616 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 10617 | E->getExplicitProperty(), |
| 10618 | E->getLocation()); |
| 10619 | |
| 10620 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 10621 | SemaRef.Context.PseudoObjectTy, |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 10622 | E->getImplicitPropertyGetter(), |
| 10623 | E->getImplicitPropertySetter(), |
| 10624 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10625 | } |
| 10626 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10627 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10628 | ExprResult |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10629 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 10630 | // Transform the base expression. |
| 10631 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 10632 | if (Base.isInvalid()) |
| 10633 | return ExprError(); |
| 10634 | |
| 10635 | // Transform the key expression. |
| 10636 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 10637 | if (Key.isInvalid()) |
| 10638 | return ExprError(); |
| 10639 | |
| 10640 | // If nothing changed, just retain the existing expression. |
| 10641 | if (!getDerived().AlwaysRebuild() && |
| 10642 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10643 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10644 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10645 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10646 | Base.get(), Key.get(), |
| 10647 | E->getAtIndexMethodDecl(), |
| 10648 | E->setAtIndexMethodDecl()); |
| 10649 | } |
| 10650 | |
| 10651 | template<typename Derived> |
| 10652 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10653 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10654 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10655 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10656 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10657 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10658 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10659 | // If nothing changed, just retain the existing expression. |
| 10660 | if (!getDerived().AlwaysRebuild() && |
| 10661 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10662 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10663 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10664 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 10665 | E->getOpLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 10666 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10667 | } |
| 10668 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10669 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10670 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10671 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10672 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10673 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10674 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10675 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10676 | SubExprs, &ArgumentChanged)) |
| 10677 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10678 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10679 | if (!getDerived().AlwaysRebuild() && |
| 10680 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10681 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10682 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10683 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10684 | SubExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10685 | E->getRParenLoc()); |
| 10686 | } |
| 10687 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10688 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10689 | ExprResult |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 10690 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 10691 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 10692 | if (SrcExpr.isInvalid()) |
| 10693 | return ExprError(); |
| 10694 | |
| 10695 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 10696 | if (!Type) |
| 10697 | return ExprError(); |
| 10698 | |
| 10699 | if (!getDerived().AlwaysRebuild() && |
| 10700 | Type == E->getTypeSourceInfo() && |
| 10701 | SrcExpr.get() == E->getSrcExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10702 | return E; |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 10703 | |
| 10704 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 10705 | SrcExpr.get(), Type, |
| 10706 | E->getRParenLoc()); |
| 10707 | } |
| 10708 | |
| 10709 | template<typename Derived> |
| 10710 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10711 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10712 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10713 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10714 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10715 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 10716 | |
| 10717 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 10718 | blockScope->TheDecl->setBlockMissingReturnType( |
| 10719 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10720 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 10721 | SmallVector<ParmVarDecl*, 4> params; |
| 10722 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10723 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 10724 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10725 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 10726 | oldBlock->param_begin(), |
| 10727 | oldBlock->param_size(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10728 | nullptr, paramTypes, ¶ms)) { |
| 10729 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10730 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10731 | } |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10732 | |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10733 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 10734 | QualType exprResultType = |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 10735 | getDerived().TransformType(exprFunctionType->getReturnType()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 10736 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 10737 | QualType functionType = |
| 10738 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10739 | exprFunctionType->getExtProtoInfo()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10740 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10741 | |
| 10742 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10743 | if (!params.empty()) |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 10744 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 10745 | |
| 10746 | if (!oldBlock->blockMissingReturnType()) { |
| 10747 | blockScope->HasImplicitReturnType = false; |
| 10748 | blockScope->ReturnType = exprResultType; |
| 10749 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10750 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10751 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10752 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10753 | if (body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10754 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10755 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10756 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10757 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10758 | #ifndef NDEBUG |
| 10759 | // In builds with assertions, make sure that we captured everything we |
| 10760 | // captured before. |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10761 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 10762 | for (const auto &I : oldBlock->captures()) { |
| 10763 | VarDecl *oldCapture = I.getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10764 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10765 | // Ignore parameter packs. |
| 10766 | if (isa<ParmVarDecl>(oldCapture) && |
| 10767 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 10768 | continue; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10769 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10770 | VarDecl *newCapture = |
| 10771 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 10772 | oldCapture)); |
| 10773 | assert(blockScope->CaptureMap.count(newCapture)); |
| 10774 | } |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10775 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10776 | } |
| 10777 | #endif |
| 10778 | |
| 10779 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10780 | /*Scope=*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10781 | } |
| 10782 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10783 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10784 | ExprResult |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 10785 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 10786 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 10787 | } |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 10788 | |
| 10789 | template<typename Derived> |
| 10790 | ExprResult |
| 10791 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10792 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 10793 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10794 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10795 | SubExprs.reserve(E->getNumSubExprs()); |
| 10796 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 10797 | SubExprs, &ArgumentChanged)) |
| 10798 | return ExprError(); |
| 10799 | |
| 10800 | if (!getDerived().AlwaysRebuild() && |
| 10801 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10802 | return E; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10803 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10804 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10805 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 10806 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10807 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10808 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10809 | // Type reconstruction |
| 10810 | //===----------------------------------------------------------------------===// |
| 10811 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10812 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10813 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 10814 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10815 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10816 | getDerived().getBaseEntity()); |
| 10817 | } |
| 10818 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10819 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10820 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 10821 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10822 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10823 | getDerived().getBaseEntity()); |
| 10824 | } |
| 10825 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10826 | template<typename Derived> |
| 10827 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10828 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 10829 | bool WrittenAsLValue, |
| 10830 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10831 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10832 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10833 | } |
| 10834 | |
| 10835 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10836 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10837 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 10838 | QualType ClassType, |
| 10839 | SourceLocation Sigil) { |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 10840 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 10841 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10842 | } |
| 10843 | |
| 10844 | template<typename Derived> |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 10845 | QualType TreeTransform<Derived>::RebuildObjCObjectType( |
| 10846 | QualType BaseType, |
| 10847 | SourceLocation Loc, |
| 10848 | SourceLocation TypeArgsLAngleLoc, |
| 10849 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 10850 | SourceLocation TypeArgsRAngleLoc, |
| 10851 | SourceLocation ProtocolLAngleLoc, |
| 10852 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 10853 | ArrayRef<SourceLocation> ProtocolLocs, |
| 10854 | SourceLocation ProtocolRAngleLoc) { |
| 10855 | return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, |
| 10856 | TypeArgs, TypeArgsRAngleLoc, |
| 10857 | ProtocolLAngleLoc, Protocols, ProtocolLocs, |
| 10858 | ProtocolRAngleLoc, |
| 10859 | /*FailOnError=*/true); |
| 10860 | } |
| 10861 | |
| 10862 | template<typename Derived> |
| 10863 | QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( |
| 10864 | QualType PointeeType, |
| 10865 | SourceLocation Star) { |
| 10866 | return SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 10867 | } |
| 10868 | |
| 10869 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10870 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10871 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 10872 | ArrayType::ArraySizeModifier SizeMod, |
| 10873 | const llvm::APInt *Size, |
| 10874 | Expr *SizeExpr, |
| 10875 | unsigned IndexTypeQuals, |
| 10876 | SourceRange BracketsRange) { |
| 10877 | if (SizeExpr || !Size) |
| 10878 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 10879 | IndexTypeQuals, BracketsRange, |
| 10880 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10881 | |
| 10882 | QualType Types[] = { |
| 10883 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 10884 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 10885 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10886 | }; |
Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 10887 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10888 | QualType SizeType; |
| 10889 | for (unsigned I = 0; I != NumTypes; ++I) |
| 10890 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 10891 | SizeType = Types[I]; |
| 10892 | break; |
| 10893 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10894 | |
Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 10895 | // Note that we can return a VariableArrayType here in the case where |
| 10896 | // the element type was a dependent VariableArrayType. |
| 10897 | IntegerLiteral *ArraySize |
| 10898 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 10899 | /*FIXME*/BracketsRange.getBegin()); |
| 10900 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10901 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10902 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10903 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10904 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10905 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10906 | QualType |
| 10907 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10908 | ArrayType::ArraySizeModifier SizeMod, |
| 10909 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10910 | unsigned IndexTypeQuals, |
| 10911 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10912 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10913 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10914 | } |
| 10915 | |
| 10916 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10917 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10918 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10919 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10920 | unsigned IndexTypeQuals, |
| 10921 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10922 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10923 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10924 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10925 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10926 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10927 | QualType |
| 10928 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10929 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10930 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10931 | unsigned IndexTypeQuals, |
| 10932 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10933 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10934 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10935 | IndexTypeQuals, BracketsRange); |
| 10936 | } |
| 10937 | |
| 10938 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10939 | QualType |
| 10940 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10941 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10942 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10943 | unsigned IndexTypeQuals, |
| 10944 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10945 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10946 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10947 | IndexTypeQuals, BracketsRange); |
| 10948 | } |
| 10949 | |
| 10950 | template<typename Derived> |
| 10951 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 10952 | unsigned NumElements, |
| 10953 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10954 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 10955 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10956 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10957 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10958 | template<typename Derived> |
| 10959 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 10960 | unsigned NumElements, |
| 10961 | SourceLocation AttributeLoc) { |
| 10962 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 10963 | NumElements, true); |
| 10964 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 10965 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 10966 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10967 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10968 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10969 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10970 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10971 | QualType |
| 10972 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10973 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10974 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10975 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10976 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10977 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10978 | template<typename Derived> |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 10979 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 10980 | QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 10981 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10982 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 10983 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10984 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 10985 | getDerived().getBaseEntity(), |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10986 | EPI); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10988 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10989 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 10990 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 10991 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 10992 | } |
| 10993 | |
| 10994 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10995 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 10996 | assert(D && "no decl found"); |
| 10997 | if (D->isInvalidDecl()) return QualType(); |
| 10998 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10999 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 11000 | TypeDecl *Ty; |
| 11001 | if (isa<UsingDecl>(D)) { |
| 11002 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 11003 | assert(Using->hasTypename() && |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 11004 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 11005 | |
| 11006 | // A valid resolved using typename decl points to exactly one type decl. |
| 11007 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 11008 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11009 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 11010 | } else { |
| 11011 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 11012 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 11013 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 11014 | } |
| 11015 | |
| 11016 | return SemaRef.Context.getTypeDeclType(Ty); |
| 11017 | } |
| 11018 | |
| 11019 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 11020 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 11021 | SourceLocation Loc) { |
| 11022 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11023 | } |
| 11024 | |
| 11025 | template<typename Derived> |
| 11026 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 11027 | return SemaRef.Context.getTypeOfType(Underlying); |
| 11028 | } |
| 11029 | |
| 11030 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 11031 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 11032 | SourceLocation Loc) { |
| 11033 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11034 | } |
| 11035 | |
| 11036 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 11037 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 11038 | UnaryTransformType::UTTKind UKind, |
| 11039 | SourceLocation Loc) { |
| 11040 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 11041 | } |
| 11042 | |
| 11043 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11044 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 11045 | TemplateName Template, |
| 11046 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 11047 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 11048 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11050 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 11051 | template<typename Derived> |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 11052 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 11053 | SourceLocation KWLoc) { |
| 11054 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 11055 | } |
| 11056 | |
| 11057 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11058 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11059 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 11060 | bool TemplateKW, |
| 11061 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11062 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 11063 | Template); |
| 11064 | } |
| 11065 | |
| 11066 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11067 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11068 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 11069 | const IdentifierInfo &Name, |
| 11070 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11071 | QualType ObjectType, |
| 11072 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11073 | UnqualifiedId TemplateName; |
| 11074 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 11075 | Sema::TemplateTy Template; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11076 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11077 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11078 | SS, TemplateKWLoc, TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11079 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 11080 | /*EnteringContext=*/false, |
| 11081 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11082 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 11083 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11084 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11085 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11086 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11087 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11088 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11089 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11090 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11091 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11092 | // FIXME: Bogus location information. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11093 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11094 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11095 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 11096 | Sema::TemplateTy Template; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11097 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11098 | SS, TemplateKWLoc, Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11099 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 11100 | /*EnteringContext=*/false, |
| 11101 | Template); |
Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 11102 | return Template.get(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11103 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11104 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11105 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11106 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11107 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 11108 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11109 | Expr *OrigCallee, |
| 11110 | Expr *First, |
| 11111 | Expr *Second) { |
| 11112 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 11113 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11114 | |
Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 11115 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 11116 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 11117 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 11118 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 11119 | First, Second); |
| 11120 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 11121 | if (Result.isInvalid()) |
| 11122 | return ExprError(); |
| 11123 | First = Result.get(); |
| 11124 | } |
| 11125 | |
| 11126 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 11127 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 11128 | if (Result.isInvalid()) |
| 11129 | return ExprError(); |
| 11130 | Second = Result.get(); |
| 11131 | } |
| 11132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11133 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 11134 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11135 | if (!First->getType()->isOverloadableType() && |
| 11136 | !Second->getType()->isOverloadableType()) |
| 11137 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 11138 | Callee->getLocStart(), |
| 11139 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 11140 | } else if (Op == OO_Arrow) { |
| 11141 | // -> is never a builtin operation. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11142 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 11143 | } else if (Second == nullptr || isPostIncDec) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11144 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11145 | // The argument is not of overloadable type, so try to create a |
| 11146 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11147 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11148 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11149 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11150 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11151 | } |
| 11152 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11153 | if (!First->getType()->isOverloadableType() && |
| 11154 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11155 | // Neither of the arguments is an overloadable type, so try to |
| 11156 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11157 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11158 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11159 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11160 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11161 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11162 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11163 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11164 | } |
| 11165 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11166 | |
| 11167 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11168 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 11169 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11170 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11171 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11172 | assert(ULE->requiresADL()); |
Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 11173 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11174 | } else { |
Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 11175 | // If we've resolved this to a particular non-member function, just call |
| 11176 | // that function. If we resolved it to a member function, |
| 11177 | // CreateOverloaded* will find that function for us. |
| 11178 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 11179 | if (!isa<CXXMethodDecl>(ND)) |
| 11180 | Functions.addDecl(ND); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11181 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11182 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11183 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11184 | Expr *Args[2] = { First, Second }; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11185 | unsigned NumArgs = 1 + (Second != nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11186 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11187 | // Create the overloaded operator invocation for unary operators. |
| 11188 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11189 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11190 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11191 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11192 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11193 | |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 11194 | if (Op == OO_Subscript) { |
| 11195 | SourceLocation LBrace; |
| 11196 | SourceLocation RBrace; |
| 11197 | |
| 11198 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
NAKAMURA Takumi | 44d4d9a | 2014-10-29 08:11:47 +0000 | [diff] [blame] | 11199 | DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo(); |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 11200 | LBrace = SourceLocation::getFromRawEncoding( |
| 11201 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 11202 | RBrace = SourceLocation::getFromRawEncoding( |
| 11203 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 11204 | } else { |
| 11205 | LBrace = Callee->getLocStart(); |
| 11206 | RBrace = OpLoc; |
| 11207 | } |
| 11208 | |
| 11209 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 11210 | First, Second); |
| 11211 | } |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 11212 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11213 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11214 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11215 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11216 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 11217 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11218 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11219 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11220 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11221 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11222 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11223 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11224 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11225 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11226 | SourceLocation OperatorLoc, |
| 11227 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 11228 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11229 | TypeSourceInfo *ScopeType, |
| 11230 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 11231 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 11232 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11233 | QualType BaseType = Base->getType(); |
| 11234 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11235 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11236 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 11237 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 11238 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11239 | // This pseudo-destructor expression is still a pseudo-destructor. |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 11240 | return SemaRef.BuildPseudoDestructorExpr( |
| 11241 | Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, |
| 11242 | CCLoc, TildeLoc, Destroyed); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11243 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11244 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 11245 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11246 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 11247 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 11248 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 11249 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 11250 | |
Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 11251 | // The scope type is now known to be a valid nested name specifier |
| 11252 | // component. Tack it on to the end of the nested name specifier. |
Alexey Bataev | 2a06681 | 2014-10-16 03:04:35 +0000 | [diff] [blame] | 11253 | if (ScopeType) { |
| 11254 | if (!ScopeType->getType()->getAs<TagType>()) { |
| 11255 | getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 11256 | diag::err_expected_class_or_namespace) |
| 11257 | << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 11258 | return ExprError(); |
| 11259 | } |
| 11260 | SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), |
| 11261 | CCLoc); |
| 11262 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11263 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11264 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11265 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11266 | OperatorLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11267 | SS, TemplateKWLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11268 | /*FIXME: FirstQualifier*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11269 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 11270 | /*TemplateArgs*/ nullptr, |
| 11271 | /*S*/nullptr); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11272 | } |
| 11273 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 11274 | template<typename Derived> |
| 11275 | StmtResult |
| 11276 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 11277 | SourceLocation Loc = S->getLocStart(); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 11278 | CapturedDecl *CD = S->getCapturedDecl(); |
| 11279 | unsigned NumParams = CD->getNumParams(); |
| 11280 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 11281 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 11282 | for (unsigned I = 0; I < NumParams; ++I) { |
| 11283 | if (I != ContextParamPos) { |
| 11284 | Params.push_back( |
| 11285 | std::make_pair( |
| 11286 | CD->getParam(I)->getName(), |
| 11287 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 11288 | } else { |
| 11289 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 11290 | } |
| 11291 | } |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11292 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 11293 | S->getCapturedRegionKind(), Params); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11294 | StmtResult Body; |
| 11295 | { |
| 11296 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 11297 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 11298 | } |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 11299 | |
| 11300 | if (Body.isInvalid()) { |
| 11301 | getSema().ActOnCapturedRegionError(); |
| 11302 | return StmtError(); |
| 11303 | } |
| 11304 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11305 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 11306 | } |
| 11307 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11308 | } // end namespace clang |
| 11309 | |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 11310 | #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |