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. |
Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 394 | bool TransformExprs(Expr *const *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 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 413 | /// \brief Transform the specified condition. |
| 414 | /// |
| 415 | /// By default, this transforms the variable and expression and rebuilds |
| 416 | /// the condition. |
| 417 | Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, |
| 418 | Expr *Expr, |
| 419 | Sema::ConditionKind Kind); |
| 420 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 421 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 422 | /// place them on the new declaration. |
| 423 | /// |
| 424 | /// By default, this operation does nothing. Subclasses may override this |
| 425 | /// behavior to transform attributes. |
| 426 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 427 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 428 | /// \brief Note that a local declaration has been transformed by this |
| 429 | /// transformer. |
| 430 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 431 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 432 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 433 | /// the transformer itself has to transform the declarations. This routine |
| 434 | /// can be overridden by a subclass that keeps track of such mappings. |
| 435 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 436 | TransformedLocalDecls[Old] = New; |
| 437 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 438 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 439 | /// \brief Transform the definition of the given declaration. |
| 440 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 442 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 443 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 444 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 445 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 447 | /// \brief Transform the given declaration, which was the first part of a |
| 448 | /// nested-name-specifier in a member access expression. |
| 449 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 450 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 451 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 452 | /// the \c T in \c x->T::member |
| 453 | /// |
| 454 | /// By default, invokes TransformDecl() to transform the declaration. |
| 455 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 456 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 457 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 458 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 459 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 460 | /// \brief Transform the given nested-name-specifier with source-location |
| 461 | /// information. |
| 462 | /// |
| 463 | /// By default, transforms all of the types and declarations within the |
| 464 | /// nested-name-specifier. Subclasses may override this function to provide |
| 465 | /// alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 466 | NestedNameSpecifierLoc |
| 467 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 468 | QualType ObjectType = QualType(), |
| 469 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 470 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 471 | /// \brief Transform the given declaration name. |
| 472 | /// |
| 473 | /// By default, transforms the types of conversion function, constructor, |
| 474 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 475 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 476 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 477 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 478 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 479 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 480 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 481 | /// |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 482 | /// \param SS The nested-name-specifier that qualifies the template |
| 483 | /// name. This nested-name-specifier must already have been transformed. |
| 484 | /// |
| 485 | /// \param Name The template name to transform. |
| 486 | /// |
| 487 | /// \param NameLoc The source location of the template name. |
| 488 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 489 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 490 | /// access expression, this is the type of the object whose member template |
| 491 | /// is being referenced. |
| 492 | /// |
| 493 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 494 | /// also refers to a name within the current (lexical) scope, this is the |
| 495 | /// declaration it refers to. |
| 496 | /// |
| 497 | /// By default, transforms the template name by transforming the declarations |
| 498 | /// and nested-name-specifiers that occur within the template name. |
| 499 | /// Subclasses may override this function to provide alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 500 | TemplateName |
| 501 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 502 | SourceLocation NameLoc, |
| 503 | QualType ObjectType = QualType(), |
| 504 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 505 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 506 | /// \brief Transform the given template argument. |
| 507 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 508 | /// By default, this operation transforms the type, expression, or |
| 509 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 510 | /// new template argument from the transformed result. Subclasses may |
| 511 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 512 | /// |
| 513 | /// Returns true if there was an error. |
| 514 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 515 | TemplateArgumentLoc &Output, |
| 516 | bool Uneval = false); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 517 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 518 | /// \brief Transform the given set of template arguments. |
| 519 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 520 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 521 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 522 | /// the transformed arguments to the output list. |
| 523 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 524 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 525 | /// a convenience function. Subclasses that wish to override this behavior |
| 526 | /// should override the iterator-based member template version. |
| 527 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 528 | /// \param Inputs The set of template arguments to be transformed. |
| 529 | /// |
| 530 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 531 | /// |
| 532 | /// \param Outputs The set of transformed template arguments output by this |
| 533 | /// routine. |
| 534 | /// |
| 535 | /// Returns true if an error occurred. |
| 536 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 537 | unsigned NumInputs, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 538 | TemplateArgumentListInfo &Outputs, |
| 539 | bool Uneval = false) { |
| 540 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, |
| 541 | Uneval); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 542 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 543 | |
| 544 | /// \brief Transform the given set of template arguments. |
| 545 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 546 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 547 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 548 | /// the transformed arguments to the output list. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 549 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 550 | /// \param First An iterator to the first template argument. |
| 551 | /// |
| 552 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 553 | /// |
| 554 | /// \param Outputs The set of transformed template arguments output by this |
| 555 | /// routine. |
| 556 | /// |
| 557 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 558 | template<typename InputIterator> |
| 559 | bool TransformTemplateArguments(InputIterator First, |
| 560 | InputIterator Last, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 561 | TemplateArgumentListInfo &Outputs, |
| 562 | bool Uneval = false); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 563 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 564 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 565 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 566 | TemplateArgumentLoc &ArgLoc); |
| 567 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 568 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 569 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 570 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 571 | getDerived().getBaseLocation()); |
| 572 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 574 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 575 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 576 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 577 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 578 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 579 | template<typename Fn> |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 580 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 581 | FunctionProtoTypeLoc TL, |
| 582 | CXXRecordDecl *ThisContext, |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 583 | unsigned ThisTypeQuals, |
| 584 | Fn TransformExceptionSpec); |
| 585 | |
| 586 | bool TransformExceptionSpec(SourceLocation Loc, |
| 587 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 588 | SmallVectorImpl<QualType> &Exceptions, |
| 589 | bool &Changed); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 590 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 591 | StmtResult TransformSEHHandler(Stmt *Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 592 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 593 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 594 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 595 | TemplateSpecializationTypeLoc TL, |
| 596 | TemplateName Template); |
| 597 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 598 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 599 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 600 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 601 | TemplateName Template, |
| 602 | CXXScopeSpec &SS); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 603 | |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 604 | QualType TransformDependentTemplateSpecializationType( |
| 605 | TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, |
| 606 | NestedNameSpecifierLoc QualifierLoc); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 607 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 608 | /// \brief Transforms the parameters of a function type into the |
| 609 | /// given vectors. |
| 610 | /// |
| 611 | /// The result vectors should be kept in sync; null entries in the |
| 612 | /// variables vector are acceptable. |
| 613 | /// |
| 614 | /// Return true on error. |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 615 | bool TransformFunctionTypeParams( |
| 616 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 617 | const QualType *ParamTypes, |
| 618 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 619 | SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, |
| 620 | Sema::ExtParameterInfoBuilder &PInfos); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 621 | |
| 622 | /// \brief Transforms a single function-type parameter. Return null |
| 623 | /// on error. |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 624 | /// |
| 625 | /// \param indexAdjustment - A number to add to the parameter's |
| 626 | /// scope index; can be negative |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 627 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 628 | int indexAdjustment, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 629 | Optional<unsigned> NumExpansions, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 630 | bool ExpectParameterPack); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 631 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 632 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 633 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 634 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 635 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 636 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 637 | TemplateParameterList *TransformTemplateParameterList( |
| 638 | TemplateParameterList *TPL) { |
| 639 | return TPL; |
| 640 | } |
| 641 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 642 | ExprResult TransformAddressOfOperand(Expr *E); |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 643 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 644 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 645 | bool IsAddressOfOperand, |
| 646 | TypeSourceInfo **RecoveryTSI); |
| 647 | |
| 648 | ExprResult TransformParenDependentScopeDeclRefExpr( |
| 649 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 650 | TypeSourceInfo **RecoveryTSI); |
| 651 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 652 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 653 | |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 654 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 655 | // amount of stack usage with clang. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 656 | #define STMT(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 657 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 658 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 659 | #define EXPR(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 660 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 661 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 662 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 663 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 665 | #define OPENMP_CLAUSE(Name, Class) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 666 | LLVM_ATTRIBUTE_NOINLINE \ |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 667 | OMPClause *Transform ## Class(Class *S); |
| 668 | #include "clang/Basic/OpenMPKinds.def" |
| 669 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 670 | /// \brief Build a new pointer type given its pointee type. |
| 671 | /// |
| 672 | /// By default, performs semantic analysis when building the pointer type. |
| 673 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 674 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 675 | |
| 676 | /// \brief Build a new block pointer type given its pointee type. |
| 677 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 678 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 679 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 680 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 681 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 682 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 683 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 684 | /// By default, performs semantic analysis when building the |
| 685 | /// reference type. Subclasses may override this routine to provide |
| 686 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 687 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 688 | /// \param LValue whether the type was written with an lvalue sigil |
| 689 | /// or an rvalue sigil. |
| 690 | QualType RebuildReferenceType(QualType ReferentType, |
| 691 | bool LValue, |
| 692 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 693 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 694 | /// \brief Build a new member pointer type given the pointee type and the |
| 695 | /// class type it refers into. |
| 696 | /// |
| 697 | /// By default, performs semantic analysis when building the member pointer |
| 698 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 699 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 700 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 702 | /// \brief Build an Objective-C object type. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis when building the object type. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
| 706 | QualType RebuildObjCObjectType(QualType BaseType, |
| 707 | SourceLocation Loc, |
| 708 | SourceLocation TypeArgsLAngleLoc, |
| 709 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 710 | SourceLocation TypeArgsRAngleLoc, |
| 711 | SourceLocation ProtocolLAngleLoc, |
| 712 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 713 | ArrayRef<SourceLocation> ProtocolLocs, |
| 714 | SourceLocation ProtocolRAngleLoc); |
| 715 | |
| 716 | /// \brief Build a new Objective-C object pointer type given the pointee type. |
| 717 | /// |
| 718 | /// By default, directly builds the pointer type, with no additional semantic |
| 719 | /// analysis. |
| 720 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 721 | SourceLocation Star); |
| 722 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 723 | /// \brief Build a new array type given the element type, size |
| 724 | /// modifier, size of the array (if known), size expression, and index type |
| 725 | /// qualifiers. |
| 726 | /// |
| 727 | /// By default, performs semantic analysis when building the array type. |
| 728 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 730 | QualType RebuildArrayType(QualType ElementType, |
| 731 | ArrayType::ArraySizeModifier SizeMod, |
| 732 | const llvm::APInt *Size, |
| 733 | Expr *SizeExpr, |
| 734 | unsigned IndexTypeQuals, |
| 735 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 736 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 737 | /// \brief Build a new constant array type given the element type, size |
| 738 | /// modifier, (known) size of the array, and index type qualifiers. |
| 739 | /// |
| 740 | /// By default, performs semantic analysis when building the array type. |
| 741 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 743 | ArrayType::ArraySizeModifier SizeMod, |
| 744 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 745 | unsigned IndexTypeQuals, |
| 746 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 747 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 748 | /// \brief Build a new incomplete array type given the element type, size |
| 749 | /// modifier, and index type qualifiers. |
| 750 | /// |
| 751 | /// By default, performs semantic analysis when building the array type. |
| 752 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 753 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 754 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 755 | unsigned IndexTypeQuals, |
| 756 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 757 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 759 | /// size modifier, size expression, and index type qualifiers. |
| 760 | /// |
| 761 | /// By default, performs semantic analysis when building the array type. |
| 762 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 763 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 764 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 765 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 766 | unsigned IndexTypeQuals, |
| 767 | SourceRange BracketsRange); |
| 768 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 770 | /// size modifier, size expression, and index type qualifiers. |
| 771 | /// |
| 772 | /// By default, performs semantic analysis when building the array type. |
| 773 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 774 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 775 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 776 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 777 | unsigned IndexTypeQuals, |
| 778 | SourceRange BracketsRange); |
| 779 | |
| 780 | /// \brief Build a new vector type given the element type and |
| 781 | /// number of elements. |
| 782 | /// |
| 783 | /// By default, performs semantic analysis when building the vector type. |
| 784 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 785 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 786 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 787 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 788 | /// \brief Build a new extended vector type given the element type and |
| 789 | /// number of elements. |
| 790 | /// |
| 791 | /// By default, performs semantic analysis when building the vector type. |
| 792 | /// Subclasses may override this routine to provide different behavior. |
| 793 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 794 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 795 | |
| 796 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 797 | /// given the element type and number of elements. |
| 798 | /// |
| 799 | /// By default, performs semantic analysis when building the vector type. |
| 800 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 801 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 802 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 803 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 805 | /// \brief Build a new function type. |
| 806 | /// |
| 807 | /// By default, performs semantic analysis when building the function type. |
| 808 | /// Subclasses may override this routine to provide different behavior. |
| 809 | QualType RebuildFunctionProtoType(QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 810 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 811 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 813 | /// \brief Build a new unprototyped function type. |
| 814 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 815 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 816 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 817 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 818 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 819 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 820 | /// \brief Build a new typedef type. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 821 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 822 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 823 | } |
| 824 | |
| 825 | /// \brief Build a new class/struct/union type. |
| 826 | QualType RebuildRecordType(RecordDecl *Record) { |
| 827 | return SemaRef.Context.getTypeDeclType(Record); |
| 828 | } |
| 829 | |
| 830 | /// \brief Build a new Enum type. |
| 831 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 832 | return SemaRef.Context.getTypeDeclType(Enum); |
| 833 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 834 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 835 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 836 | /// |
| 837 | /// By default, performs semantic analysis when building the typeof type. |
| 838 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 839 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 840 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 842 | /// |
| 843 | /// By default, builds a new TypeOfType with the given underlying type. |
| 844 | QualType RebuildTypeOfType(QualType Underlying); |
| 845 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 846 | /// \brief Build a new unary transform type. |
| 847 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 848 | UnaryTransformType::UTTKind UKind, |
| 849 | SourceLocation Loc); |
| 850 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 851 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 852 | /// |
| 853 | /// By default, performs semantic analysis when building the decltype type. |
| 854 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 855 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 857 | /// \brief Build a new C++11 auto type. |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 858 | /// |
| 859 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 860 | QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) { |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 861 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 862 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 863 | // that we'll retry deduction after the transformation. |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 864 | return SemaRef.Context.getAutoType(Deduced, Keyword, |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 865 | /*IsDependent*/ false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 866 | } |
| 867 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 868 | /// \brief Build a new template specialization type. |
| 869 | /// |
| 870 | /// By default, performs semantic analysis when building the template |
| 871 | /// specialization type. Subclasses may override this routine to provide |
| 872 | /// different behavior. |
| 873 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 874 | SourceLocation TemplateLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 875 | TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 876 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 877 | /// \brief Build a new parenthesized type. |
| 878 | /// |
| 879 | /// By default, builds a new ParenType type from the inner type. |
| 880 | /// Subclasses may override this routine to provide different behavior. |
| 881 | QualType RebuildParenType(QualType InnerType) { |
| 882 | return SemaRef.Context.getParenType(InnerType); |
| 883 | } |
| 884 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 885 | /// \brief Build a new qualified name type. |
| 886 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 887 | /// By default, builds a new ElaboratedType type from the keyword, |
| 888 | /// the nested-name-specifier and the named type. |
| 889 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 890 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 891 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 892 | NestedNameSpecifierLoc QualifierLoc, |
| 893 | QualType Named) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 894 | return SemaRef.Context.getElaboratedType(Keyword, |
| 895 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 896 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 897 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 898 | |
| 899 | /// \brief Build a new typename type that refers to a template-id. |
| 900 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 901 | /// By default, builds a new DependentNameType type from the |
| 902 | /// nested-name-specifier and the given type. Subclasses may override |
| 903 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 904 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 905 | ElaboratedTypeKeyword Keyword, |
| 906 | NestedNameSpecifierLoc QualifierLoc, |
| 907 | const IdentifierInfo *Name, |
| 908 | SourceLocation NameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 909 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 910 | // Rebuild the template name. |
| 911 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 912 | CXXScopeSpec SS; |
| 913 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 914 | TemplateName InstName |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 915 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), |
| 916 | nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 917 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 918 | if (InstName.isNull()) |
| 919 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 920 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 921 | // If it's still dependent, make a dependent specialization. |
| 922 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 923 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 924 | QualifierLoc.getNestedNameSpecifier(), |
| 925 | Name, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 926 | Args); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 928 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 929 | // specialization. |
| 930 | QualType T = |
| 931 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 932 | if (T.isNull()) return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 933 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 934 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 935 | return T; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 936 | |
| 937 | return SemaRef.Context.getElaboratedType(Keyword, |
| 938 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 939 | T); |
| 940 | } |
| 941 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 942 | /// \brief Build a new typename type that refers to an identifier. |
| 943 | /// |
| 944 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 945 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 946 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 947 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 948 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 949 | NestedNameSpecifierLoc QualifierLoc, |
| 950 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 951 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 952 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 953 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 954 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 955 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 956 | // If the name is still dependent, just build a new dependent name type. |
| 957 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 958 | return SemaRef.Context.getDependentNameType(Keyword, |
| 959 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 960 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 963 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 964 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 965 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 966 | |
| 967 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 968 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 969 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 970 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 971 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 972 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 973 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 974 | if (!DC) |
| 975 | return QualType(); |
| 976 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 977 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 978 | return QualType(); |
| 979 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 980 | TagDecl *Tag = nullptr; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 981 | SemaRef.LookupQualifiedName(Result, DC); |
| 982 | switch (Result.getResultKind()) { |
| 983 | case LookupResult::NotFound: |
| 984 | case LookupResult::NotFoundInCurrentInstantiation: |
| 985 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 986 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 987 | case LookupResult::Found: |
| 988 | Tag = Result.getAsSingle<TagDecl>(); |
| 989 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 990 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 991 | case LookupResult::FoundOverloaded: |
| 992 | case LookupResult::FoundUnresolvedValue: |
| 993 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 994 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 995 | case LookupResult::Ambiguous: |
| 996 | // Let the LookupResult structure handle ambiguities. |
| 997 | return QualType(); |
| 998 | } |
| 999 | |
| 1000 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1001 | // Check where the name exists but isn't a tag type and use that to emit |
| 1002 | // better diagnostics. |
| 1003 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 1004 | SemaRef.LookupQualifiedName(Result, DC); |
| 1005 | switch (Result.getResultKind()) { |
| 1006 | case LookupResult::Found: |
| 1007 | case LookupResult::FoundOverloaded: |
| 1008 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1009 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1010 | unsigned Kind = 0; |
| 1011 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1012 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 1013 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1014 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 1015 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 1016 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1017 | } |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1018 | default: |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1019 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Stephan Tolksdorf | eb7708d | 2014-03-13 20:34:03 +0000 | [diff] [blame] | 1020 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1021 | break; |
| 1022 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1023 | return QualType(); |
| 1024 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1025 | |
Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 1026 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
Justin Bogner | c6ecb7c | 2015-07-10 23:05:47 +0000 | [diff] [blame] | 1027 | IdLoc, Id)) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1028 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1029 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 1030 | return QualType(); |
| 1031 | } |
| 1032 | |
| 1033 | // Build the elaborated-type-specifier type. |
| 1034 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1035 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1036 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1037 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1038 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1039 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1040 | /// \brief Build a new pack expansion type. |
| 1041 | /// |
| 1042 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 1043 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1044 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1045 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1046 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1047 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1048 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 1049 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1052 | /// \brief Build a new atomic type given its value type. |
| 1053 | /// |
| 1054 | /// By default, performs semantic analysis when building the atomic type. |
| 1055 | /// Subclasses may override this routine to provide different behavior. |
| 1056 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1057 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 1058 | /// \brief Build a new pipe type given its value type. |
| 1059 | QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc); |
| 1060 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1061 | /// \brief Build a new template name given a nested name specifier, a flag |
| 1062 | /// indicating whether the "template" keyword was provided, and the template |
| 1063 | /// that the template name refers to. |
| 1064 | /// |
| 1065 | /// By default, builds the new template name directly. Subclasses may override |
| 1066 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1067 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1068 | bool TemplateKW, |
| 1069 | TemplateDecl *Template); |
| 1070 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1071 | /// \brief Build a new template name given a nested name specifier and the |
| 1072 | /// name that is referred to as a template. |
| 1073 | /// |
| 1074 | /// By default, performs semantic analysis to determine whether the name can |
| 1075 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1076 | /// template name. Subclasses may override this routine to provide different |
| 1077 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1078 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1079 | const IdentifierInfo &Name, |
| 1080 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1081 | QualType ObjectType, |
| 1082 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1084 | /// \brief Build a new template name given a nested name specifier and the |
| 1085 | /// overloaded operator name that is referred to as a template. |
| 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. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1091 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1092 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1093 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1094 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1095 | |
| 1096 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1097 | /// and the |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1098 | /// |
| 1099 | /// By default, performs semantic analysis to determine whether the name can |
| 1100 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1101 | /// template name. Subclasses may override this routine to provide different |
| 1102 | /// behavior. |
| 1103 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1104 | const TemplateArgument &ArgPack) { |
| 1105 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1106 | } |
| 1107 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1108 | /// \brief Build a new compound 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 RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1113 | MultiStmtArg Statements, |
| 1114 | SourceLocation RBraceLoc, |
| 1115 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1116 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1117 | IsStmtExpr); |
| 1118 | } |
| 1119 | |
| 1120 | /// \brief Build a new case statement. |
| 1121 | /// |
| 1122 | /// By default, performs semantic analysis to build the new statement. |
| 1123 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1124 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1125 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1126 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1127 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1128 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1129 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1130 | ColonLoc); |
| 1131 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1133 | /// \brief Attach the body to a new case statement. |
| 1134 | /// |
| 1135 | /// By default, performs semantic analysis to build the new statement. |
| 1136 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1137 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1138 | getSema().ActOnCaseStmtBody(S, Body); |
| 1139 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1140 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1141 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1142 | /// \brief Build a new default statement. |
| 1143 | /// |
| 1144 | /// By default, performs semantic analysis to build the new statement. |
| 1145 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1146 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1147 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1148 | Stmt *SubStmt) { |
| 1149 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1150 | /*CurScope=*/nullptr); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1151 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1152 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1153 | /// \brief Build a new label statement. |
| 1154 | /// |
| 1155 | /// By default, performs semantic analysis to build the new statement. |
| 1156 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1157 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1158 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1159 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1160 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1162 | /// \brief Build a new label statement. |
| 1163 | /// |
| 1164 | /// By default, performs semantic analysis to build the new statement. |
| 1165 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1166 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1167 | ArrayRef<const Attr*> Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1168 | Stmt *SubStmt) { |
| 1169 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1170 | } |
| 1171 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1172 | /// \brief Build a new "if" statement. |
| 1173 | /// |
| 1174 | /// By default, performs semantic analysis to build the new statement. |
| 1175 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 1176 | StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
| 1177 | Sema::ConditionResult Cond, Stmt *Then, |
| 1178 | SourceLocation ElseLoc, Stmt *Else) { |
Richard Smith | c7a05a9 | 2016-06-29 21:17:59 +0000 | [diff] [blame] | 1179 | return getSema().ActOnIfStmt(IfLoc, IsConstexpr, nullptr, Cond, Then, |
| 1180 | ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1181 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1183 | /// \brief Start building a new switch statement. |
| 1184 | /// |
| 1185 | /// By default, performs semantic analysis to build the new statement. |
| 1186 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1187 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1188 | Sema::ConditionResult Cond) { |
Richard Smith | c7a05a9 | 2016-06-29 21:17:59 +0000 | [diff] [blame] | 1189 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, nullptr, Cond); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1191 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1192 | /// \brief Attach the body to the switch statement. |
| 1193 | /// |
| 1194 | /// By default, performs semantic analysis to build the new statement. |
| 1195 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1196 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1197 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1198 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | /// \brief Build a new while statement. |
| 1202 | /// |
| 1203 | /// By default, performs semantic analysis to build the new statement. |
| 1204 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1205 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 1206 | Sema::ConditionResult Cond, Stmt *Body) { |
| 1207 | return getSema().ActOnWhileStmt(WhileLoc, Cond, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1208 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1210 | /// \brief Build a new do-while statement. |
| 1211 | /// |
| 1212 | /// By default, performs semantic analysis to build the new statement. |
| 1213 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1214 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1215 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1216 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1217 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1218 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | /// \brief Build a new for 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 RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1226 | Stmt *Init, Sema::ConditionResult Cond, |
| 1227 | Sema::FullExprArg Inc, SourceLocation RParenLoc, |
| 1228 | Stmt *Body) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1229 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1230 | Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1231 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1232 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1233 | /// \brief Build a new goto statement. |
| 1234 | /// |
| 1235 | /// By default, performs semantic analysis to build the new statement. |
| 1236 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1237 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1238 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1239 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | /// \brief Build a new indirect goto statement. |
| 1243 | /// |
| 1244 | /// By default, performs semantic analysis to build the new statement. |
| 1245 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1246 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1247 | SourceLocation StarLoc, |
| 1248 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1249 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1250 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1251 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1252 | /// \brief Build a new return statement. |
| 1253 | /// |
| 1254 | /// By default, performs semantic analysis to build the new statement. |
| 1255 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1256 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
Nick Lewycky | d78f92f | 2014-05-03 00:41:18 +0000 | [diff] [blame] | 1257 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1258 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1259 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1260 | /// \brief Build a new declaration statement. |
| 1261 | /// |
| 1262 | /// By default, performs semantic analysis to build the new statement. |
| 1263 | /// Subclasses may override this routine to provide different behavior. |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 1264 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1265 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1266 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1267 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1268 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1269 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1270 | /// \brief Build a new inline asm statement. |
| 1271 | /// |
| 1272 | /// By default, performs semantic analysis to build the new statement. |
| 1273 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1274 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1275 | bool IsVolatile, unsigned NumOutputs, |
| 1276 | unsigned NumInputs, IdentifierInfo **Names, |
| 1277 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1278 | Expr *AsmString, MultiExprArg Clobbers, |
| 1279 | SourceLocation RParenLoc) { |
| 1280 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1281 | NumInputs, Names, Constraints, Exprs, |
| 1282 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1283 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1284 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1285 | /// \brief Build a new MS style inline asm statement. |
| 1286 | /// |
| 1287 | /// By default, performs semantic analysis to build the new statement. |
| 1288 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1289 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1290 | ArrayRef<Token> AsmToks, |
| 1291 | StringRef AsmString, |
| 1292 | unsigned NumOutputs, unsigned NumInputs, |
| 1293 | ArrayRef<StringRef> Constraints, |
| 1294 | ArrayRef<StringRef> Clobbers, |
| 1295 | ArrayRef<Expr*> Exprs, |
| 1296 | SourceLocation EndLoc) { |
| 1297 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1298 | NumOutputs, NumInputs, |
| 1299 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1302 | /// \brief Build a new co_return statement. |
| 1303 | /// |
| 1304 | /// By default, performs semantic analysis to build the new statement. |
| 1305 | /// Subclasses may override this routine to provide different behavior. |
| 1306 | StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) { |
| 1307 | return getSema().BuildCoreturnStmt(CoreturnLoc, Result); |
| 1308 | } |
| 1309 | |
| 1310 | /// \brief Build a new co_await expression. |
| 1311 | /// |
| 1312 | /// By default, performs semantic analysis to build the new expression. |
| 1313 | /// Subclasses may override this routine to provide different behavior. |
| 1314 | ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) { |
| 1315 | return getSema().BuildCoawaitExpr(CoawaitLoc, Result); |
| 1316 | } |
| 1317 | |
| 1318 | /// \brief Build a new co_yield expression. |
| 1319 | /// |
| 1320 | /// By default, performs semantic analysis to build the new expression. |
| 1321 | /// Subclasses may override this routine to provide different behavior. |
| 1322 | ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) { |
| 1323 | return getSema().BuildCoyieldExpr(CoyieldLoc, Result); |
| 1324 | } |
| 1325 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1326 | /// \brief Build a new Objective-C \@try 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 RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1331 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1332 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1333 | Stmt *Finally) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1334 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1335 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1338 | /// \brief Rebuild an Objective-C exception declaration. |
| 1339 | /// |
| 1340 | /// By default, performs semantic analysis to build the new declaration. |
| 1341 | /// Subclasses may override this routine to provide different behavior. |
| 1342 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1343 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1344 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1345 | ExceptionDecl->getInnerLocStart(), |
| 1346 | ExceptionDecl->getLocation(), |
| 1347 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1348 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1349 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1350 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1351 | /// |
| 1352 | /// By default, performs semantic analysis to build the new statement. |
| 1353 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1354 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1355 | SourceLocation RParenLoc, |
| 1356 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1357 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1358 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1359 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1360 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1361 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1362 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1363 | /// |
| 1364 | /// By default, performs semantic analysis to build the new statement. |
| 1365 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1366 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1367 | Stmt *Body) { |
| 1368 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1369 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1370 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1371 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1372 | /// |
| 1373 | /// By default, performs semantic analysis to build the new statement. |
| 1374 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1375 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1376 | Expr *Operand) { |
| 1377 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1378 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1379 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1380 | /// \brief Build a new OpenMP executable directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1381 | /// |
| 1382 | /// By default, performs semantic analysis to build the new statement. |
| 1383 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1384 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1385 | DeclarationNameInfo DirName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1386 | OpenMPDirectiveKind CancelRegion, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1387 | ArrayRef<OMPClause *> Clauses, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1388 | Stmt *AStmt, SourceLocation StartLoc, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1389 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1390 | return getSema().ActOnOpenMPExecutableDirective( |
| 1391 | Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1392 | } |
| 1393 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1394 | /// \brief Build a new OpenMP 'if' clause. |
| 1395 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1396 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1397 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1398 | OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, |
| 1399 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1400 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1401 | SourceLocation NameModifierLoc, |
| 1402 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1403 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1404 | return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc, |
| 1405 | LParenLoc, NameModifierLoc, ColonLoc, |
| 1406 | EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1409 | /// \brief Build a new OpenMP 'final' clause. |
| 1410 | /// |
| 1411 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1412 | /// Subclasses may override this routine to provide different behavior. |
| 1413 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1414 | SourceLocation LParenLoc, |
| 1415 | SourceLocation EndLoc) { |
| 1416 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
| 1417 | EndLoc); |
| 1418 | } |
| 1419 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1420 | /// \brief Build a new OpenMP 'num_threads' clause. |
| 1421 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1422 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1423 | /// Subclasses may override this routine to provide different behavior. |
| 1424 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
| 1425 | SourceLocation StartLoc, |
| 1426 | SourceLocation LParenLoc, |
| 1427 | SourceLocation EndLoc) { |
| 1428 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
| 1429 | LParenLoc, EndLoc); |
| 1430 | } |
| 1431 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1432 | /// \brief Build a new OpenMP 'safelen' clause. |
| 1433 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1434 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1435 | /// Subclasses may override this routine to provide different behavior. |
| 1436 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1437 | SourceLocation LParenLoc, |
| 1438 | SourceLocation EndLoc) { |
| 1439 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1440 | } |
| 1441 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1442 | /// \brief Build a new OpenMP 'simdlen' clause. |
| 1443 | /// |
| 1444 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1445 | /// Subclasses may override this routine to provide different behavior. |
| 1446 | OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 1447 | SourceLocation LParenLoc, |
| 1448 | SourceLocation EndLoc) { |
| 1449 | return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1450 | } |
| 1451 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1452 | /// \brief Build a new OpenMP 'collapse' clause. |
| 1453 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1454 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1455 | /// Subclasses may override this routine to provide different behavior. |
| 1456 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1457 | SourceLocation LParenLoc, |
| 1458 | SourceLocation EndLoc) { |
| 1459 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
| 1460 | EndLoc); |
| 1461 | } |
| 1462 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1463 | /// \brief Build a new OpenMP 'default' clause. |
| 1464 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1465 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1466 | /// Subclasses may override this routine to provide different behavior. |
| 1467 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1468 | SourceLocation KindKwLoc, |
| 1469 | SourceLocation StartLoc, |
| 1470 | SourceLocation LParenLoc, |
| 1471 | SourceLocation EndLoc) { |
| 1472 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1473 | StartLoc, LParenLoc, EndLoc); |
| 1474 | } |
| 1475 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1476 | /// \brief Build a new OpenMP 'proc_bind' clause. |
| 1477 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1478 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1479 | /// Subclasses may override this routine to provide different behavior. |
| 1480 | OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 1481 | SourceLocation KindKwLoc, |
| 1482 | SourceLocation StartLoc, |
| 1483 | SourceLocation LParenLoc, |
| 1484 | SourceLocation EndLoc) { |
| 1485 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
| 1486 | StartLoc, LParenLoc, EndLoc); |
| 1487 | } |
| 1488 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1489 | /// \brief Build a new OpenMP 'schedule' clause. |
| 1490 | /// |
| 1491 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1492 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1493 | OMPClause *RebuildOMPScheduleClause( |
| 1494 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| 1495 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 1496 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 1497 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1498 | return getSema().ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1499 | M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc, |
| 1500 | CommaLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1503 | /// \brief Build a new OpenMP 'ordered' clause. |
| 1504 | /// |
| 1505 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1506 | /// Subclasses may override this routine to provide different behavior. |
| 1507 | OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, |
| 1508 | SourceLocation EndLoc, |
| 1509 | SourceLocation LParenLoc, Expr *Num) { |
| 1510 | return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); |
| 1511 | } |
| 1512 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1513 | /// \brief Build a new OpenMP 'private' clause. |
| 1514 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1515 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1516 | /// Subclasses may override this routine to provide different behavior. |
| 1517 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1518 | SourceLocation StartLoc, |
| 1519 | SourceLocation LParenLoc, |
| 1520 | SourceLocation EndLoc) { |
| 1521 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1522 | EndLoc); |
| 1523 | } |
| 1524 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1525 | /// \brief Build a new OpenMP 'firstprivate' clause. |
| 1526 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1527 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1528 | /// Subclasses may override this routine to provide different behavior. |
| 1529 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1530 | SourceLocation StartLoc, |
| 1531 | SourceLocation LParenLoc, |
| 1532 | SourceLocation EndLoc) { |
| 1533 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1534 | EndLoc); |
| 1535 | } |
| 1536 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1537 | /// \brief Build a new OpenMP 'lastprivate' clause. |
| 1538 | /// |
| 1539 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1540 | /// Subclasses may override this routine to provide different behavior. |
| 1541 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1542 | SourceLocation StartLoc, |
| 1543 | SourceLocation LParenLoc, |
| 1544 | SourceLocation EndLoc) { |
| 1545 | return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, |
| 1546 | EndLoc); |
| 1547 | } |
| 1548 | |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1549 | /// \brief Build a new OpenMP 'shared' clause. |
| 1550 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1551 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1552 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1553 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1554 | SourceLocation StartLoc, |
| 1555 | SourceLocation LParenLoc, |
| 1556 | SourceLocation EndLoc) { |
| 1557 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1558 | EndLoc); |
| 1559 | } |
| 1560 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1561 | /// \brief Build a new OpenMP 'reduction' clause. |
| 1562 | /// |
| 1563 | /// By default, performs semantic analysis to build the new statement. |
| 1564 | /// Subclasses may override this routine to provide different behavior. |
| 1565 | OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList, |
| 1566 | SourceLocation StartLoc, |
| 1567 | SourceLocation LParenLoc, |
| 1568 | SourceLocation ColonLoc, |
| 1569 | SourceLocation EndLoc, |
| 1570 | CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 1571 | const DeclarationNameInfo &ReductionId, |
| 1572 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1573 | return getSema().ActOnOpenMPReductionClause( |
| 1574 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 1575 | ReductionId, UnresolvedReductions); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1578 | /// \brief Build a new OpenMP 'linear' clause. |
| 1579 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1580 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1581 | /// Subclasses may override this routine to provide different behavior. |
| 1582 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1583 | SourceLocation StartLoc, |
| 1584 | SourceLocation LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1585 | OpenMPLinearClauseKind Modifier, |
| 1586 | SourceLocation ModifierLoc, |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1587 | SourceLocation ColonLoc, |
| 1588 | SourceLocation EndLoc) { |
| 1589 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1590 | Modifier, ModifierLoc, ColonLoc, |
| 1591 | EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1594 | /// \brief Build a new OpenMP 'aligned' clause. |
| 1595 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1596 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1597 | /// Subclasses may override this routine to provide different behavior. |
| 1598 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 1599 | SourceLocation StartLoc, |
| 1600 | SourceLocation LParenLoc, |
| 1601 | SourceLocation ColonLoc, |
| 1602 | SourceLocation EndLoc) { |
| 1603 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
| 1604 | LParenLoc, ColonLoc, EndLoc); |
| 1605 | } |
| 1606 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1607 | /// \brief Build a new OpenMP 'copyin' clause. |
| 1608 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1609 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1610 | /// Subclasses may override this routine to provide different behavior. |
| 1611 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1612 | SourceLocation StartLoc, |
| 1613 | SourceLocation LParenLoc, |
| 1614 | SourceLocation EndLoc) { |
| 1615 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
| 1616 | EndLoc); |
| 1617 | } |
| 1618 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1619 | /// \brief Build a new OpenMP 'copyprivate' clause. |
| 1620 | /// |
| 1621 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1622 | /// Subclasses may override this routine to provide different behavior. |
| 1623 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 1624 | SourceLocation StartLoc, |
| 1625 | SourceLocation LParenLoc, |
| 1626 | SourceLocation EndLoc) { |
| 1627 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
| 1628 | EndLoc); |
| 1629 | } |
| 1630 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1631 | /// \brief Build a new OpenMP 'flush' pseudo clause. |
| 1632 | /// |
| 1633 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1634 | /// Subclasses may override this routine to provide different behavior. |
| 1635 | OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
| 1636 | SourceLocation StartLoc, |
| 1637 | SourceLocation LParenLoc, |
| 1638 | SourceLocation EndLoc) { |
| 1639 | return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, |
| 1640 | EndLoc); |
| 1641 | } |
| 1642 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1643 | /// \brief Build a new OpenMP 'depend' pseudo clause. |
| 1644 | /// |
| 1645 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1646 | /// Subclasses may override this routine to provide different behavior. |
| 1647 | OMPClause * |
| 1648 | RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc, |
| 1649 | SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 1650 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1651 | SourceLocation EndLoc) { |
| 1652 | return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList, |
| 1653 | StartLoc, LParenLoc, EndLoc); |
| 1654 | } |
| 1655 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1656 | /// \brief Build a new OpenMP 'device' clause. |
| 1657 | /// |
| 1658 | /// By default, performs semantic analysis to build the new statement. |
| 1659 | /// Subclasses may override this routine to provide different behavior. |
| 1660 | OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 1661 | SourceLocation LParenLoc, |
| 1662 | SourceLocation EndLoc) { |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1663 | return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc, |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1664 | EndLoc); |
| 1665 | } |
| 1666 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1667 | /// \brief Build a new OpenMP 'map' clause. |
| 1668 | /// |
| 1669 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1670 | /// Subclasses may override this routine to provide different behavior. |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1671 | OMPClause * |
| 1672 | RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 1673 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 1674 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 1675 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1676 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 1677 | return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, |
| 1678 | IsMapTypeImplicit, MapLoc, ColonLoc, |
| 1679 | VarList, StartLoc, LParenLoc, EndLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1682 | /// \brief Build a new OpenMP 'num_teams' clause. |
| 1683 | /// |
| 1684 | /// By default, performs semantic analysis to build the new statement. |
| 1685 | /// Subclasses may override this routine to provide different behavior. |
| 1686 | OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
| 1687 | SourceLocation LParenLoc, |
| 1688 | SourceLocation EndLoc) { |
| 1689 | return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc, |
| 1690 | EndLoc); |
| 1691 | } |
| 1692 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1693 | /// \brief Build a new OpenMP 'thread_limit' clause. |
| 1694 | /// |
| 1695 | /// By default, performs semantic analysis to build the new statement. |
| 1696 | /// Subclasses may override this routine to provide different behavior. |
| 1697 | OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit, |
| 1698 | SourceLocation StartLoc, |
| 1699 | SourceLocation LParenLoc, |
| 1700 | SourceLocation EndLoc) { |
| 1701 | return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc, |
| 1702 | LParenLoc, EndLoc); |
| 1703 | } |
| 1704 | |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1705 | /// \brief Build a new OpenMP 'priority' clause. |
| 1706 | /// |
| 1707 | /// By default, performs semantic analysis to build the new statement. |
| 1708 | /// Subclasses may override this routine to provide different behavior. |
| 1709 | OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
| 1710 | SourceLocation LParenLoc, |
| 1711 | SourceLocation EndLoc) { |
| 1712 | return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc, |
| 1713 | EndLoc); |
| 1714 | } |
| 1715 | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1716 | /// \brief Build a new OpenMP 'grainsize' clause. |
| 1717 | /// |
| 1718 | /// By default, performs semantic analysis to build the new statement. |
| 1719 | /// Subclasses may override this routine to provide different behavior. |
| 1720 | OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc, |
| 1721 | SourceLocation LParenLoc, |
| 1722 | SourceLocation EndLoc) { |
| 1723 | return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc, |
| 1724 | EndLoc); |
| 1725 | } |
| 1726 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1727 | /// \brief Build a new OpenMP 'num_tasks' clause. |
| 1728 | /// |
| 1729 | /// By default, performs semantic analysis to build the new statement. |
| 1730 | /// Subclasses may override this routine to provide different behavior. |
| 1731 | OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, |
| 1732 | SourceLocation LParenLoc, |
| 1733 | SourceLocation EndLoc) { |
| 1734 | return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc, |
| 1735 | EndLoc); |
| 1736 | } |
| 1737 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1738 | /// \brief Build a new OpenMP 'hint' clause. |
| 1739 | /// |
| 1740 | /// By default, performs semantic analysis to build the new statement. |
| 1741 | /// Subclasses may override this routine to provide different behavior. |
| 1742 | OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 1743 | SourceLocation LParenLoc, |
| 1744 | SourceLocation EndLoc) { |
| 1745 | return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc); |
| 1746 | } |
| 1747 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1748 | /// \brief Build a new OpenMP 'dist_schedule' clause. |
| 1749 | /// |
| 1750 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1751 | /// Subclasses may override this routine to provide different behavior. |
| 1752 | OMPClause * |
| 1753 | RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, |
| 1754 | Expr *ChunkSize, SourceLocation StartLoc, |
| 1755 | SourceLocation LParenLoc, SourceLocation KindLoc, |
| 1756 | SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 1757 | return getSema().ActOnOpenMPDistScheduleClause( |
| 1758 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 1759 | } |
| 1760 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 1761 | /// \brief Build a new OpenMP 'to' clause. |
| 1762 | /// |
| 1763 | /// By default, performs semantic analysis to build the new statement. |
| 1764 | /// Subclasses may override this routine to provide different behavior. |
| 1765 | OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList, |
| 1766 | SourceLocation StartLoc, |
| 1767 | SourceLocation LParenLoc, |
| 1768 | SourceLocation EndLoc) { |
| 1769 | return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 1770 | } |
| 1771 | |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1772 | /// \brief Build a new OpenMP 'from' clause. |
| 1773 | /// |
| 1774 | /// By default, performs semantic analysis to build the new statement. |
| 1775 | /// Subclasses may override this routine to provide different behavior. |
| 1776 | OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList, |
| 1777 | SourceLocation StartLoc, |
| 1778 | SourceLocation LParenLoc, |
| 1779 | SourceLocation EndLoc) { |
| 1780 | return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, |
| 1781 | EndLoc); |
| 1782 | } |
| 1783 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1784 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1785 | /// |
| 1786 | /// By default, performs semantic analysis to build the new statement. |
| 1787 | /// Subclasses may override this routine to provide different behavior. |
| 1788 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1789 | Expr *object) { |
| 1790 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1791 | } |
| 1792 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1793 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1794 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1795 | /// By default, performs semantic analysis to build the new statement. |
| 1796 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1797 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1798 | Expr *Object, Stmt *Body) { |
| 1799 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1800 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1801 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1802 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1803 | /// |
| 1804 | /// By default, performs semantic analysis to build the new statement. |
| 1805 | /// Subclasses may override this routine to provide different behavior. |
| 1806 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1807 | Stmt *Body) { |
| 1808 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1809 | } |
John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1810 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1811 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1812 | /// |
| 1813 | /// By default, performs semantic analysis to build the new statement. |
| 1814 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1815 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1816 | Stmt *Element, |
| 1817 | Expr *Collection, |
| 1818 | SourceLocation RParenLoc, |
| 1819 | Stmt *Body) { |
Sam Panzer | 2c4ca0f | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1820 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1821 | Element, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1822 | Collection, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1823 | RParenLoc); |
| 1824 | if (ForEachStmt.isInvalid()) |
| 1825 | return StmtError(); |
| 1826 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1827 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1828 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1829 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1830 | /// \brief Build a new C++ exception declaration. |
| 1831 | /// |
| 1832 | /// By default, performs semantic analysis to build the new decaration. |
| 1833 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1834 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1835 | TypeSourceInfo *Declarator, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1836 | SourceLocation StartLoc, |
| 1837 | SourceLocation IdLoc, |
| 1838 | IdentifierInfo *Id) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1839 | VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1840 | StartLoc, IdLoc, Id); |
| 1841 | if (Var) |
| 1842 | getSema().CurContext->addDecl(Var); |
| 1843 | return Var; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | /// \brief Build a new C++ catch statement. |
| 1847 | /// |
| 1848 | /// By default, performs semantic analysis to build the new statement. |
| 1849 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1850 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1851 | VarDecl *ExceptionDecl, |
| 1852 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1853 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1854 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1856 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1857 | /// \brief Build a new C++ try statement. |
| 1858 | /// |
| 1859 | /// By default, performs semantic analysis to build the new statement. |
| 1860 | /// Subclasses may override this routine to provide different behavior. |
Robert Wilhelm | cafda82 | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 1861 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 1862 | ArrayRef<Stmt *> Handlers) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1863 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1864 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1866 | /// \brief Build a new C++0x range-based for statement. |
| 1867 | /// |
| 1868 | /// By default, performs semantic analysis to build the new statement. |
| 1869 | /// Subclasses may override this routine to provide different behavior. |
| 1870 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1871 | SourceLocation CoawaitLoc, |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1872 | SourceLocation ColonLoc, |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 1873 | Stmt *Range, Stmt *Begin, Stmt *End, |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1874 | Expr *Cond, Expr *Inc, |
| 1875 | Stmt *LoopVar, |
| 1876 | SourceLocation RParenLoc) { |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1877 | // If we've just learned that the range is actually an Objective-C |
| 1878 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1879 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1880 | if (RangeStmt->isSingleDecl()) { |
| 1881 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1882 | if (RangeVar->isInvalidDecl()) |
| 1883 | return StmtError(); |
| 1884 | |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1885 | Expr *RangeExpr = RangeVar->getInit(); |
| 1886 | if (!RangeExpr->isTypeDependent() && |
| 1887 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1888 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1889 | RParenLoc); |
| 1890 | } |
| 1891 | } |
| 1892 | } |
| 1893 | |
Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 1894 | return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc, |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 1895 | Range, Begin, End, |
Richard Smith | a05b3b5 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1896 | Cond, Inc, LoopVar, RParenLoc, |
| 1897 | Sema::BFRK_Rebuild); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1898 | } |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1899 | |
| 1900 | /// \brief Build a new C++0x range-based for statement. |
| 1901 | /// |
| 1902 | /// By default, performs semantic analysis to build the new statement. |
| 1903 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1904 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1905 | bool IsIfExists, |
| 1906 | NestedNameSpecifierLoc QualifierLoc, |
| 1907 | DeclarationNameInfo NameInfo, |
| 1908 | Stmt *Nested) { |
| 1909 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1910 | QualifierLoc, NameInfo, Nested); |
| 1911 | } |
| 1912 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1913 | /// \brief Attach body to a C++0x range-based for statement. |
| 1914 | /// |
| 1915 | /// By default, performs semantic analysis to finish the new statement. |
| 1916 | /// Subclasses may override this routine to provide different behavior. |
| 1917 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1918 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1919 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1920 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1921 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1922 | Stmt *TryBlock, Stmt *Handler) { |
| 1923 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1926 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1927 | Stmt *Block) { |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1928 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1931 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
Nico Weber | d64657f | 2015-03-09 02:47:59 +0000 | [diff] [blame] | 1932 | return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 1935 | /// \brief Build a new predefined expression. |
| 1936 | /// |
| 1937 | /// By default, performs semantic analysis to build the new expression. |
| 1938 | /// Subclasses may override this routine to provide different behavior. |
| 1939 | ExprResult RebuildPredefinedExpr(SourceLocation Loc, |
| 1940 | PredefinedExpr::IdentType IT) { |
| 1941 | return getSema().BuildPredefinedExpr(Loc, IT); |
| 1942 | } |
| 1943 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1944 | /// \brief Build a new expression that references a declaration. |
| 1945 | /// |
| 1946 | /// By default, performs semantic analysis to build the new expression. |
| 1947 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1948 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1949 | LookupResult &R, |
| 1950 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1951 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1952 | } |
| 1953 | |
| 1954 | |
| 1955 | /// \brief Build a new expression that references a declaration. |
| 1956 | /// |
| 1957 | /// By default, performs semantic analysis to build the new expression. |
| 1958 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1959 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1960 | ValueDecl *VD, |
| 1961 | const DeclarationNameInfo &NameInfo, |
| 1962 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1963 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1964 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1965 | |
| 1966 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1967 | |
| 1968 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1969 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1970 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1971 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1973 | /// By default, performs semantic analysis to build the new expression. |
| 1974 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1975 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1976 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1977 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1980 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1981 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1982 | /// By default, performs semantic analysis to build the new expression. |
| 1983 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1984 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1985 | SourceLocation OperatorLoc, |
| 1986 | bool isArrow, |
| 1987 | CXXScopeSpec &SS, |
| 1988 | TypeSourceInfo *ScopeType, |
| 1989 | SourceLocation CCLoc, |
| 1990 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1991 | PseudoDestructorTypeStorage Destroyed); |
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 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1994 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1995 | /// By default, performs semantic analysis to build the new expression. |
| 1996 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1997 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1998 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1999 | Expr *SubExpr) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2000 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2001 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2002 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2003 | /// \brief Build a new builtin offsetof expression. |
| 2004 | /// |
| 2005 | /// By default, performs semantic analysis to build the new expression. |
| 2006 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2007 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 2008 | TypeSourceInfo *Type, |
| 2009 | ArrayRef<Sema::OffsetOfComponent> Components, |
| 2010 | SourceLocation RParenLoc) { |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2011 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 2012 | RParenLoc); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2013 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2014 | |
| 2015 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2016 | /// type argument. |
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. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2020 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 2021 | SourceLocation OpLoc, |
| 2022 | UnaryExprOrTypeTrait ExprKind, |
| 2023 | SourceRange R) { |
| 2024 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2027 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 2028 | /// expression argument. |
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. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2032 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 2033 | UnaryExprOrTypeTrait ExprKind, |
| 2034 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2035 | ExprResult Result |
Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 2036 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2037 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2038 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2039 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2040 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2041 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2042 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2043 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2045 | /// By default, performs semantic analysis to build the new expression. |
| 2046 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2047 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2048 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2049 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2050 | SourceLocation RBracketLoc) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2051 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2052 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2053 | RBracketLoc); |
| 2054 | } |
| 2055 | |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 2056 | /// \brief Build a new array section expression. |
| 2057 | /// |
| 2058 | /// By default, performs semantic analysis to build the new expression. |
| 2059 | /// Subclasses may override this routine to provide different behavior. |
| 2060 | ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, |
| 2061 | Expr *LowerBound, |
| 2062 | SourceLocation ColonLoc, Expr *Length, |
| 2063 | SourceLocation RBracketLoc) { |
| 2064 | return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound, |
| 2065 | ColonLoc, Length, RBracketLoc); |
| 2066 | } |
| 2067 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2068 | /// \brief Build a new call 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 RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2073 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 2074 | SourceLocation RParenLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2075 | Expr *ExecConfig = nullptr) { |
| 2076 | return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2077 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2081 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2082 | /// By default, performs semantic analysis to build the new expression. |
| 2083 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2084 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2085 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2086 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2087 | SourceLocation TemplateKWLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2088 | const DeclarationNameInfo &MemberNameInfo, |
| 2089 | ValueDecl *Member, |
| 2090 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2091 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2092 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2093 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 2094 | isArrow); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 2095 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2096 | // We have a reference to an unnamed field. This is always the |
| 2097 | // base of an anonymous struct/union member access, i.e. the |
| 2098 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2099 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2100 | assert(Member->getType()->isRecordType() && |
| 2101 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2102 | |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2103 | BaseResult = |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2104 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2105 | QualifierLoc.getNestedNameSpecifier(), |
| 2106 | FoundDecl, Member); |
| 2107 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2108 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2109 | Base = BaseResult.get(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2110 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Aaron Ballman | f4cb2be | 2015-03-24 15:07:53 +0000 | [diff] [blame] | 2111 | MemberExpr *ME = new (getSema().Context) |
| 2112 | MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo, |
| 2113 | cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2114 | return ME; |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 2115 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2116 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 2117 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2118 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 2119 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2120 | Base = BaseResult.get(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2121 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2122 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 2123 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 2124 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2125 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 2126 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2127 | R.resolveKind(); |
| 2128 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2129 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2130 | SS, TemplateKWLoc, |
| 2131 | FirstQualifierInScope, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2132 | R, ExplicitTemplateArgs, |
| 2133 | /*S*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2135 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2136 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2137 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2138 | /// By default, performs semantic analysis to build the new expression. |
| 2139 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2140 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2141 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2142 | Expr *LHS, Expr *RHS) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2143 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2148 | /// By default, performs semantic analysis to build the new expression. |
| 2149 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2150 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 2151 | SourceLocation QuestionLoc, |
| 2152 | Expr *LHS, |
| 2153 | SourceLocation ColonLoc, |
| 2154 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2155 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 2156 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2159 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2161 | /// By default, performs semantic analysis to build the new expression. |
| 2162 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2163 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2164 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2165 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2166 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 2167 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2168 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2169 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2170 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2171 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2172 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2173 | /// By default, performs semantic analysis to build the new expression. |
| 2174 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2175 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 2176 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2177 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2178 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 2179 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2180 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2181 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2182 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2183 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2184 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2185 | /// By default, performs semantic analysis to build the new expression. |
| 2186 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2187 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2188 | SourceLocation OpLoc, |
| 2189 | SourceLocation AccessorLoc, |
| 2190 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2191 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2192 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2193 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2194 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2195 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2196 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2197 | /*FirstQualifierInScope*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2198 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2199 | /* TemplateArgs */ nullptr, |
| 2200 | /*S*/ nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2202 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2203 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2204 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2205 | /// By default, performs semantic analysis to build the new expression. |
| 2206 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2207 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2208 | MultiExprArg Inits, |
| 2209 | SourceLocation RBraceLoc, |
| 2210 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2211 | ExprResult Result |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2212 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 2213 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2214 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2215 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 2216 | // Patch in the result type we were given, which may have been computed |
| 2217 | // when the initial InitListExpr was built. |
| 2218 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 2219 | ILE->setType(ResultTy); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2220 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2221 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2222 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2223 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2224 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2225 | /// By default, performs semantic analysis to build the new expression. |
| 2226 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2227 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2228 | MultiExprArg ArrayExprs, |
| 2229 | SourceLocation EqualOrColonLoc, |
| 2230 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2231 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2232 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2233 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2234 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2235 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2236 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2237 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2238 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2239 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2240 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2241 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2242 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2243 | /// By default, builds the implicit value initialization without performing |
| 2244 | /// any semantic analysis. Subclasses may override this routine to provide |
| 2245 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2246 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2247 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2249 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2250 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2251 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2252 | /// By default, performs semantic analysis to build the new expression. |
| 2253 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2254 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2255 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2256 | SourceLocation RParenLoc) { |
| 2257 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2258 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2259 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2263 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2264 | /// By default, performs semantic analysis to build the new expression. |
| 2265 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2266 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 2267 | MultiExprArg SubExprs, |
| 2268 | SourceLocation RParenLoc) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2269 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2270 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2271 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2272 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2273 | /// |
| 2274 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2275 | /// rather than attempting to map the label statement itself. |
| 2276 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2277 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 2278 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2279 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2280 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2281 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2282 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2283 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2284 | /// By default, performs semantic analysis to build the new expression. |
| 2285 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2286 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2287 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2288 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2289 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2290 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2291 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2292 | /// \brief Build a new __builtin_choose_expr expression. |
| 2293 | /// |
| 2294 | /// By default, performs semantic analysis to build the new expression. |
| 2295 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2296 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2297 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2298 | SourceLocation RParenLoc) { |
| 2299 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2300 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2301 | RParenLoc); |
| 2302 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2303 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2304 | /// \brief Build a new generic selection expression. |
| 2305 | /// |
| 2306 | /// By default, performs semantic analysis to build the new expression. |
| 2307 | /// Subclasses may override this routine to provide different behavior. |
| 2308 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2309 | SourceLocation DefaultLoc, |
| 2310 | SourceLocation RParenLoc, |
| 2311 | Expr *ControllingExpr, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2312 | ArrayRef<TypeSourceInfo *> Types, |
| 2313 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2314 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2315 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2318 | /// \brief Build a new overloaded operator call expression. |
| 2319 | /// |
| 2320 | /// By default, performs semantic analysis to build the new expression. |
| 2321 | /// The semantic analysis provides the behavior of template instantiation, |
| 2322 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2323 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2324 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2325 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2326 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2327 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2328 | Expr *Callee, |
| 2329 | Expr *First, |
| 2330 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2331 | |
| 2332 | /// \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] | 2333 | /// reinterpret_cast. |
| 2334 | /// |
| 2335 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2336 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2337 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2338 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2339 | Stmt::StmtClass Class, |
| 2340 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2341 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2342 | SourceLocation RAngleLoc, |
| 2343 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2344 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2345 | SourceLocation RParenLoc) { |
| 2346 | switch (Class) { |
| 2347 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2348 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2349 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2350 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2351 | |
| 2352 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2353 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2354 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2355 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2356 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2357 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2358 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2359 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2360 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2361 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2362 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2363 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2364 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2365 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2366 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2367 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2368 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2369 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2370 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2371 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2372 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2373 | /// \brief Build a new C++ static_cast expression. |
| 2374 | /// |
| 2375 | /// By default, performs semantic analysis to build the new expression. |
| 2376 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2377 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2378 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2379 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2380 | SourceLocation RAngleLoc, |
| 2381 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2382 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2383 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2384 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2385 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2386 | SourceRange(LAngleLoc, RAngleLoc), |
| 2387 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | /// \brief Build a new C++ dynamic_cast expression. |
| 2391 | /// |
| 2392 | /// By default, performs semantic analysis to build the new expression. |
| 2393 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2394 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2395 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2396 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2397 | SourceLocation RAngleLoc, |
| 2398 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2399 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2400 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2401 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2402 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2403 | SourceRange(LAngleLoc, RAngleLoc), |
| 2404 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | /// \brief Build a new C++ reinterpret_cast expression. |
| 2408 | /// |
| 2409 | /// By default, performs semantic analysis to build the new expression. |
| 2410 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2411 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2412 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2413 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2414 | SourceLocation RAngleLoc, |
| 2415 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2416 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2417 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2418 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2419 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2420 | SourceRange(LAngleLoc, RAngleLoc), |
| 2421 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | /// \brief Build a new C++ const_cast expression. |
| 2425 | /// |
| 2426 | /// By default, performs semantic analysis to build the new expression. |
| 2427 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2428 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2429 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2430 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2431 | SourceLocation RAngleLoc, |
| 2432 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2433 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2434 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2435 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2436 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2437 | SourceRange(LAngleLoc, RAngleLoc), |
| 2438 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2439 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2440 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2441 | /// \brief Build a new C++ functional-style cast expression. |
| 2442 | /// |
| 2443 | /// By default, performs semantic analysis to build the new expression. |
| 2444 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2445 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2446 | SourceLocation LParenLoc, |
| 2447 | Expr *Sub, |
| 2448 | SourceLocation RParenLoc) { |
| 2449 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2450 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2451 | RParenLoc); |
| 2452 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2453 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2454 | /// \brief Build a new C++ typeid(type) expression. |
| 2455 | /// |
| 2456 | /// By default, performs semantic analysis to build the new expression. |
| 2457 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2458 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2459 | SourceLocation TypeidLoc, |
| 2460 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2461 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2462 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2463 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2465 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2466 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2467 | /// \brief Build a new C++ typeid(expr) expression. |
| 2468 | /// |
| 2469 | /// By default, performs semantic analysis to build the new expression. |
| 2470 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2471 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2472 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2473 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2474 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2475 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2476 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2479 | /// \brief Build a new C++ __uuidof(type) expression. |
| 2480 | /// |
| 2481 | /// By default, performs semantic analysis to build the new expression. |
| 2482 | /// Subclasses may override this routine to provide different behavior. |
| 2483 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2484 | SourceLocation TypeidLoc, |
| 2485 | TypeSourceInfo *Operand, |
| 2486 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2487 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2488 | RParenLoc); |
| 2489 | } |
| 2490 | |
| 2491 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2492 | /// |
| 2493 | /// By default, performs semantic analysis to build the new expression. |
| 2494 | /// Subclasses may override this routine to provide different behavior. |
| 2495 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2496 | SourceLocation TypeidLoc, |
| 2497 | Expr *Operand, |
| 2498 | SourceLocation RParenLoc) { |
| 2499 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2500 | RParenLoc); |
| 2501 | } |
| 2502 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2503 | /// \brief Build a new C++ "this" expression. |
| 2504 | /// |
| 2505 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2506 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2507 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2508 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2509 | QualType ThisType, |
| 2510 | bool isImplicit) { |
Eli Friedman | 20139d3 | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2511 | getSema().CheckCXXThisCapture(ThisLoc); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2512 | return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | /// \brief Build a new C++ throw expression. |
| 2516 | /// |
| 2517 | /// By default, performs semantic analysis to build the new expression. |
| 2518 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2519 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2520 | bool IsThrownVariableInScope) { |
| 2521 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | /// \brief Build a new C++ default-argument expression. |
| 2525 | /// |
| 2526 | /// By default, builds a new default-argument expression, which does not |
| 2527 | /// require any semantic analysis. Subclasses may override this routine to |
| 2528 | /// provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2529 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2530 | ParmVarDecl *Param) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2531 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2534 | /// \brief Build a new C++11 default-initialization expression. |
| 2535 | /// |
| 2536 | /// By default, builds a new default field initialization expression, which |
| 2537 | /// does not require any semantic analysis. Subclasses may override this |
| 2538 | /// routine to provide different behavior. |
| 2539 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2540 | FieldDecl *Field) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2541 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field); |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2544 | /// \brief Build a new C++ zero-initialization expression. |
| 2545 | /// |
| 2546 | /// By default, performs semantic analysis to build the new expression. |
| 2547 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2548 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2549 | SourceLocation LParenLoc, |
| 2550 | SourceLocation RParenLoc) { |
| 2551 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2552 | None, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2553 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2554 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2555 | /// \brief Build a new C++ "new" expression. |
| 2556 | /// |
| 2557 | /// By default, performs semantic analysis to build the new expression. |
| 2558 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2559 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2560 | bool UseGlobal, |
| 2561 | SourceLocation PlacementLParen, |
| 2562 | MultiExprArg PlacementArgs, |
| 2563 | SourceLocation PlacementRParen, |
| 2564 | SourceRange TypeIdParens, |
| 2565 | QualType AllocatedType, |
| 2566 | TypeSourceInfo *AllocatedTypeInfo, |
| 2567 | Expr *ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2568 | SourceRange DirectInitRange, |
| 2569 | Expr *Initializer) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2570 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2571 | PlacementLParen, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2572 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2573 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2574 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2575 | AllocatedType, |
| 2576 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2577 | ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2578 | DirectInitRange, |
| 2579 | Initializer); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2580 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2582 | /// \brief Build a new C++ "delete" expression. |
| 2583 | /// |
| 2584 | /// By default, performs semantic analysis to build the new expression. |
| 2585 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2586 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2587 | bool IsGlobalDelete, |
| 2588 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2589 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2590 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2591 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2593 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2594 | /// \brief Build a new type trait expression. |
| 2595 | /// |
| 2596 | /// By default, performs semantic analysis to build the new expression. |
| 2597 | /// Subclasses may override this routine to provide different behavior. |
| 2598 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2599 | SourceLocation StartLoc, |
| 2600 | ArrayRef<TypeSourceInfo *> Args, |
| 2601 | SourceLocation RParenLoc) { |
| 2602 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2603 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2604 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2605 | /// \brief Build a new array type trait expression. |
| 2606 | /// |
| 2607 | /// By default, performs semantic analysis to build the new expression. |
| 2608 | /// Subclasses may override this routine to provide different behavior. |
| 2609 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2610 | SourceLocation StartLoc, |
| 2611 | TypeSourceInfo *TSInfo, |
| 2612 | Expr *DimExpr, |
| 2613 | SourceLocation RParenLoc) { |
| 2614 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2615 | } |
| 2616 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2617 | /// \brief Build a new expression trait expression. |
| 2618 | /// |
| 2619 | /// By default, performs semantic analysis to build the new expression. |
| 2620 | /// Subclasses may override this routine to provide different behavior. |
| 2621 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2622 | SourceLocation StartLoc, |
| 2623 | Expr *Queried, |
| 2624 | SourceLocation RParenLoc) { |
| 2625 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2626 | } |
| 2627 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2628 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2629 | /// expression. |
| 2630 | /// |
| 2631 | /// By default, performs semantic analysis to build the new expression. |
| 2632 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2633 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2634 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2635 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2636 | const DeclarationNameInfo &NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2637 | const TemplateArgumentListInfo *TemplateArgs, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2638 | bool IsAddressOfOperand, |
| 2639 | TypeSourceInfo **RecoveryTSI) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2640 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2641 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2642 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2643 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2644 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2645 | TemplateArgs); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2646 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2647 | return getSema().BuildQualifiedDeclarationNameExpr( |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2648 | SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | /// \brief Build a new template-id expression. |
| 2652 | /// |
| 2653 | /// By default, performs semantic analysis to build the new expression. |
| 2654 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2655 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2656 | SourceLocation TemplateKWLoc, |
| 2657 | LookupResult &R, |
| 2658 | bool RequiresADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2659 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2660 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2661 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | /// \brief Build a new object-construction expression. |
| 2665 | /// |
| 2666 | /// By default, performs semantic analysis to build the new expression. |
| 2667 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2668 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2669 | SourceLocation Loc, |
| 2670 | CXXConstructorDecl *Constructor, |
| 2671 | bool IsElidable, |
| 2672 | MultiExprArg Args, |
| 2673 | bool HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2674 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2675 | bool StdInitListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2676 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2677 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2678 | SourceRange ParenRange) { |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2679 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2680 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2681 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2682 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2683 | |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 2684 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 2685 | IsElidable, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2686 | ConvertedArgs, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2687 | HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2688 | ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2689 | StdInitListInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2690 | RequiresZeroInit, ConstructKind, |
| 2691 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 2694 | /// \brief Build a new implicit construction via inherited constructor |
| 2695 | /// expression. |
| 2696 | ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, |
| 2697 | CXXConstructorDecl *Constructor, |
| 2698 | bool ConstructsVBase, |
| 2699 | bool InheritedFromVBase) { |
| 2700 | return new (getSema().Context) CXXInheritedCtorInitExpr( |
| 2701 | Loc, T, Constructor, ConstructsVBase, InheritedFromVBase); |
| 2702 | } |
| 2703 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2704 | /// \brief Build a new object-construction expression. |
| 2705 | /// |
| 2706 | /// By default, performs semantic analysis to build the new expression. |
| 2707 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2708 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2709 | SourceLocation LParenLoc, |
| 2710 | MultiExprArg Args, |
| 2711 | SourceLocation RParenLoc) { |
| 2712 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2713 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2714 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2715 | RParenLoc); |
| 2716 | } |
| 2717 | |
| 2718 | /// \brief Build a new object-construction expression. |
| 2719 | /// |
| 2720 | /// By default, performs semantic analysis to build the new expression. |
| 2721 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2722 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2723 | SourceLocation LParenLoc, |
| 2724 | MultiExprArg Args, |
| 2725 | SourceLocation RParenLoc) { |
| 2726 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2727 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2728 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2729 | RParenLoc); |
| 2730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2731 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2732 | /// \brief Build a new member reference expression. |
| 2733 | /// |
| 2734 | /// By default, performs semantic analysis to build the new expression. |
| 2735 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2736 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2737 | QualType BaseType, |
| 2738 | bool IsArrow, |
| 2739 | SourceLocation OperatorLoc, |
| 2740 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2741 | SourceLocation TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2742 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2743 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2744 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2745 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2746 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2747 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2748 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2749 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2750 | SS, TemplateKWLoc, |
| 2751 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2752 | MemberNameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2753 | TemplateArgs, /*S*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2756 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2757 | /// |
| 2758 | /// By default, performs semantic analysis to build the new expression. |
| 2759 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2760 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2761 | SourceLocation OperatorLoc, |
| 2762 | bool IsArrow, |
| 2763 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2764 | SourceLocation TemplateKWLoc, |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2765 | NamedDecl *FirstQualifierInScope, |
| 2766 | LookupResult &R, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2767 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2768 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2769 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2770 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2771 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2772 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2773 | SS, TemplateKWLoc, |
| 2774 | FirstQualifierInScope, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2775 | R, TemplateArgs, /*S*/nullptr); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2776 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2777 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2778 | /// \brief Build a new noexcept expression. |
| 2779 | /// |
| 2780 | /// By default, performs semantic analysis to build the new expression. |
| 2781 | /// Subclasses may override this routine to provide different behavior. |
| 2782 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2783 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2784 | } |
| 2785 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2786 | /// \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] | 2787 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, |
| 2788 | NamedDecl *Pack, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2789 | SourceLocation PackLoc, |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2790 | SourceLocation RParenLoc, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 2791 | Optional<unsigned> Length, |
| 2792 | ArrayRef<TemplateArgument> PartialArgs) { |
| 2793 | return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, |
| 2794 | RParenLoc, Length, PartialArgs); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2795 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2796 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2797 | /// \brief Build a new Objective-C boxed expression. |
| 2798 | /// |
| 2799 | /// By default, performs semantic analysis to build the new expression. |
| 2800 | /// Subclasses may override this routine to provide different behavior. |
| 2801 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2802 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2803 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2804 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2805 | /// \brief Build a new Objective-C array literal. |
| 2806 | /// |
| 2807 | /// By default, performs semantic analysis to build the new expression. |
| 2808 | /// Subclasses may override this routine to provide different behavior. |
| 2809 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2810 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2811 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2812 | MultiExprArg(Elements, NumElements)); |
| 2813 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2814 | |
| 2815 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2816 | Expr *Base, Expr *Key, |
| 2817 | ObjCMethodDecl *getterMethod, |
| 2818 | ObjCMethodDecl *setterMethod) { |
| 2819 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2820 | getterMethod, setterMethod); |
| 2821 | } |
| 2822 | |
| 2823 | /// \brief Build a new Objective-C dictionary literal. |
| 2824 | /// |
| 2825 | /// By default, performs semantic analysis to build the new expression. |
| 2826 | /// Subclasses may override this routine to provide different behavior. |
| 2827 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
Craig Topper | d4336e0 | 2015-12-24 23:58:15 +0000 | [diff] [blame] | 2828 | MutableArrayRef<ObjCDictionaryElement> Elements) { |
| 2829 | return getSema().BuildObjCDictionaryLiteral(Range, Elements); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2830 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2831 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2832 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2833 | /// |
| 2834 | /// By default, performs semantic analysis to build the new expression. |
| 2835 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2836 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2837 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2838 | SourceLocation RParenLoc) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2839 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2840 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2841 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2842 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2843 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2844 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2845 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2846 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2847 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2848 | MultiExprArg Args, |
| 2849 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2850 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2851 | ReceiverTypeInfo->getType(), |
| 2852 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2853 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2854 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2858 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2859 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2860 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2861 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2862 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2863 | MultiExprArg Args, |
| 2864 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2865 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2866 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2867 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2868 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2869 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2872 | /// \brief Build a new Objective-C instance/class message to 'super'. |
| 2873 | ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, |
| 2874 | Selector Sel, |
| 2875 | ArrayRef<SourceLocation> SelectorLocs, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2876 | QualType SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2877 | ObjCMethodDecl *Method, |
| 2878 | SourceLocation LBracLoc, |
| 2879 | MultiExprArg Args, |
| 2880 | SourceLocation RBracLoc) { |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2881 | return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2882 | SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2883 | SuperLoc, |
| 2884 | Sel, Method, LBracLoc, SelectorLocs, |
| 2885 | RBracLoc, Args) |
| 2886 | : SemaRef.BuildClassMessage(nullptr, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 2887 | SuperType, |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 2888 | SuperLoc, |
| 2889 | Sel, Method, LBracLoc, SelectorLocs, |
| 2890 | RBracLoc, Args); |
| 2891 | |
| 2892 | |
| 2893 | } |
| 2894 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2895 | /// \brief Build a new Objective-C ivar reference expression. |
| 2896 | /// |
| 2897 | /// By default, performs semantic analysis to build the new expression. |
| 2898 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2899 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2900 | SourceLocation IvarLoc, |
| 2901 | bool IsArrow, bool IsFreeIvar) { |
| 2902 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2903 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2904 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| 2905 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2906 | /*FIXME:*/IvarLoc, IsArrow, |
| 2907 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2908 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2909 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2910 | /*TemplateArgs=*/nullptr, |
| 2911 | /*S=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2912 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2913 | |
| 2914 | /// \brief Build a new Objective-C property reference expression. |
| 2915 | /// |
| 2916 | /// By default, performs semantic analysis to build the new expression. |
| 2917 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2918 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2919 | ObjCPropertyDecl *Property, |
| 2920 | SourceLocation PropertyLoc) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2921 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2922 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 2923 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 2924 | /*FIXME:*/PropertyLoc, |
| 2925 | /*IsArrow=*/false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2926 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2927 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2928 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2929 | /*TemplateArgs=*/nullptr, |
| 2930 | /*S=*/nullptr); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2931 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2932 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2933 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2934 | /// |
| 2935 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2936 | /// Subclasses may override this routine to provide different behavior. |
| 2937 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2938 | ObjCMethodDecl *Getter, |
| 2939 | ObjCMethodDecl *Setter, |
| 2940 | SourceLocation PropertyLoc) { |
| 2941 | // Since these expressions can only be value-dependent, we do not |
| 2942 | // need to perform semantic analysis again. |
| 2943 | return Owned( |
| 2944 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2945 | VK_LValue, OK_ObjCProperty, |
| 2946 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2949 | /// \brief Build a new Objective-C "isa" expression. |
| 2950 | /// |
| 2951 | /// By default, performs semantic analysis to build the new expression. |
| 2952 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2953 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2954 | SourceLocation OpLoc, bool IsArrow) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2955 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2956 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 2957 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2958 | OpLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2959 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2960 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2961 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2962 | /*TemplateArgs=*/nullptr, |
| 2963 | /*S=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2964 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2965 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2966 | /// \brief Build a new shuffle vector expression. |
| 2967 | /// |
| 2968 | /// By default, performs semantic analysis to build the new expression. |
| 2969 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2970 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2971 | MultiExprArg SubExprs, |
| 2972 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2973 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2974 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2975 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2976 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2977 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2978 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2979 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2980 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2981 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2982 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2983 | SemaRef.Context.BuiltinFnTy, |
| 2984 | VK_RValue, BuiltinLoc); |
| 2985 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2986 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2987 | CK_BuiltinFnToFnPtr).get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2988 | |
| 2989 | // Build the CallExpr |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2990 | ExprResult TheCall = new (SemaRef.Context) CallExpr( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2991 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2992 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2993 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2994 | // Type-check the __builtin_shufflevector expression. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2995 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2996 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2997 | |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 2998 | /// \brief Build a new convert vector expression. |
| 2999 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 3000 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 3001 | SourceLocation RParenLoc) { |
| 3002 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 3003 | BuiltinLoc, RParenLoc); |
| 3004 | } |
| 3005 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3006 | /// \brief Build a new template argument pack expansion. |
| 3007 | /// |
| 3008 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3009 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3010 | /// different behavior. |
| 3011 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3012 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3013 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3014 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3015 | case TemplateArgument::Expression: { |
| 3016 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3017 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 3018 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3019 | if (Result.isInvalid()) |
| 3020 | return TemplateArgumentLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3021 | |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3022 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 3023 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3024 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3025 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3026 | return TemplateArgumentLoc(TemplateArgument( |
| 3027 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3028 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3029 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3030 | Pattern.getTemplateNameLoc(), |
| 3031 | EllipsisLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3032 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3033 | case TemplateArgument::Null: |
| 3034 | case TemplateArgument::Integral: |
| 3035 | case TemplateArgument::Declaration: |
| 3036 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3037 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3038 | case TemplateArgument::NullPtr: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3039 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3040 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3041 | case TemplateArgument::Type: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3042 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3043 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3044 | EllipsisLoc, |
| 3045 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3046 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 3047 | Expansion); |
| 3048 | break; |
| 3049 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3050 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3051 | return TemplateArgumentLoc(); |
| 3052 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3053 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3054 | /// \brief Build a new expression pack expansion. |
| 3055 | /// |
| 3056 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3057 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3058 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3059 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3060 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3061 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3062 | } |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3063 | |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3064 | /// \brief Build a new C++1z fold-expression. |
| 3065 | /// |
| 3066 | /// By default, performs semantic analysis in order to build a new fold |
| 3067 | /// expression. |
| 3068 | ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, |
| 3069 | BinaryOperatorKind Operator, |
| 3070 | SourceLocation EllipsisLoc, Expr *RHS, |
| 3071 | SourceLocation RParenLoc) { |
| 3072 | return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc, |
| 3073 | RHS, RParenLoc); |
| 3074 | } |
| 3075 | |
| 3076 | /// \brief Build an empty C++1z fold-expression with the given operator. |
| 3077 | /// |
| 3078 | /// By default, produces the fallback value for the fold-expression, or |
| 3079 | /// produce an error if there is no fallback value. |
| 3080 | ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 3081 | BinaryOperatorKind Operator) { |
| 3082 | return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); |
| 3083 | } |
| 3084 | |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3085 | /// \brief Build a new atomic operation expression. |
| 3086 | /// |
| 3087 | /// By default, performs semantic analysis to build the new expression. |
| 3088 | /// Subclasses may override this routine to provide different behavior. |
| 3089 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 3090 | MultiExprArg SubExprs, |
| 3091 | QualType RetTy, |
| 3092 | AtomicExpr::AtomicOp Op, |
| 3093 | SourceLocation RParenLoc) { |
| 3094 | // Just create the expression; there is not any interesting semantic |
| 3095 | // analysis here because we can't actually build an AtomicExpr until |
| 3096 | // we are sure it is semantically sound. |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 3097 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3098 | RParenLoc); |
| 3099 | } |
| 3100 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3101 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3102 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 3103 | QualType ObjectType, |
| 3104 | NamedDecl *FirstQualifierInScope, |
| 3105 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3106 | |
| 3107 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3108 | QualType ObjectType, |
| 3109 | NamedDecl *FirstQualifierInScope, |
| 3110 | CXXScopeSpec &SS); |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3111 | |
| 3112 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 3113 | NamedDecl *FirstQualifierInScope, |
| 3114 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3115 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3116 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3117 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3118 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3119 | if (!S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3120 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3121 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3122 | switch (S->getStmtClass()) { |
| 3123 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3124 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3125 | // Transform individual statement nodes |
| 3126 | #define STMT(Node, Parent) \ |
| 3127 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 3128 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3129 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3130 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3131 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3132 | // Transform expressions by calling TransformExpr. |
| 3133 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3134 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3135 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3136 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3137 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3138 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3139 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3140 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3141 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 3142 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3143 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3144 | } |
| 3145 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3146 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3147 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3148 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3149 | template<typename Derived> |
| 3150 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 3151 | if (!S) |
| 3152 | return S; |
| 3153 | |
| 3154 | switch (S->getClauseKind()) { |
| 3155 | default: break; |
| 3156 | // Transform individual clause nodes |
| 3157 | #define OPENMP_CLAUSE(Name, Class) \ |
| 3158 | case OMPC_ ## Name : \ |
| 3159 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 3160 | #include "clang/Basic/OpenMPKinds.def" |
| 3161 | } |
| 3162 | |
| 3163 | return S; |
| 3164 | } |
| 3165 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3167 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3168 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3169 | if (!E) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3170 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3171 | |
| 3172 | switch (E->getStmtClass()) { |
| 3173 | case Stmt::NoStmtClass: break; |
| 3174 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3175 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3176 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3177 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3178 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3179 | } |
| 3180 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3181 | return E; |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | template<typename Derived> |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3185 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3186 | bool NotCopyInit) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3187 | // Initializers are instantiated like expressions, except that various outer |
| 3188 | // layers are stripped. |
| 3189 | if (!Init) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3190 | return Init; |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3191 | |
| 3192 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 3193 | Init = ExprTemp->getSubExpr(); |
| 3194 | |
Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 3195 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 3196 | Init = MTE->GetTemporaryExpr(); |
| 3197 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3198 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 3199 | Init = Binder->getSubExpr(); |
| 3200 | |
| 3201 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 3202 | Init = ICE->getSubExprAsWritten(); |
| 3203 | |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3204 | if (CXXStdInitializerListExpr *ILE = |
| 3205 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3206 | return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3207 | |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3208 | // If this is copy-initialization, we only need to reconstruct |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3209 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 3210 | // the initializer is already the right type. |
| 3211 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3212 | if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3213 | return getDerived().TransformExpr(Init); |
| 3214 | |
| 3215 | // Revert value-initialization back to empty parens. |
| 3216 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 3217 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3218 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3219 | Parens.getEnd()); |
| 3220 | } |
| 3221 | |
| 3222 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 3223 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3224 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3225 | SourceLocation()); |
| 3226 | |
| 3227 | // Revert initialization by constructor back to a parenthesized or braced list |
| 3228 | // of expressions. Any other form of initializer can just be reused directly. |
| 3229 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3230 | return getDerived().TransformExpr(Init); |
| 3231 | |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3232 | // If the initialization implicitly converted an initializer list to a |
| 3233 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 3234 | if (Construct && Construct->isStdInitListInitialization()) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3235 | return TransformInitializer(Construct->getArg(0), NotCopyInit); |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3236 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3237 | SmallVector<Expr*, 8> NewArgs; |
| 3238 | bool ArgChanged = false; |
| 3239 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3240 | /*IsCall*/true, NewArgs, &ArgChanged)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3241 | return ExprError(); |
| 3242 | |
| 3243 | // If this was list initialization, revert to list form. |
| 3244 | if (Construct->isListInitialization()) |
| 3245 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 3246 | Construct->getLocEnd(), |
| 3247 | Construct->getType()); |
| 3248 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3249 | // Build a ParenListExpr to represent anything else. |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 3250 | SourceRange Parens = Construct->getParenOrBraceRange(); |
Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 3251 | if (Parens.isInvalid()) { |
| 3252 | // This was a variable declaration's initialization for which no initializer |
| 3253 | // was specified. |
| 3254 | assert(NewArgs.empty() && |
| 3255 | "no parens or braces but have direct init with arguments?"); |
| 3256 | return ExprEmpty(); |
| 3257 | } |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3258 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 3259 | Parens.getEnd()); |
| 3260 | } |
| 3261 | |
| 3262 | template<typename Derived> |
Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 3263 | bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3264 | unsigned NumInputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3265 | bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3266 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3267 | bool *ArgChanged) { |
| 3268 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 3269 | // If requested, drop call arguments that need to be dropped. |
| 3270 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 3271 | if (ArgChanged) |
| 3272 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3273 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3274 | break; |
| 3275 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3276 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3277 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 3278 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3279 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3280 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3281 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3282 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3283 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3284 | // Determine whether the set of unexpanded parameter packs can and should |
| 3285 | // be expanded. |
| 3286 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3287 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3288 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 3289 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3290 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 3291 | Pattern->getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3292 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3293 | Expand, RetainExpansion, |
| 3294 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3295 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3296 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3297 | if (!Expand) { |
| 3298 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3299 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3300 | // expansion. |
| 3301 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3302 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 3303 | if (OutPattern.isInvalid()) |
| 3304 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3305 | |
| 3306 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3307 | Expansion->getEllipsisLoc(), |
| 3308 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3309 | if (Out.isInvalid()) |
| 3310 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3311 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3312 | if (ArgChanged) |
| 3313 | *ArgChanged = true; |
| 3314 | Outputs.push_back(Out.get()); |
| 3315 | continue; |
| 3316 | } |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 3317 | |
| 3318 | // Record right away that the argument was changed. This needs |
| 3319 | // to happen even if the array expands to nothing. |
| 3320 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3321 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3322 | // The transform has determined that we should perform an elementwise |
| 3323 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3324 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3325 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3326 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3327 | if (Out.isInvalid()) |
| 3328 | return true; |
| 3329 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3330 | // FIXME: Can this happen? We should not try to expand the pack |
| 3331 | // in this case. |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3332 | if (Out.get()->containsUnexpandedParameterPack()) { |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3333 | Out = getDerived().RebuildPackExpansion( |
| 3334 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3335 | if (Out.isInvalid()) |
| 3336 | return true; |
| 3337 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3338 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3339 | Outputs.push_back(Out.get()); |
| 3340 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3341 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3342 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3343 | // forgetting the partially-substituted parameter pack. |
| 3344 | if (RetainExpansion) { |
| 3345 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3346 | |
| 3347 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3348 | if (Out.isInvalid()) |
| 3349 | return true; |
| 3350 | |
| 3351 | Out = getDerived().RebuildPackExpansion( |
| 3352 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3353 | if (Out.isInvalid()) |
| 3354 | return true; |
| 3355 | |
| 3356 | Outputs.push_back(Out.get()); |
| 3357 | } |
| 3358 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3359 | continue; |
| 3360 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3361 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3362 | ExprResult Result = |
| 3363 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3364 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3365 | if (Result.isInvalid()) |
| 3366 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3367 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3368 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3369 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3370 | |
| 3371 | Outputs.push_back(Result.get()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3372 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3373 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3374 | return false; |
| 3375 | } |
| 3376 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 3377 | template <typename Derived> |
| 3378 | Sema::ConditionResult TreeTransform<Derived>::TransformCondition( |
| 3379 | SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) { |
| 3380 | if (Var) { |
| 3381 | VarDecl *ConditionVar = cast_or_null<VarDecl>( |
| 3382 | getDerived().TransformDefinition(Var->getLocation(), Var)); |
| 3383 | |
| 3384 | if (!ConditionVar) |
| 3385 | return Sema::ConditionError(); |
| 3386 | |
| 3387 | return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind); |
| 3388 | } |
| 3389 | |
| 3390 | if (Expr) { |
| 3391 | ExprResult CondExpr = getDerived().TransformExpr(Expr); |
| 3392 | |
| 3393 | if (CondExpr.isInvalid()) |
| 3394 | return Sema::ConditionError(); |
| 3395 | |
| 3396 | return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind); |
| 3397 | } |
| 3398 | |
| 3399 | return Sema::ConditionResult(); |
| 3400 | } |
| 3401 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3402 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3403 | NestedNameSpecifierLoc |
| 3404 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3405 | NestedNameSpecifierLoc NNS, |
| 3406 | QualType ObjectType, |
| 3407 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3408 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3409 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3410 | Qualifier = Qualifier.getPrefix()) |
| 3411 | Qualifiers.push_back(Qualifier); |
| 3412 | |
| 3413 | CXXScopeSpec SS; |
| 3414 | while (!Qualifiers.empty()) { |
| 3415 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3416 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3417 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3418 | switch (QNNS->getKind()) { |
| 3419 | case NestedNameSpecifier::Identifier: |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3420 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3421 | *QNNS->getAsIdentifier(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3422 | Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3423 | Q.getLocalEndLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3424 | ObjectType, false, SS, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3425 | FirstQualifierInScope, false)) |
| 3426 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3427 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3428 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3429 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3430 | case NestedNameSpecifier::Namespace: { |
| 3431 | NamespaceDecl *NS |
| 3432 | = cast_or_null<NamespaceDecl>( |
| 3433 | getDerived().TransformDecl( |
| 3434 | Q.getLocalBeginLoc(), |
| 3435 | QNNS->getAsNamespace())); |
| 3436 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3437 | break; |
| 3438 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3439 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3440 | case NestedNameSpecifier::NamespaceAlias: { |
| 3441 | NamespaceAliasDecl *Alias |
| 3442 | = cast_or_null<NamespaceAliasDecl>( |
| 3443 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3444 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3445 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3446 | Q.getLocalEndLoc()); |
| 3447 | break; |
| 3448 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3449 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3450 | case NestedNameSpecifier::Global: |
| 3451 | // There is no meaningful transformation that one could perform on the |
| 3452 | // global scope. |
| 3453 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3454 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3455 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 3456 | case NestedNameSpecifier::Super: { |
| 3457 | CXXRecordDecl *RD = |
| 3458 | cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 3459 | SourceLocation(), QNNS->getAsRecordDecl())); |
| 3460 | SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); |
| 3461 | break; |
| 3462 | } |
| 3463 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3464 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3465 | case NestedNameSpecifier::TypeSpec: { |
| 3466 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3467 | FirstQualifierInScope, SS); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3468 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3469 | if (!TL) |
| 3470 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3471 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3472 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3473 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3474 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3475 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3476 | "Can't get cv-qualifiers here"); |
Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3477 | if (TL.getType()->isEnumeralType()) |
| 3478 | SemaRef.Diag(TL.getBeginLoc(), |
| 3479 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3480 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3481 | Q.getLocalEndLoc()); |
| 3482 | break; |
| 3483 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3484 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3485 | // error because a previous error should have already been emitted. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3486 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3487 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3488 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3489 | << TL.getType() << SS.getRange(); |
| 3490 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3491 | return NestedNameSpecifierLoc(); |
| 3492 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3493 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3494 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3495 | // 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] | 3496 | FirstQualifierInScope = nullptr; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3497 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3498 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3499 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3500 | // 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] | 3501 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3502 | !getDerived().AlwaysRebuild()) |
| 3503 | return NNS; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3504 | |
| 3505 | // If we can re-use the source-location data from the original |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3506 | // nested-name-specifier, do so. |
| 3507 | if (SS.location_size() == NNS.getDataLength() && |
| 3508 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3509 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3510 | |
| 3511 | // Allocate new nested-name-specifier location information. |
| 3512 | return SS.getWithLocInContext(SemaRef.Context); |
| 3513 | } |
| 3514 | |
| 3515 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3516 | DeclarationNameInfo |
| 3517 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3518 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3519 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3520 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3521 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3522 | |
| 3523 | switch (Name.getNameKind()) { |
| 3524 | case DeclarationName::Identifier: |
| 3525 | case DeclarationName::ObjCZeroArgSelector: |
| 3526 | case DeclarationName::ObjCOneArgSelector: |
| 3527 | case DeclarationName::ObjCMultiArgSelector: |
| 3528 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3529 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3530 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3531 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3533 | case DeclarationName::CXXConstructorName: |
| 3534 | case DeclarationName::CXXDestructorName: |
| 3535 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3536 | TypeSourceInfo *NewTInfo; |
| 3537 | CanQualType NewCanTy; |
| 3538 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3539 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3540 | if (!NewTInfo) |
| 3541 | return DeclarationNameInfo(); |
| 3542 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3543 | } |
| 3544 | else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3545 | NewTInfo = nullptr; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3546 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3547 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3548 | if (NewT.isNull()) |
| 3549 | return DeclarationNameInfo(); |
| 3550 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3551 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3552 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3553 | DeclarationName NewName |
| 3554 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3555 | NewCanTy); |
| 3556 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3557 | NewNameInfo.setName(NewName); |
| 3558 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3559 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3560 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3561 | } |
| 3562 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3563 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3567 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3568 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3569 | TemplateName Name, |
| 3570 | SourceLocation NameLoc, |
| 3571 | QualType ObjectType, |
| 3572 | NamedDecl *FirstQualifierInScope) { |
| 3573 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3574 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3575 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3576 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3577 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3578 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3579 | Template)); |
| 3580 | if (!TransTemplate) |
| 3581 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3582 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3583 | if (!getDerived().AlwaysRebuild() && |
| 3584 | SS.getScopeRep() == QTN->getQualifier() && |
| 3585 | TransTemplate == Template) |
| 3586 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3587 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3588 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3589 | TransTemplate); |
| 3590 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3591 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3592 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3593 | if (SS.getScopeRep()) { |
| 3594 | // These apply to the scope specifier, not the template. |
| 3595 | ObjectType = QualType(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3596 | FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3597 | } |
| 3598 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3599 | if (!getDerived().AlwaysRebuild() && |
| 3600 | SS.getScopeRep() == DTN->getQualifier() && |
| 3601 | ObjectType.isNull()) |
| 3602 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3603 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3604 | if (DTN->isIdentifier()) { |
| 3605 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3606 | *DTN->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3607 | NameLoc, |
| 3608 | ObjectType, |
| 3609 | FirstQualifierInScope); |
| 3610 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3611 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3612 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3613 | ObjectType); |
| 3614 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3615 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3616 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3617 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3618 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3619 | Template)); |
| 3620 | if (!TransTemplate) |
| 3621 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3622 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3623 | if (!getDerived().AlwaysRebuild() && |
| 3624 | TransTemplate == Template) |
| 3625 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3626 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3627 | return TemplateName(TransTemplate); |
| 3628 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3629 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3630 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3631 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3632 | TemplateTemplateParmDecl *TransParam |
| 3633 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3634 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3635 | if (!TransParam) |
| 3636 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3637 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3638 | if (!getDerived().AlwaysRebuild() && |
| 3639 | TransParam == SubstPack->getParameterPack()) |
| 3640 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3641 | |
| 3642 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3643 | SubstPack->getArgumentPack()); |
| 3644 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3645 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3646 | // These should be getting filtered out before they reach the AST. |
| 3647 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3651 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3652 | const TemplateArgument &Arg, |
| 3653 | TemplateArgumentLoc &Output) { |
| 3654 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3655 | switch (Arg.getKind()) { |
| 3656 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3657 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3658 | break; |
| 3659 | |
| 3660 | case TemplateArgument::Type: |
| 3661 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3662 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3663 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3664 | break; |
| 3665 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3666 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3667 | case TemplateArgument::TemplateExpansion: { |
| 3668 | NestedNameSpecifierLocBuilder Builder; |
Manuel Klimek | 4c67fa7 | 2016-01-11 11:39:00 +0000 | [diff] [blame] | 3669 | TemplateName Template = Arg.getAsTemplateOrTemplatePattern(); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3670 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3671 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3672 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3673 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3674 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3675 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3676 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3677 | Builder.getWithLocInContext(SemaRef.Context), |
| 3678 | Loc); |
| 3679 | else |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3680 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3681 | Builder.getWithLocInContext(SemaRef.Context), |
| 3682 | Loc, Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3683 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3684 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3685 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3686 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3687 | case TemplateArgument::Expression: |
| 3688 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3689 | break; |
| 3690 | |
| 3691 | case TemplateArgument::Declaration: |
| 3692 | case TemplateArgument::Integral: |
| 3693 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3694 | case TemplateArgument::NullPtr: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3695 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3696 | break; |
| 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | template<typename Derived> |
| 3701 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3702 | const TemplateArgumentLoc &Input, |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3703 | TemplateArgumentLoc &Output, bool Uneval) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3704 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3705 | switch (Arg.getKind()) { |
| 3706 | case TemplateArgument::Null: |
| 3707 | case TemplateArgument::Integral: |
Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3708 | case TemplateArgument::Pack: |
| 3709 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3710 | case TemplateArgument::NullPtr: |
| 3711 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3713 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3714 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3715 | if (!DI) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3716 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3717 | |
| 3718 | DI = getDerived().TransformType(DI); |
| 3719 | if (!DI) return true; |
| 3720 | |
| 3721 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3722 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3723 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3724 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3725 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3726 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3727 | if (QualifierLoc) { |
| 3728 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3729 | if (!QualifierLoc) |
| 3730 | return true; |
| 3731 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3732 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3733 | CXXScopeSpec SS; |
| 3734 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3735 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3736 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3737 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3738 | if (Template.isNull()) |
| 3739 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3740 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3741 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3742 | Input.getTemplateNameLoc()); |
| 3743 | return false; |
| 3744 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3745 | |
| 3746 | case TemplateArgument::TemplateExpansion: |
| 3747 | llvm_unreachable("Caller should expand pack expansions"); |
| 3748 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3749 | case TemplateArgument::Expression: { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3750 | // Template argument expressions are constant expressions. |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3751 | EnterExpressionEvaluationContext Unevaluated( |
| 3752 | getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3753 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3754 | Expr *InputExpr = Input.getSourceExpression(); |
| 3755 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3756 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3757 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3758 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3759 | if (E.isInvalid()) return true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3760 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3761 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3762 | } |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3763 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3765 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3766 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3767 | } |
| 3768 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3769 | /// \brief Iterator adaptor that invents template argument location information |
| 3770 | /// for each of the template arguments in its underlying iterator. |
| 3771 | template<typename Derived, typename InputIterator> |
| 3772 | class TemplateArgumentLocInventIterator { |
| 3773 | TreeTransform<Derived> &Self; |
| 3774 | InputIterator Iter; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3775 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3776 | public: |
| 3777 | typedef TemplateArgumentLoc value_type; |
| 3778 | typedef TemplateArgumentLoc reference; |
| 3779 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3780 | difference_type; |
| 3781 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3782 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3783 | class pointer { |
| 3784 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3785 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3786 | public: |
| 3787 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3788 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3789 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3790 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3791 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 3792 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3793 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3794 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3795 | InputIterator Iter) |
| 3796 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3797 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3798 | TemplateArgumentLocInventIterator &operator++() { |
| 3799 | ++Iter; |
| 3800 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3801 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3802 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3803 | TemplateArgumentLocInventIterator operator++(int) { |
| 3804 | TemplateArgumentLocInventIterator Old(*this); |
| 3805 | ++(*this); |
| 3806 | return Old; |
| 3807 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3808 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3809 | reference operator*() const { |
| 3810 | TemplateArgumentLoc Result; |
| 3811 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3812 | return Result; |
| 3813 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3814 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3815 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3816 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3817 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3818 | const TemplateArgumentLocInventIterator &Y) { |
| 3819 | return X.Iter == Y.Iter; |
| 3820 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3821 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3822 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3823 | const TemplateArgumentLocInventIterator &Y) { |
| 3824 | return X.Iter != Y.Iter; |
| 3825 | } |
| 3826 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3827 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3828 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3829 | template<typename InputIterator> |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3830 | bool TreeTransform<Derived>::TransformTemplateArguments( |
| 3831 | InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, |
| 3832 | bool Uneval) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3833 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3834 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3835 | TemplateArgumentLoc In = *First; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3837 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3838 | // Unpack argument packs, which we translate them into separate |
| 3839 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3840 | // FIXME: We could do much better if we could guarantee that the |
| 3841 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3842 | // all of the template arguments in the argument pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3843 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3844 | TemplateArgument::pack_iterator> |
| 3845 | PackLocIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3846 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3847 | In.getArgument().pack_begin()), |
| 3848 | PackLocIterator(*this, |
| 3849 | In.getArgument().pack_end()), |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3850 | Outputs, Uneval)) |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3851 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3852 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3853 | continue; |
| 3854 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3855 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3856 | if (In.getArgument().isPackExpansion()) { |
| 3857 | // We have a pack expansion, for which we will be substituting into |
| 3858 | // the pattern. |
| 3859 | SourceLocation Ellipsis; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3860 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3861 | TemplateArgumentLoc Pattern |
Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3862 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3863 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3864 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3865 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3866 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3867 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3868 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3869 | // Determine whether the set of unexpanded parameter packs can and should |
| 3870 | // be expanded. |
| 3871 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3872 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3873 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3874 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3875 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3876 | Unexpanded, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3877 | Expand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3878 | RetainExpansion, |
| 3879 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3880 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3881 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3882 | if (!Expand) { |
| 3883 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3884 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3885 | // expansion. |
| 3886 | TemplateArgumentLoc OutPattern; |
| 3887 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3888 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3889 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3890 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3891 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3892 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3893 | if (Out.getArgument().isNull()) |
| 3894 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3895 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3896 | Outputs.addArgument(Out); |
| 3897 | continue; |
| 3898 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3899 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3900 | // The transform has determined that we should perform an elementwise |
| 3901 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3902 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3903 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3904 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3905 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3906 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3907 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3908 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3909 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3910 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3911 | if (Out.getArgument().isNull()) |
| 3912 | return true; |
| 3913 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3914 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3915 | Outputs.addArgument(Out); |
| 3916 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3917 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3918 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3919 | // forgetting the partially-substituted parameter pack. |
| 3920 | if (RetainExpansion) { |
| 3921 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3922 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3923 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3924 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3925 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3926 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3927 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3928 | if (Out.getArgument().isNull()) |
| 3929 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3930 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3931 | Outputs.addArgument(Out); |
| 3932 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3933 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3934 | continue; |
| 3935 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3936 | |
| 3937 | // The simple case: |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3938 | if (getDerived().TransformTemplateArgument(In, Out, Uneval)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3939 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3940 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3941 | Outputs.addArgument(Out); |
| 3942 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3943 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3944 | return false; |
| 3945 | |
| 3946 | } |
| 3947 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3948 | //===----------------------------------------------------------------------===// |
| 3949 | // Type transformation |
| 3950 | //===----------------------------------------------------------------------===// |
| 3951 | |
| 3952 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3953 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3954 | if (getDerived().AlreadyTransformed(T)) |
| 3955 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3957 | // Temporary workaround. All of these transformations should |
| 3958 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3959 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3960 | getDerived().getBaseLocation()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3961 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3962 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3963 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3964 | if (!NewDI) |
| 3965 | return QualType(); |
| 3966 | |
| 3967 | return NewDI->getType(); |
| 3968 | } |
| 3969 | |
| 3970 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3971 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3972 | // Refine the base location to the type's location. |
| 3973 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3974 | getDerived().getBaseEntity()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3975 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3976 | return DI; |
| 3977 | |
| 3978 | TypeLocBuilder TLB; |
| 3979 | |
| 3980 | TypeLoc TL = DI->getTypeLoc(); |
| 3981 | TLB.reserve(TL.getFullDataSize()); |
| 3982 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3983 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3984 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3985 | return nullptr; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3986 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3987 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | template<typename Derived> |
| 3991 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3992 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3993 | switch (T.getTypeLocClass()) { |
| 3994 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3995 | #define TYPELOC(CLASS, PARENT) \ |
| 3996 | case TypeLoc::CLASS: \ |
| 3997 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3998 | T.castAs<CLASS##TypeLoc>()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3999 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4000 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4001 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4002 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 4006 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 4007 | /// that are not permitted (e.g., qualifiers on reference or function |
| 4008 | /// types). This is the right thing for template instantiation, but |
| 4009 | /// probably not for other clients. |
| 4010 | template<typename Derived> |
| 4011 | QualType |
| 4012 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4013 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 4014 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4015 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4016 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4017 | if (Result.isNull()) |
| 4018 | return QualType(); |
| 4019 | |
| 4020 | // Silently suppress qualifiers if the result type can't be qualified. |
| 4021 | // FIXME: this is the right thing for template instantiation, but |
| 4022 | // probably not for other clients. |
| 4023 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4024 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4025 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4026 | // 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] | 4027 | // resulting type. |
| 4028 | if (Quals.hasObjCLifetime()) { |
| 4029 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 4030 | Quals.removeObjCLifetime(); |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 4031 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4032 | // Objective-C ARC: |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4033 | // A lifetime qualifier applied to a substituted template parameter |
| 4034 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4035 | const AutoType *AutoTy; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4036 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4037 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 4038 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 4039 | Qualifiers Qs = Replacement.getQualifiers(); |
| 4040 | Qs.removeObjCLifetime(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4041 | Replacement |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4042 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 4043 | Qs); |
| 4044 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4045 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4046 | Replacement); |
| 4047 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4048 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 4049 | // 'auto' types behave the same way as template parameters. |
| 4050 | QualType Deduced = AutoTy->getDeducedType(); |
| 4051 | Qualifiers Qs = Deduced.getQualifiers(); |
| 4052 | Qs.removeObjCLifetime(); |
| 4053 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 4054 | Qs); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 4055 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 4056 | AutoTy->isDependentType()); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4057 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4058 | } else { |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 4059 | // Otherwise, complain about the addition of a qualifier to an |
| 4060 | // already-qualified type. |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 4061 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 4062 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 4063 | << Result << R; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4064 | |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4065 | Quals.removeObjCLifetime(); |
| 4066 | } |
| 4067 | } |
| 4068 | } |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 4069 | if (!Quals.empty()) { |
| 4070 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 4071 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 4072 | if (Result.hasLocalQualifiers()) |
| 4073 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 4074 | // No location information to preserve. |
| 4075 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4076 | |
| 4077 | return Result; |
| 4078 | } |
| 4079 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4080 | template<typename Derived> |
| 4081 | TypeLoc |
| 4082 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 4083 | QualType ObjectType, |
| 4084 | NamedDecl *UnqualLookup, |
| 4085 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4086 | if (getDerived().AlreadyTransformed(TL.getType())) |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4087 | return TL; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4088 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4089 | TypeSourceInfo *TSI = |
| 4090 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 4091 | if (TSI) |
| 4092 | return TSI->getTypeLoc(); |
| 4093 | return TypeLoc(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4094 | } |
| 4095 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4096 | template<typename Derived> |
| 4097 | TypeSourceInfo * |
| 4098 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 4099 | QualType ObjectType, |
| 4100 | NamedDecl *UnqualLookup, |
| 4101 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4102 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4103 | return TSInfo; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4104 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4105 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 4106 | UnqualLookup, SS); |
| 4107 | } |
| 4108 | |
| 4109 | template <typename Derived> |
| 4110 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 4111 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 4112 | CXXScopeSpec &SS) { |
| 4113 | QualType T = TL.getType(); |
| 4114 | assert(!getDerived().AlreadyTransformed(T)); |
| 4115 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4116 | TypeLocBuilder TLB; |
| 4117 | QualType Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4118 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4119 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4120 | TemplateSpecializationTypeLoc SpecTL = |
| 4121 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4122 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4123 | TemplateName Template |
| 4124 | = getDerived().TransformTemplateName(SS, |
| 4125 | SpecTL.getTypePtr()->getTemplateName(), |
| 4126 | SpecTL.getTemplateNameLoc(), |
| 4127 | ObjectType, UnqualLookup); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4128 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4129 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4130 | |
| 4131 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4132 | Template); |
| 4133 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4134 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 4135 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4136 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4137 | TemplateName Template |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4138 | = getDerived().RebuildTemplateName(SS, |
| 4139 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4140 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4141 | ObjectType, UnqualLookup); |
| 4142 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4143 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4144 | |
| 4145 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4146 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4147 | Template, |
| 4148 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4149 | } else { |
| 4150 | // Nothing special needs to be done for these. |
| 4151 | Result = getDerived().TransformType(TLB, TL); |
| 4152 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4153 | |
| 4154 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4155 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4156 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4157 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4158 | } |
| 4159 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4160 | template <class TyLoc> static inline |
| 4161 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 4162 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 4163 | NewT.setNameLoc(T.getNameLoc()); |
| 4164 | return T.getType(); |
| 4165 | } |
| 4166 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4167 | template<typename Derived> |
| 4168 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4169 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4170 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 4171 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 4172 | if (T.needsExtraLocalData()) |
| 4173 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 4174 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4175 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4176 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4177 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4178 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4179 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4180 | // FIXME: recurse? |
| 4181 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4182 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4184 | template <typename Derived> |
| 4185 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 4186 | AdjustedTypeLoc TL) { |
| 4187 | // Adjustments applied during transformation are handled elsewhere. |
| 4188 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4189 | } |
| 4190 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4191 | template<typename Derived> |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 4192 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 4193 | DecayedTypeLoc TL) { |
| 4194 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4195 | if (OriginalType.isNull()) |
| 4196 | return QualType(); |
| 4197 | |
| 4198 | QualType Result = TL.getType(); |
| 4199 | if (getDerived().AlwaysRebuild() || |
| 4200 | OriginalType != TL.getOriginalLoc().getType()) |
| 4201 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 4202 | TLB.push<DecayedTypeLoc>(Result); |
| 4203 | // Nothing to set for DecayedTypeLoc. |
| 4204 | return Result; |
| 4205 | } |
| 4206 | |
| 4207 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4208 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4209 | PointerTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4210 | QualType PointeeType |
| 4211 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4212 | if (PointeeType.isNull()) |
| 4213 | return QualType(); |
| 4214 | |
| 4215 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4216 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4217 | // A dependent pointer type 'T *' has is being transformed such |
| 4218 | // that an Objective-C class type is being replaced for 'T'. The |
| 4219 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 4220 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4221 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4222 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4223 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 4224 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4225 | return Result; |
| 4226 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4227 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4228 | if (getDerived().AlwaysRebuild() || |
| 4229 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4230 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 4231 | if (Result.isNull()) |
| 4232 | return QualType(); |
| 4233 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4234 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4235 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4236 | // pointing to. |
| 4237 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4238 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4239 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 4240 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4241 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4242 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4243 | |
| 4244 | template<typename Derived> |
| 4245 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4246 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4247 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4248 | QualType PointeeType |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4249 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4250 | if (PointeeType.isNull()) |
| 4251 | return QualType(); |
| 4252 | |
| 4253 | QualType Result = TL.getType(); |
| 4254 | if (getDerived().AlwaysRebuild() || |
| 4255 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4256 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4257 | TL.getSigilLoc()); |
| 4258 | if (Result.isNull()) |
| 4259 | return QualType(); |
| 4260 | } |
| 4261 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 4262 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4263 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 4264 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4265 | } |
| 4266 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4267 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 4268 | /// don't care whether the type itself is an l-value type or an r-value |
| 4269 | /// type; we only care if the type was *written* as an l-value type |
| 4270 | /// or an r-value type. |
| 4271 | template<typename Derived> |
| 4272 | QualType |
| 4273 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4274 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4275 | const ReferenceType *T = TL.getTypePtr(); |
| 4276 | |
| 4277 | // Note that this works with the pointee-as-written. |
| 4278 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4279 | if (PointeeType.isNull()) |
| 4280 | return QualType(); |
| 4281 | |
| 4282 | QualType Result = TL.getType(); |
| 4283 | if (getDerived().AlwaysRebuild() || |
| 4284 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 4285 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 4286 | T->isSpelledAsLValue(), |
| 4287 | TL.getSigilLoc()); |
| 4288 | if (Result.isNull()) |
| 4289 | return QualType(); |
| 4290 | } |
| 4291 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4292 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4293 | // referring to. |
| 4294 | TLB.TypeWasModifiedSafely( |
| 4295 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 4296 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4297 | // r-value references can be rebuilt as l-value references. |
| 4298 | ReferenceTypeLoc NewTL; |
| 4299 | if (isa<LValueReferenceType>(Result)) |
| 4300 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 4301 | else |
| 4302 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 4303 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 4304 | |
| 4305 | return Result; |
| 4306 | } |
| 4307 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4308 | template<typename Derived> |
| 4309 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4310 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4311 | LValueReferenceTypeLoc TL) { |
| 4312 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4315 | template<typename Derived> |
| 4316 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4317 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4318 | RValueReferenceTypeLoc TL) { |
| 4319 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4320 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4321 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4322 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4323 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4324 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4325 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4326 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4327 | if (PointeeType.isNull()) |
| 4328 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4329 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4330 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4331 | TypeSourceInfo *NewClsTInfo = nullptr; |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4332 | if (OldClsTInfo) { |
| 4333 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 4334 | if (!NewClsTInfo) |
| 4335 | return QualType(); |
| 4336 | } |
| 4337 | |
| 4338 | const MemberPointerType *T = TL.getTypePtr(); |
| 4339 | QualType OldClsType = QualType(T->getClass(), 0); |
| 4340 | QualType NewClsType; |
| 4341 | if (NewClsTInfo) |
| 4342 | NewClsType = NewClsTInfo->getType(); |
| 4343 | else { |
| 4344 | NewClsType = getDerived().TransformType(OldClsType); |
| 4345 | if (NewClsType.isNull()) |
| 4346 | return QualType(); |
| 4347 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4348 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4349 | QualType Result = TL.getType(); |
| 4350 | if (getDerived().AlwaysRebuild() || |
| 4351 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4352 | NewClsType != OldClsType) { |
| 4353 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4354 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4355 | if (Result.isNull()) |
| 4356 | return QualType(); |
| 4357 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4358 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4359 | // If we had to adjust the pointee type when building a member pointer, make |
| 4360 | // sure to push TypeLoc info for it. |
| 4361 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 4362 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 4363 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 4364 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 4365 | } |
| 4366 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4367 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 4368 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4369 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4370 | |
| 4371 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4372 | } |
| 4373 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | template<typename Derived> |
| 4375 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4376 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4377 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4378 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4379 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4380 | if (ElementType.isNull()) |
| 4381 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4382 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4383 | QualType Result = TL.getType(); |
| 4384 | if (getDerived().AlwaysRebuild() || |
| 4385 | ElementType != T->getElementType()) { |
| 4386 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4387 | T->getSizeModifier(), |
| 4388 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4389 | T->getIndexTypeCVRQualifiers(), |
| 4390 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4391 | if (Result.isNull()) |
| 4392 | return QualType(); |
| 4393 | } |
Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4394 | |
| 4395 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4396 | // a ConstantArrayType is allowed to have an element type which is a |
| 4397 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4398 | // types have the same location layout. |
| 4399 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4400 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4401 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4403 | Expr *Size = TL.getSizeExpr(); |
| 4404 | if (Size) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4405 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4406 | Sema::ConstantEvaluated); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4407 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4408 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4409 | } |
| 4410 | NewTL.setSizeExpr(Size); |
| 4411 | |
| 4412 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4413 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4415 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4416 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4417 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4418 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4419 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4420 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4421 | if (ElementType.isNull()) |
| 4422 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4423 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4424 | QualType Result = TL.getType(); |
| 4425 | if (getDerived().AlwaysRebuild() || |
| 4426 | ElementType != T->getElementType()) { |
| 4427 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4428 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4429 | T->getIndexTypeCVRQualifiers(), |
| 4430 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4431 | if (Result.isNull()) |
| 4432 | return QualType(); |
| 4433 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4434 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4435 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4436 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4437 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4438 | NewTL.setSizeExpr(nullptr); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4439 | |
| 4440 | return Result; |
| 4441 | } |
| 4442 | |
| 4443 | template<typename Derived> |
| 4444 | QualType |
| 4445 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4446 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4447 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4448 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4449 | if (ElementType.isNull()) |
| 4450 | return QualType(); |
| 4451 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4452 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4453 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 4454 | if (SizeResult.isInvalid()) |
| 4455 | return QualType(); |
| 4456 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4457 | Expr *Size = SizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4458 | |
| 4459 | QualType Result = TL.getType(); |
| 4460 | if (getDerived().AlwaysRebuild() || |
| 4461 | ElementType != T->getElementType() || |
| 4462 | Size != T->getSizeExpr()) { |
| 4463 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4464 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4465 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4466 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4467 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4468 | if (Result.isNull()) |
| 4469 | return QualType(); |
| 4470 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4471 | |
Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4472 | // We might have constant size array now, but fortunately it has the same |
| 4473 | // location layout. |
| 4474 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4475 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4476 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4477 | NewTL.setSizeExpr(Size); |
| 4478 | |
| 4479 | return Result; |
| 4480 | } |
| 4481 | |
| 4482 | template<typename Derived> |
| 4483 | QualType |
| 4484 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4485 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4486 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4487 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4488 | if (ElementType.isNull()) |
| 4489 | return QualType(); |
| 4490 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4491 | // Array bounds are constant expressions. |
| 4492 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4493 | Sema::ConstantEvaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4494 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4495 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4496 | Expr *origSize = TL.getSizeExpr(); |
| 4497 | if (!origSize) origSize = T->getSizeExpr(); |
| 4498 | |
| 4499 | ExprResult sizeResult |
| 4500 | = getDerived().TransformExpr(origSize); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4501 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4502 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4503 | return QualType(); |
| 4504 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4505 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4506 | |
| 4507 | QualType Result = TL.getType(); |
| 4508 | if (getDerived().AlwaysRebuild() || |
| 4509 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4510 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4511 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4512 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4513 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4514 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4515 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4516 | if (Result.isNull()) |
| 4517 | return QualType(); |
| 4518 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4519 | |
| 4520 | // We might have any sort of array type now, but fortunately they |
| 4521 | // all have the same location layout. |
| 4522 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4523 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4524 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4525 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4526 | |
| 4527 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4528 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4529 | |
| 4530 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4531 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4532 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4533 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4534 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4535 | |
| 4536 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4537 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4538 | if (ElementType.isNull()) |
| 4539 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4540 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4541 | // Vector sizes are constant expressions. |
| 4542 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4543 | Sema::ConstantEvaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4544 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4545 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4546 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4547 | if (Size.isInvalid()) |
| 4548 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4549 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4550 | QualType Result = TL.getType(); |
| 4551 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4552 | ElementType != T->getElementType() || |
| 4553 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4554 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4555 | Size.get(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4556 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4557 | if (Result.isNull()) |
| 4558 | return QualType(); |
| 4559 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4560 | |
| 4561 | // Result might be dependent or not. |
| 4562 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4563 | DependentSizedExtVectorTypeLoc NewTL |
| 4564 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4565 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4566 | } else { |
| 4567 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4568 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4569 | } |
| 4570 | |
| 4571 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4572 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
| 4574 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4575 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4576 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4577 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4578 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4579 | if (ElementType.isNull()) |
| 4580 | return QualType(); |
| 4581 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4582 | QualType Result = TL.getType(); |
| 4583 | if (getDerived().AlwaysRebuild() || |
| 4584 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4585 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4586 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4587 | if (Result.isNull()) |
| 4588 | return QualType(); |
| 4589 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4590 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4591 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4592 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4593 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4594 | return Result; |
| 4595 | } |
| 4596 | |
| 4597 | template<typename Derived> |
| 4598 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4599 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4600 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4601 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4602 | if (ElementType.isNull()) |
| 4603 | return QualType(); |
| 4604 | |
| 4605 | QualType Result = TL.getType(); |
| 4606 | if (getDerived().AlwaysRebuild() || |
| 4607 | ElementType != T->getElementType()) { |
| 4608 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4609 | T->getNumElements(), |
| 4610 | /*FIXME*/ SourceLocation()); |
| 4611 | if (Result.isNull()) |
| 4612 | return QualType(); |
| 4613 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4614 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4615 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4616 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4617 | |
| 4618 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4619 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4620 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4621 | template <typename Derived> |
| 4622 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4623 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4624 | bool ExpectParameterPack) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4625 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4626 | TypeSourceInfo *NewDI = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4627 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4628 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4629 | // 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] | 4630 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4631 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4632 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4633 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4634 | TypeLocBuilder TLB; |
| 4635 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4636 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4637 | |
| 4638 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4639 | OldExpansionTL.getPatternLoc()); |
| 4640 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4641 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4642 | |
| 4643 | Result = RebuildPackExpansionType(Result, |
| 4644 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4645 | OldExpansionTL.getEllipsisLoc(), |
| 4646 | NumExpansions); |
| 4647 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4648 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4649 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4650 | PackExpansionTypeLoc NewExpansionTL |
| 4651 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4652 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4653 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4654 | } else |
| 4655 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4656 | if (!NewDI) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4657 | return nullptr; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4658 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4659 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4660 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4661 | |
| 4662 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4663 | OldParm->getDeclContext(), |
| 4664 | OldParm->getInnerLocStart(), |
| 4665 | OldParm->getLocation(), |
| 4666 | OldParm->getIdentifier(), |
| 4667 | NewDI->getType(), |
| 4668 | NewDI, |
| 4669 | OldParm->getStorageClass(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4670 | /* DefArg */ nullptr); |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4671 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4672 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4673 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4674 | } |
| 4675 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4676 | template <typename Derived> |
| 4677 | bool TreeTransform<Derived>::TransformFunctionTypeParams( |
| 4678 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 4679 | const QualType *ParamTypes, |
| 4680 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 4681 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4682 | SmallVectorImpl<ParmVarDecl *> *PVars, |
| 4683 | Sema::ExtParameterInfoBuilder &PInfos) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4684 | int indexAdjustment = 0; |
| 4685 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4686 | unsigned NumParams = Params.size(); |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4687 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4688 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4689 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4690 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4691 | Optional<unsigned> NumExpansions; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4692 | ParmVarDecl *NewParm = nullptr; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4693 | if (OldParm->isParameterPack()) { |
| 4694 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4695 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4697 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4698 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4699 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4700 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4701 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4702 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4703 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4704 | // Determine whether we should expand the parameter packs. |
| 4705 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4706 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4707 | Optional<unsigned> OrigNumExpansions = |
| 4708 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4709 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4710 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4711 | Pattern.getSourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4712 | Unexpanded, |
| 4713 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4714 | RetainExpansion, |
| 4715 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4716 | return true; |
| 4717 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4719 | if (ShouldExpand) { |
| 4720 | // Expand the function parameter pack into multiple, separate |
| 4721 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4722 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4723 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4724 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4725 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4726 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4727 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4728 | OrigNumExpansions, |
| 4729 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4730 | if (!NewParm) |
| 4731 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4732 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4733 | if (ParamInfos) |
| 4734 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4735 | OutParamTypes.push_back(NewParm->getType()); |
| 4736 | if (PVars) |
| 4737 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4738 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4739 | |
| 4740 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4741 | // forgetting the partially-substituted parameter pack. |
| 4742 | if (RetainExpansion) { |
| 4743 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4744 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4745 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4746 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4747 | OrigNumExpansions, |
| 4748 | /*ExpectParameterPack=*/false); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4749 | if (!NewParm) |
| 4750 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4751 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4752 | if (ParamInfos) |
| 4753 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4754 | OutParamTypes.push_back(NewParm->getType()); |
| 4755 | if (PVars) |
| 4756 | PVars->push_back(NewParm); |
| 4757 | } |
| 4758 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4759 | // The next parameter should have the same adjustment as the |
| 4760 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4761 | // on every push. Also, if we push nothing, the adjustment should |
| 4762 | // go down by one. |
| 4763 | indexAdjustment--; |
| 4764 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4765 | // We're done with the pack expansion. |
| 4766 | continue; |
| 4767 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4768 | |
| 4769 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4770 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4771 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4772 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4773 | indexAdjustment, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4774 | NumExpansions, |
| 4775 | /*ExpectParameterPack=*/true); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4776 | } else { |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4777 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4778 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4779 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4780 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4781 | if (!NewParm) |
| 4782 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4783 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4784 | if (ParamInfos) |
| 4785 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4786 | OutParamTypes.push_back(NewParm->getType()); |
| 4787 | if (PVars) |
| 4788 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4789 | continue; |
| 4790 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4791 | |
| 4792 | // Deal with the possibility that we don't have a parameter |
| 4793 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4794 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4795 | bool IsPackExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4796 | Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4797 | QualType NewType; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4798 | if (const PackExpansionType *Expansion |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4799 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4800 | // We have a function parameter pack that may need to be expanded. |
| 4801 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4802 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4803 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4804 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4805 | // Determine whether we should expand the parameter packs. |
| 4806 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4807 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4808 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4809 | Unexpanded, |
| 4810 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4811 | RetainExpansion, |
| 4812 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4813 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4814 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4815 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4816 | if (ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4817 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4818 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4819 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4820 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4821 | QualType NewType = getDerived().TransformType(Pattern); |
| 4822 | if (NewType.isNull()) |
| 4823 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4824 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4825 | if (ParamInfos) |
| 4826 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4827 | OutParamTypes.push_back(NewType); |
| 4828 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4829 | PVars->push_back(nullptr); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4830 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4831 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4832 | // We're done with the pack expansion. |
| 4833 | continue; |
| 4834 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4835 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4836 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4837 | // forgetting the partially-substituted parameter pack. |
| 4838 | if (RetainExpansion) { |
| 4839 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4840 | QualType NewType = getDerived().TransformType(Pattern); |
| 4841 | if (NewType.isNull()) |
| 4842 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4843 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4844 | if (ParamInfos) |
| 4845 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4846 | OutParamTypes.push_back(NewType); |
| 4847 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4848 | PVars->push_back(nullptr); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4849 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4850 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4851 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4852 | // expansion. |
| 4853 | OldType = Expansion->getPattern(); |
| 4854 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4855 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4856 | NewType = getDerived().TransformType(OldType); |
| 4857 | } else { |
| 4858 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4859 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4860 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4861 | if (NewType.isNull()) |
| 4862 | return true; |
| 4863 | |
| 4864 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4865 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4866 | NumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4867 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4868 | if (ParamInfos) |
| 4869 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4870 | OutParamTypes.push_back(NewType); |
| 4871 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4872 | PVars->push_back(nullptr); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4873 | } |
| 4874 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4875 | #ifndef NDEBUG |
| 4876 | if (PVars) { |
| 4877 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4878 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4879 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4880 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4881 | #endif |
| 4882 | |
| 4883 | return false; |
| 4884 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4885 | |
| 4886 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4887 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4888 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4889 | FunctionProtoTypeLoc TL) { |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4890 | SmallVector<QualType, 4> ExceptionStorage; |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 4891 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4892 | return getDerived().TransformFunctionProtoType( |
| 4893 | TLB, TL, nullptr, 0, |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 4894 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 4895 | return This->TransformExceptionSpec(TL.getBeginLoc(), ESI, |
| 4896 | ExceptionStorage, Changed); |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4897 | }); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4900 | template<typename Derived> template<typename Fn> |
| 4901 | QualType TreeTransform<Derived>::TransformFunctionProtoType( |
| 4902 | TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, |
| 4903 | unsigned ThisTypeQuals, Fn TransformExceptionSpec) { |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4904 | |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4905 | // Transform the parameters and return type. |
| 4906 | // |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4907 | // 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] | 4908 | // When the function has a trailing return type, we instantiate the |
| 4909 | // parameters before the return type, since the return type can then refer |
| 4910 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4911 | // |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4912 | SmallVector<QualType, 4> ParamTypes; |
| 4913 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4914 | Sema::ExtParameterInfoBuilder ExtParamInfos; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4915 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4916 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4917 | QualType ResultType; |
| 4918 | |
Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4919 | if (T->hasTrailingReturn()) { |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4920 | if (getDerived().TransformFunctionTypeParams( |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4921 | TL.getBeginLoc(), TL.getParams(), |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4922 | TL.getTypePtr()->param_type_begin(), |
| 4923 | T->getExtParameterInfosOrNull(), |
| 4924 | ParamTypes, &ParamDecls, ExtParamInfos)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4925 | return QualType(); |
| 4926 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4927 | { |
| 4928 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4929 | // If a declaration declares a member function or member function |
| 4930 | // 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] | 4931 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4932 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4933 | // declarator. |
| 4934 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4935 | |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4936 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4937 | if (ResultType.isNull()) |
| 4938 | return QualType(); |
| 4939 | } |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4940 | } |
| 4941 | else { |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4942 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4943 | if (ResultType.isNull()) |
| 4944 | return QualType(); |
| 4945 | |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4946 | if (getDerived().TransformFunctionTypeParams( |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4947 | TL.getBeginLoc(), TL.getParams(), |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4948 | TL.getTypePtr()->param_type_begin(), |
| 4949 | T->getExtParameterInfosOrNull(), |
| 4950 | ParamTypes, &ParamDecls, ExtParamInfos)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4951 | return QualType(); |
| 4952 | } |
| 4953 | |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4954 | FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); |
| 4955 | |
| 4956 | bool EPIChanged = false; |
| 4957 | if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) |
| 4958 | return QualType(); |
| 4959 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 4960 | // Handle extended parameter information. |
| 4961 | if (auto NewExtParamInfos = |
| 4962 | ExtParamInfos.getPointerOrNull(ParamTypes.size())) { |
| 4963 | if (!EPI.ExtParameterInfos || |
| 4964 | llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams()) |
| 4965 | != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) { |
| 4966 | EPIChanged = true; |
| 4967 | } |
| 4968 | EPI.ExtParameterInfos = NewExtParamInfos; |
| 4969 | } else if (EPI.ExtParameterInfos) { |
| 4970 | EPIChanged = true; |
| 4971 | EPI.ExtParameterInfos = nullptr; |
| 4972 | } |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4973 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4974 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4975 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
Benjamin Kramer | e1c08b0 | 2015-08-18 08:10:39 +0000 | [diff] [blame] | 4976 | T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) { |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4977 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4978 | if (Result.isNull()) |
| 4979 | return QualType(); |
| 4980 | } |
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 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4983 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4984 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4985 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4986 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4987 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 4988 | NewTL.setParam(i, ParamDecls[i]); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4989 | |
| 4990 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4993 | template<typename Derived> |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 4994 | bool TreeTransform<Derived>::TransformExceptionSpec( |
| 4995 | SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, |
| 4996 | SmallVectorImpl<QualType> &Exceptions, bool &Changed) { |
| 4997 | assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); |
| 4998 | |
| 4999 | // Instantiate a dynamic noexcept expression, if any. |
| 5000 | if (ESI.Type == EST_ComputedNoexcept) { |
| 5001 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 5002 | Sema::ConstantEvaluated); |
| 5003 | ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); |
| 5004 | if (NoexceptExpr.isInvalid()) |
| 5005 | return true; |
| 5006 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 5007 | // FIXME: This is bogus, a noexcept expression is not a condition. |
| 5008 | NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get()); |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5009 | if (NoexceptExpr.isInvalid()) |
| 5010 | return true; |
| 5011 | |
| 5012 | if (!NoexceptExpr.get()->isValueDependent()) { |
| 5013 | NoexceptExpr = getSema().VerifyIntegerConstantExpression( |
| 5014 | NoexceptExpr.get(), nullptr, |
| 5015 | diag::err_noexcept_needs_constant_expression, |
| 5016 | /*AllowFold*/false); |
| 5017 | if (NoexceptExpr.isInvalid()) |
| 5018 | return true; |
| 5019 | } |
| 5020 | |
| 5021 | if (ESI.NoexceptExpr != NoexceptExpr.get()) |
| 5022 | Changed = true; |
| 5023 | ESI.NoexceptExpr = NoexceptExpr.get(); |
| 5024 | } |
| 5025 | |
| 5026 | if (ESI.Type != EST_Dynamic) |
| 5027 | return false; |
| 5028 | |
| 5029 | // Instantiate a dynamic exception specification's type. |
| 5030 | for (QualType T : ESI.Exceptions) { |
| 5031 | if (const PackExpansionType *PackExpansion = |
| 5032 | T->getAs<PackExpansionType>()) { |
| 5033 | Changed = true; |
| 5034 | |
| 5035 | // We have a pack expansion. Instantiate it. |
| 5036 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5037 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 5038 | Unexpanded); |
| 5039 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 5040 | |
| 5041 | // Determine whether the set of unexpanded parameter packs can and |
| 5042 | // should |
| 5043 | // be expanded. |
| 5044 | bool Expand = false; |
| 5045 | bool RetainExpansion = false; |
| 5046 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 5047 | // FIXME: Track the location of the ellipsis (and track source location |
| 5048 | // information for the types in the exception specification in general). |
| 5049 | if (getDerived().TryExpandParameterPacks( |
| 5050 | Loc, SourceRange(), Unexpanded, Expand, |
| 5051 | RetainExpansion, NumExpansions)) |
| 5052 | return true; |
| 5053 | |
| 5054 | if (!Expand) { |
| 5055 | // We can't expand this pack expansion into separate arguments yet; |
| 5056 | // just substitute into the pattern and create a new pack expansion |
| 5057 | // type. |
| 5058 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5059 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5060 | if (U.isNull()) |
| 5061 | return true; |
| 5062 | |
| 5063 | U = SemaRef.Context.getPackExpansionType(U, NumExpansions); |
| 5064 | Exceptions.push_back(U); |
| 5065 | continue; |
| 5066 | } |
| 5067 | |
| 5068 | // Substitute into the pack expansion pattern for each slice of the |
| 5069 | // pack. |
| 5070 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 5071 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 5072 | |
| 5073 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5074 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5075 | return true; |
| 5076 | |
| 5077 | Exceptions.push_back(U); |
| 5078 | } |
| 5079 | } else { |
| 5080 | QualType U = getDerived().TransformType(T); |
| 5081 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5082 | return true; |
| 5083 | if (T != U) |
| 5084 | Changed = true; |
| 5085 | |
| 5086 | Exceptions.push_back(U); |
| 5087 | } |
| 5088 | } |
| 5089 | |
| 5090 | ESI.Exceptions = Exceptions; |
| 5091 | return false; |
| 5092 | } |
| 5093 | |
| 5094 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5095 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5096 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5097 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5098 | const FunctionNoProtoType *T = TL.getTypePtr(); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5099 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5100 | if (ResultType.isNull()) |
| 5101 | return QualType(); |
| 5102 | |
| 5103 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 5104 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5105 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 5106 | |
| 5107 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5108 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 5109 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5110 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5111 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5112 | |
| 5113 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5115 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5116 | template<typename Derived> QualType |
| 5117 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5118 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5119 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5120 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5121 | if (!D) |
| 5122 | return QualType(); |
| 5123 | |
| 5124 | QualType Result = TL.getType(); |
| 5125 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 5126 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 5127 | if (Result.isNull()) |
| 5128 | return QualType(); |
| 5129 | } |
| 5130 | |
| 5131 | // We might get an arbitrary type spec type back. We should at |
| 5132 | // least always get a type spec type, though. |
| 5133 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 5134 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5135 | |
| 5136 | return Result; |
| 5137 | } |
| 5138 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5139 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5140 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5141 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5142 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5143 | TypedefNameDecl *Typedef |
| 5144 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5145 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5146 | if (!Typedef) |
| 5147 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5148 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5149 | QualType Result = TL.getType(); |
| 5150 | if (getDerived().AlwaysRebuild() || |
| 5151 | Typedef != T->getDecl()) { |
| 5152 | Result = getDerived().RebuildTypedefType(Typedef); |
| 5153 | if (Result.isNull()) |
| 5154 | return QualType(); |
| 5155 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5156 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5157 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 5158 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5159 | |
| 5160 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5161 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5162 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5163 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5164 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5165 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5166 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 5167 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 5168 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5169 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5170 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5171 | if (E.isInvalid()) |
| 5172 | return QualType(); |
| 5173 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 5174 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 5175 | if (E.isInvalid()) |
| 5176 | return QualType(); |
| 5177 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5178 | QualType Result = TL.getType(); |
| 5179 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5180 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5181 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5182 | if (Result.isNull()) |
| 5183 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5184 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5185 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5187 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5188 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 5189 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5190 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5191 | |
| 5192 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | |
| 5195 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5196 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5197 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5198 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 5199 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 5200 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5201 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5202 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5203 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5204 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 5205 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5206 | if (Result.isNull()) |
| 5207 | return QualType(); |
| 5208 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5210 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5211 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 5212 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5213 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5214 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5215 | |
| 5216 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5217 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5218 | |
| 5219 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5220 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5221 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5222 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5223 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5224 | // decltype expressions are not potentially evaluated contexts |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5225 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 5226 | nullptr, /*IsDecltype=*/ true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5227 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5228 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5229 | if (E.isInvalid()) |
| 5230 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5231 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5232 | E = getSema().ActOnDecltypeExpression(E.get()); |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 5233 | if (E.isInvalid()) |
| 5234 | return QualType(); |
| 5235 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5236 | QualType Result = TL.getType(); |
| 5237 | if (getDerived().AlwaysRebuild() || |
| 5238 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5239 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5240 | if (Result.isNull()) |
| 5241 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5242 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5243 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5244 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5245 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 5246 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5247 | |
| 5248 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
| 5251 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 5252 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 5253 | TypeLocBuilder &TLB, |
| 5254 | UnaryTransformTypeLoc TL) { |
| 5255 | QualType Result = TL.getType(); |
| 5256 | if (Result->isDependentType()) { |
| 5257 | const UnaryTransformType *T = TL.getTypePtr(); |
| 5258 | QualType NewBase = |
| 5259 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 5260 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 5261 | T->getUTTKind(), |
| 5262 | TL.getKWLoc()); |
| 5263 | if (Result.isNull()) |
| 5264 | return QualType(); |
| 5265 | } |
| 5266 | |
| 5267 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 5268 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5269 | NewTL.setParensRange(TL.getParensRange()); |
| 5270 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 5271 | return Result; |
| 5272 | } |
| 5273 | |
| 5274 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5275 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 5276 | AutoTypeLoc TL) { |
| 5277 | const AutoType *T = TL.getTypePtr(); |
| 5278 | QualType OldDeduced = T->getDeducedType(); |
| 5279 | QualType NewDeduced; |
| 5280 | if (!OldDeduced.isNull()) { |
| 5281 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5282 | if (NewDeduced.isNull()) |
| 5283 | return QualType(); |
| 5284 | } |
| 5285 | |
| 5286 | QualType Result = TL.getType(); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5287 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 5288 | T->isDependentType()) { |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 5289 | Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5290 | if (Result.isNull()) |
| 5291 | return QualType(); |
| 5292 | } |
| 5293 | |
| 5294 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 5295 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5296 | |
| 5297 | return Result; |
| 5298 | } |
| 5299 | |
| 5300 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5301 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5302 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5303 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5304 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5305 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5306 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5307 | if (!Record) |
| 5308 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5309 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5310 | QualType Result = TL.getType(); |
| 5311 | if (getDerived().AlwaysRebuild() || |
| 5312 | Record != T->getDecl()) { |
| 5313 | Result = getDerived().RebuildRecordType(Record); |
| 5314 | if (Result.isNull()) |
| 5315 | return QualType(); |
| 5316 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5317 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5318 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 5319 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5320 | |
| 5321 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5322 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5323 | |
| 5324 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5325 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5326 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5327 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5328 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5329 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5330 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5331 | if (!Enum) |
| 5332 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5333 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5334 | QualType Result = TL.getType(); |
| 5335 | if (getDerived().AlwaysRebuild() || |
| 5336 | Enum != T->getDecl()) { |
| 5337 | Result = getDerived().RebuildEnumType(Enum); |
| 5338 | if (Result.isNull()) |
| 5339 | return QualType(); |
| 5340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5341 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5342 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 5343 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5344 | |
| 5345 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5346 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 5347 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5348 | template<typename Derived> |
| 5349 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 5350 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5351 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5352 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 5353 | TL.getTypePtr()->getDecl()); |
| 5354 | if (!D) return QualType(); |
| 5355 | |
| 5356 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 5357 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 5358 | return T; |
| 5359 | } |
| 5360 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5361 | template<typename Derived> |
| 5362 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5363 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5364 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5365 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5366 | } |
| 5367 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5368 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5369 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5370 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5371 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5372 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5373 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5374 | // Substitute into the replacement type, which itself might involve something |
| 5375 | // that needs to be transformed. This only tends to occur with default |
| 5376 | // template arguments of template template parameters. |
| 5377 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 5378 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 5379 | if (Replacement.isNull()) |
| 5380 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5382 | // Always canonicalize the replacement type. |
| 5383 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 5384 | QualType Result |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5385 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5386 | Replacement); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5387 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5388 | // Propagate type-source information. |
| 5389 | SubstTemplateTypeParmTypeLoc NewTL |
| 5390 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 5391 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5392 | return Result; |
| 5393 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 5397 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 5398 | TypeLocBuilder &TLB, |
| 5399 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 5400 | return TransformTypeSpecType(TLB, TL); |
| 5401 | } |
| 5402 | |
| 5403 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5404 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5405 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5406 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5407 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 5408 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5409 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 5410 | // because we can't have a dependent nested-name-specifier anyway. |
| 5411 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5412 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5413 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 5414 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5415 | if (Template.isNull()) |
| 5416 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5417 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5418 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 5419 | } |
| 5420 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 5421 | template<typename Derived> |
| 5422 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 5423 | AtomicTypeLoc TL) { |
| 5424 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5425 | if (ValueType.isNull()) |
| 5426 | return QualType(); |
| 5427 | |
| 5428 | QualType Result = TL.getType(); |
| 5429 | if (getDerived().AlwaysRebuild() || |
| 5430 | ValueType != TL.getValueLoc().getType()) { |
| 5431 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 5432 | if (Result.isNull()) |
| 5433 | return QualType(); |
| 5434 | } |
| 5435 | |
| 5436 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 5437 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5438 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5439 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5440 | |
| 5441 | return Result; |
| 5442 | } |
| 5443 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 5444 | template <typename Derived> |
| 5445 | QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB, |
| 5446 | PipeTypeLoc TL) { |
| 5447 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5448 | if (ValueType.isNull()) |
| 5449 | return QualType(); |
| 5450 | |
| 5451 | QualType Result = TL.getType(); |
| 5452 | if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) { |
| 5453 | Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc()); |
| 5454 | if (Result.isNull()) |
| 5455 | return QualType(); |
| 5456 | } |
| 5457 | |
| 5458 | PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result); |
| 5459 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5460 | |
| 5461 | return Result; |
| 5462 | } |
| 5463 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5464 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5465 | /// container that provides a \c getArgLoc() member function. |
| 5466 | /// |
| 5467 | /// This iterator is intended to be used with the iterator form of |
| 5468 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 5469 | template<typename ArgLocContainer> |
| 5470 | class TemplateArgumentLocContainerIterator { |
| 5471 | ArgLocContainer *Container; |
| 5472 | unsigned Index; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5473 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5474 | public: |
| 5475 | typedef TemplateArgumentLoc value_type; |
| 5476 | typedef TemplateArgumentLoc reference; |
| 5477 | typedef int difference_type; |
| 5478 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5479 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5480 | class pointer { |
| 5481 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5482 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5483 | public: |
| 5484 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5485 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5486 | const TemplateArgumentLoc *operator->() const { |
| 5487 | return &Arg; |
| 5488 | } |
| 5489 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5490 | |
| 5491 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 5492 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5494 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 5495 | unsigned Index) |
| 5496 | : Container(&Container), Index(Index) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5497 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5498 | TemplateArgumentLocContainerIterator &operator++() { |
| 5499 | ++Index; |
| 5500 | return *this; |
| 5501 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5502 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5503 | TemplateArgumentLocContainerIterator operator++(int) { |
| 5504 | TemplateArgumentLocContainerIterator Old(*this); |
| 5505 | ++(*this); |
| 5506 | return Old; |
| 5507 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5508 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5509 | TemplateArgumentLoc operator*() const { |
| 5510 | return Container->getArgLoc(Index); |
| 5511 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5512 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5513 | pointer operator->() const { |
| 5514 | return pointer(Container->getArgLoc(Index)); |
| 5515 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5516 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5517 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5518 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5519 | return X.Container == Y.Container && X.Index == Y.Index; |
| 5520 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5521 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5522 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5523 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5524 | return !(X == Y); |
| 5525 | } |
| 5526 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5527 | |
| 5528 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5529 | template <typename Derived> |
| 5530 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 5531 | TypeLocBuilder &TLB, |
| 5532 | TemplateSpecializationTypeLoc TL, |
| 5533 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5534 | TemplateArgumentListInfo NewTemplateArgs; |
| 5535 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5536 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5537 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 5538 | ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5539 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5540 | ArgIterator(TL, TL.getNumArgs()), |
| 5541 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 5542 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5543 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5544 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 5545 | |
| 5546 | QualType Result = |
| 5547 | getDerived().RebuildTemplateSpecializationType(Template, |
| 5548 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5549 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5550 | |
| 5551 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5552 | // Specializations of template template parameters are represented as |
| 5553 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 5554 | // within a dependent context can transform them into |
| 5555 | // DependentTemplateSpecializationTypes. |
| 5556 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5557 | DependentTemplateSpecializationTypeLoc NewTL |
| 5558 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5559 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5560 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5561 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5562 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5563 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5564 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5565 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5566 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5567 | return Result; |
| 5568 | } |
| 5569 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5570 | TemplateSpecializationTypeLoc NewTL |
| 5571 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5572 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5573 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5574 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5575 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5576 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5577 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5578 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5579 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5580 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5581 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5583 | template <typename Derived> |
| 5584 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 5585 | TypeLocBuilder &TLB, |
| 5586 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 5587 | TemplateName Template, |
| 5588 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5589 | TemplateArgumentListInfo NewTemplateArgs; |
| 5590 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5591 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 5592 | typedef TemplateArgumentLocContainerIterator< |
| 5593 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5594 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5595 | ArgIterator(TL, TL.getNumArgs()), |
| 5596 | NewTemplateArgs)) |
| 5597 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5598 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5599 | // 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] | 5600 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5601 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 5602 | QualType Result |
| 5603 | = getSema().Context.getDependentTemplateSpecializationType( |
| 5604 | TL.getTypePtr()->getKeyword(), |
| 5605 | DTN->getQualifier(), |
| 5606 | DTN->getIdentifier(), |
| 5607 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5608 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5609 | DependentTemplateSpecializationTypeLoc NewTL |
| 5610 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5611 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5612 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5613 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5614 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5615 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5616 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5617 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5618 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5619 | return Result; |
| 5620 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5621 | |
| 5622 | QualType Result |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5623 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5624 | TL.getTemplateNameLoc(), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5625 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5626 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5627 | if (!Result.isNull()) { |
| 5628 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 5629 | TemplateSpecializationTypeLoc NewTL |
| 5630 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5631 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5632 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5633 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5634 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5635 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5636 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5637 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5638 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5639 | return Result; |
| 5640 | } |
| 5641 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5642 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5643 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5644 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5645 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5646 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5647 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5648 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5649 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5650 | if (TL.getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5651 | QualifierLoc |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5652 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5653 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5654 | return QualType(); |
| 5655 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5656 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5657 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 5658 | if (NamedT.isNull()) |
| 5659 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 5660 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5661 | // C++0x [dcl.type.elab]p2: |
| 5662 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 5663 | // resolves to an alias template specialization, the |
| 5664 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5665 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 5666 | if (const TemplateSpecializationType *TST = |
| 5667 | NamedT->getAs<TemplateSpecializationType>()) { |
| 5668 | TemplateName Template = TST->getTemplateName(); |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 5669 | if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( |
| 5670 | Template.getAsTemplateDecl())) { |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5671 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 5672 | diag::err_tag_reference_non_tag) << 4; |
| 5673 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 5674 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5675 | } |
| 5676 | } |
| 5677 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5678 | QualType Result = TL.getType(); |
| 5679 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5680 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5681 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5682 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5683 | T->getKeyword(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5684 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5685 | if (Result.isNull()) |
| 5686 | return QualType(); |
| 5687 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5688 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5689 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5690 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5691 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5692 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5693 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5694 | |
| 5695 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5696 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5697 | TypeLocBuilder &TLB, |
| 5698 | AttributedTypeLoc TL) { |
| 5699 | const AttributedType *oldType = TL.getTypePtr(); |
| 5700 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5701 | if (modifiedType.isNull()) |
| 5702 | return QualType(); |
| 5703 | |
| 5704 | QualType result = TL.getType(); |
| 5705 | |
| 5706 | // FIXME: dependent operand expressions? |
| 5707 | if (getDerived().AlwaysRebuild() || |
| 5708 | modifiedType != oldType->getModifiedType()) { |
| 5709 | // TODO: this is really lame; we should really be rebuilding the |
| 5710 | // equivalent type from first principles. |
| 5711 | QualType equivalentType |
| 5712 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5713 | if (equivalentType.isNull()) |
| 5714 | return QualType(); |
Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 5715 | |
| 5716 | // Check whether we can add nullability; it is only represented as |
| 5717 | // type sugar, and therefore cannot be diagnosed in any other way. |
| 5718 | if (auto nullability = oldType->getImmediateNullability()) { |
| 5719 | if (!modifiedType->canHaveNullability()) { |
| 5720 | SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer) |
Douglas Gregor | aea7afd | 2015-06-24 22:02:08 +0000 | [diff] [blame] | 5721 | << DiagNullabilityKind(*nullability, false) << modifiedType; |
Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 5722 | return QualType(); |
| 5723 | } |
| 5724 | } |
| 5725 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5726 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5727 | modifiedType, |
| 5728 | equivalentType); |
| 5729 | } |
| 5730 | |
| 5731 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5732 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5733 | if (TL.hasAttrOperand()) |
| 5734 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5735 | if (TL.hasAttrExprOperand()) |
| 5736 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5737 | else if (TL.hasAttrEnumOperand()) |
| 5738 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5739 | |
| 5740 | return result; |
| 5741 | } |
| 5742 | |
| 5743 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5744 | QualType |
| 5745 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5746 | ParenTypeLoc TL) { |
| 5747 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5748 | if (Inner.isNull()) |
| 5749 | return QualType(); |
| 5750 | |
| 5751 | QualType Result = TL.getType(); |
| 5752 | if (getDerived().AlwaysRebuild() || |
| 5753 | Inner != TL.getInnerLoc().getType()) { |
| 5754 | Result = getDerived().RebuildParenType(Inner); |
| 5755 | if (Result.isNull()) |
| 5756 | return QualType(); |
| 5757 | } |
| 5758 | |
| 5759 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5760 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5761 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5762 | return Result; |
| 5763 | } |
| 5764 | |
| 5765 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5766 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5767 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5768 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5769 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5770 | NestedNameSpecifierLoc QualifierLoc |
| 5771 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5772 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5773 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5774 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5775 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5776 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5777 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5778 | QualifierLoc, |
| 5779 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5780 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5781 | if (Result.isNull()) |
| 5782 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5783 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5784 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5785 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5786 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5787 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5788 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5789 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5790 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5791 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5792 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5793 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5794 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5795 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5796 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5797 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5799 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5800 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5801 | QualType TreeTransform<Derived>:: |
| 5802 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5803 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5804 | NestedNameSpecifierLoc QualifierLoc; |
| 5805 | if (TL.getQualifierLoc()) { |
| 5806 | QualifierLoc |
| 5807 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5808 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5809 | return QualType(); |
| 5810 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5811 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5812 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5813 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | template<typename Derived> |
| 5817 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5818 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5819 | DependentTemplateSpecializationTypeLoc TL, |
| 5820 | NestedNameSpecifierLoc QualifierLoc) { |
| 5821 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5822 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5823 | TemplateArgumentListInfo NewTemplateArgs; |
| 5824 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5825 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5826 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5827 | typedef TemplateArgumentLocContainerIterator< |
| 5828 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5829 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5830 | ArgIterator(TL, TL.getNumArgs()), |
| 5831 | NewTemplateArgs)) |
| 5832 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5833 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5834 | QualType Result |
| 5835 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5836 | QualifierLoc, |
| 5837 | T->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5838 | TL.getTemplateNameLoc(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5839 | NewTemplateArgs); |
| 5840 | if (Result.isNull()) |
| 5841 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5842 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5843 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5844 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5845 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5846 | // Copy information relevant to the template specialization. |
| 5847 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5848 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5849 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5850 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5851 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5852 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5853 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5854 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5855 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5856 | // Copy information relevant to the elaborated type. |
| 5857 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5858 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5859 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5860 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5861 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5862 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5863 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5864 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5865 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5866 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5867 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5868 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5869 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5870 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5871 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5872 | TemplateSpecializationTypeLoc SpecTL |
| 5873 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5874 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5875 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5876 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5877 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5878 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5879 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5880 | } |
| 5881 | return Result; |
| 5882 | } |
| 5883 | |
| 5884 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5885 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5886 | PackExpansionTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5887 | QualType Pattern |
| 5888 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5889 | if (Pattern.isNull()) |
| 5890 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5891 | |
| 5892 | QualType Result = TL.getType(); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5893 | if (getDerived().AlwaysRebuild() || |
| 5894 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5895 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5896 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5897 | TL.getEllipsisLoc(), |
| 5898 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5899 | if (Result.isNull()) |
| 5900 | return QualType(); |
| 5901 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5902 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5903 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5904 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5905 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5909 | QualType |
| 5910 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5911 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5912 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5913 | TLB.pushFullCopy(TL); |
| 5914 | return TL.getType(); |
| 5915 | } |
| 5916 | |
| 5917 | template<typename Derived> |
| 5918 | QualType |
| 5919 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5920 | ObjCObjectTypeLoc TL) { |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 5921 | // Transform base type. |
| 5922 | QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); |
| 5923 | if (BaseType.isNull()) |
| 5924 | return QualType(); |
| 5925 | |
| 5926 | bool AnyChanged = BaseType != TL.getBaseLoc().getType(); |
| 5927 | |
| 5928 | // Transform type arguments. |
| 5929 | SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; |
| 5930 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { |
| 5931 | TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); |
| 5932 | TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); |
| 5933 | QualType TypeArg = TypeArgInfo->getType(); |
| 5934 | if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { |
| 5935 | AnyChanged = true; |
| 5936 | |
| 5937 | // We have a pack expansion. Instantiate it. |
| 5938 | const auto *PackExpansion = PackExpansionLoc.getType() |
| 5939 | ->castAs<PackExpansionType>(); |
| 5940 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5941 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 5942 | Unexpanded); |
| 5943 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 5944 | |
| 5945 | // Determine whether the set of unexpanded parameter packs can |
| 5946 | // and should be expanded. |
| 5947 | TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); |
| 5948 | bool Expand = false; |
| 5949 | bool RetainExpansion = false; |
| 5950 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 5951 | if (getDerived().TryExpandParameterPacks( |
| 5952 | PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), |
| 5953 | Unexpanded, Expand, RetainExpansion, NumExpansions)) |
| 5954 | return QualType(); |
| 5955 | |
| 5956 | if (!Expand) { |
| 5957 | // We can't expand this pack expansion into separate arguments yet; |
| 5958 | // just substitute into the pattern and create a new pack expansion |
| 5959 | // type. |
| 5960 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5961 | |
| 5962 | TypeLocBuilder TypeArgBuilder; |
| 5963 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 5964 | QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, |
| 5965 | PatternLoc); |
| 5966 | if (NewPatternType.isNull()) |
| 5967 | return QualType(); |
| 5968 | |
| 5969 | QualType NewExpansionType = SemaRef.Context.getPackExpansionType( |
| 5970 | NewPatternType, NumExpansions); |
| 5971 | auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); |
| 5972 | NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); |
| 5973 | NewTypeArgInfos.push_back( |
| 5974 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); |
| 5975 | continue; |
| 5976 | } |
| 5977 | |
| 5978 | // Substitute into the pack expansion pattern for each slice of the |
| 5979 | // pack. |
| 5980 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 5981 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 5982 | |
| 5983 | TypeLocBuilder TypeArgBuilder; |
| 5984 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 5985 | |
| 5986 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, |
| 5987 | PatternLoc); |
| 5988 | if (NewTypeArg.isNull()) |
| 5989 | return QualType(); |
| 5990 | |
| 5991 | NewTypeArgInfos.push_back( |
| 5992 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 5993 | } |
| 5994 | |
| 5995 | continue; |
| 5996 | } |
| 5997 | |
| 5998 | TypeLocBuilder TypeArgBuilder; |
| 5999 | TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); |
| 6000 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc); |
| 6001 | if (NewTypeArg.isNull()) |
| 6002 | return QualType(); |
| 6003 | |
| 6004 | // If nothing changed, just keep the old TypeSourceInfo. |
| 6005 | if (NewTypeArg == TypeArg) { |
| 6006 | NewTypeArgInfos.push_back(TypeArgInfo); |
| 6007 | continue; |
| 6008 | } |
| 6009 | |
| 6010 | NewTypeArgInfos.push_back( |
| 6011 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 6012 | AnyChanged = true; |
| 6013 | } |
| 6014 | |
| 6015 | QualType Result = TL.getType(); |
| 6016 | if (getDerived().AlwaysRebuild() || AnyChanged) { |
| 6017 | // Rebuild the type. |
| 6018 | Result = getDerived().RebuildObjCObjectType( |
| 6019 | BaseType, |
| 6020 | TL.getLocStart(), |
| 6021 | TL.getTypeArgsLAngleLoc(), |
| 6022 | NewTypeArgInfos, |
| 6023 | TL.getTypeArgsRAngleLoc(), |
| 6024 | TL.getProtocolLAngleLoc(), |
| 6025 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), |
| 6026 | TL.getNumProtocols()), |
| 6027 | TL.getProtocolLocs(), |
| 6028 | TL.getProtocolRAngleLoc()); |
| 6029 | |
| 6030 | if (Result.isNull()) |
| 6031 | return QualType(); |
| 6032 | } |
| 6033 | |
| 6034 | ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6035 | NewT.setHasBaseTypeAsWritten(true); |
| 6036 | NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); |
| 6037 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) |
| 6038 | NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); |
| 6039 | NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); |
| 6040 | NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 6041 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 6042 | NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 6043 | NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 6044 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6045 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6046 | |
| 6047 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6048 | QualType |
| 6049 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6050 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6051 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 6052 | if (PointeeType.isNull()) |
| 6053 | return QualType(); |
| 6054 | |
| 6055 | QualType Result = TL.getType(); |
| 6056 | if (getDerived().AlwaysRebuild() || |
| 6057 | PointeeType != TL.getPointeeLoc().getType()) { |
| 6058 | Result = getDerived().RebuildObjCObjectPointerType(PointeeType, |
| 6059 | TL.getStarLoc()); |
| 6060 | if (Result.isNull()) |
| 6061 | return QualType(); |
| 6062 | } |
| 6063 | |
| 6064 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 6065 | NewT.setStarLoc(TL.getStarLoc()); |
| 6066 | return Result; |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 6067 | } |
| 6068 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6069 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6070 | // Statement transformation |
| 6071 | //===----------------------------------------------------------------------===// |
| 6072 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6073 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6074 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6075 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6076 | } |
| 6077 | |
| 6078 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6079 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6080 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 6081 | return getDerived().TransformCompoundStmt(S, false); |
| 6082 | } |
| 6083 | |
| 6084 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6085 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6086 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6087 | bool IsStmtExpr) { |
Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 6088 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 6089 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6090 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6091 | bool SubStmtChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6092 | SmallVector<Stmt*, 8> Statements; |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6093 | for (auto *B : S->body()) { |
| 6094 | StmtResult Result = getDerived().TransformStmt(B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6095 | if (Result.isInvalid()) { |
| 6096 | // Immediately fail if this was a DeclStmt, since it's very |
| 6097 | // likely that this will cause problems for future statements. |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6098 | if (isa<DeclStmt>(B)) |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6099 | return StmtError(); |
| 6100 | |
| 6101 | // Otherwise, just keep processing substatements and fail later. |
| 6102 | SubStmtInvalid = true; |
| 6103 | continue; |
| 6104 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6105 | |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6106 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6107 | Statements.push_back(Result.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6109 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6110 | if (SubStmtInvalid) |
| 6111 | return StmtError(); |
| 6112 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6113 | if (!getDerived().AlwaysRebuild() && |
| 6114 | !SubStmtChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6115 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6116 | |
| 6117 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6118 | Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6119 | S->getRBracLoc(), |
| 6120 | IsStmtExpr); |
| 6121 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6122 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6123 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6124 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6125 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6126 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6127 | { |
Eli Friedman | 1f4f9dd | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 6128 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 6129 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6130 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6131 | // Transform the left-hand case value. |
| 6132 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 6133 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6134 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6135 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6136 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6137 | // Transform the right-hand case value (for the GNU case-range extension). |
| 6138 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 6139 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6140 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6141 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6142 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6143 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6144 | // Build the case statement. |
| 6145 | // Case statements are always rebuilt so that they will attached to their |
| 6146 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6147 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6148 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6149 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6150 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6151 | S->getColonLoc()); |
| 6152 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6153 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6154 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6155 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6156 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6157 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6158 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6159 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6160 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6161 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
| 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>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6167 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6168 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6169 | if (SubStmt.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 | // Default statements are always rebuilt |
| 6173 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6174 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6175 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6176 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6177 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6178 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6179 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6180 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6181 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6182 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6183 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6184 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 6185 | S->getDecl()); |
| 6186 | if (!LD) |
| 6187 | return StmtError(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6188 | |
| 6189 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6190 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 6191 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6192 | cast<LabelDecl>(LD), SourceLocation(), |
| 6193 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6194 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6195 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6196 | template <typename Derived> |
| 6197 | const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 6198 | if (!R) |
| 6199 | return R; |
| 6200 | |
| 6201 | switch (R->getKind()) { |
| 6202 | // Transform attributes with a pragma spelling by calling TransformXXXAttr. |
| 6203 | #define ATTR(X) |
| 6204 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 6205 | case attr::X: \ |
| 6206 | return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 6207 | #include "clang/Basic/AttrList.inc" |
| 6208 | default: |
| 6209 | return R; |
| 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | template <typename Derived> |
| 6214 | StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 6215 | bool AttrsChanged = false; |
| 6216 | SmallVector<const Attr *, 1> Attrs; |
| 6217 | |
| 6218 | // Visit attributes and keep track if any are transformed. |
| 6219 | for (const auto *I : S->getAttrs()) { |
| 6220 | const Attr *R = getDerived().TransformAttr(I); |
| 6221 | AttrsChanged |= (I != R); |
| 6222 | Attrs.push_back(R); |
| 6223 | } |
| 6224 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6225 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 6226 | if (SubStmt.isInvalid()) |
| 6227 | return StmtError(); |
| 6228 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6229 | if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6230 | return S; |
| 6231 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6232 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6233 | SubStmt.get()); |
| 6234 | } |
| 6235 | |
| 6236 | template<typename Derived> |
| 6237 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6238 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6239 | // Transform the condition |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6240 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6241 | S->getIfLoc(), S->getConditionVariable(), S->getCond(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6242 | S->isConstexpr() ? Sema::ConditionKind::ConstexprIf |
| 6243 | : Sema::ConditionKind::Boolean); |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6244 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6245 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6246 | |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6247 | // If this is a constexpr if, determine which arm we should instantiate. |
| 6248 | llvm::Optional<bool> ConstexprConditionValue; |
| 6249 | if (S->isConstexpr()) |
| 6250 | ConstexprConditionValue = Cond.getKnownValue(); |
| 6251 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6252 | // Transform the "then" branch. |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6253 | StmtResult Then; |
| 6254 | if (!ConstexprConditionValue || *ConstexprConditionValue) { |
| 6255 | Then = getDerived().TransformStmt(S->getThen()); |
| 6256 | if (Then.isInvalid()) |
| 6257 | return StmtError(); |
| 6258 | } else { |
| 6259 | Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart()); |
| 6260 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6261 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6262 | // Transform the "else" branch. |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6263 | StmtResult Else; |
| 6264 | if (!ConstexprConditionValue || !*ConstexprConditionValue) { |
| 6265 | Else = getDerived().TransformStmt(S->getElse()); |
| 6266 | if (Else.isInvalid()) |
| 6267 | return StmtError(); |
| 6268 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6269 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6270 | if (!getDerived().AlwaysRebuild() && |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6271 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6272 | Then.get() == S->getThen() && |
| 6273 | Else.get() == S->getElse()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6274 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6275 | |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6276 | return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond, |
| 6277 | Then.get(), S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6281 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6282 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6283 | // Transform the condition. |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6284 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6285 | S->getSwitchLoc(), S->getConditionVariable(), S->getCond(), |
| 6286 | Sema::ConditionKind::Switch); |
| 6287 | if (Cond.isInvalid()) |
| 6288 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6289 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6290 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6291 | StmtResult Switch |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6292 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6293 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6294 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6295 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6296 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6297 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6298 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6299 | return StmtError(); |
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 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6302 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 6303 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6304 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6305 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6306 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6307 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6308 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6309 | // Transform the condition |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6310 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6311 | S->getWhileLoc(), S->getConditionVariable(), S->getCond(), |
| 6312 | Sema::ConditionKind::Boolean); |
| 6313 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6314 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6315 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6316 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6317 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6318 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6319 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6320 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6321 | if (!getDerived().AlwaysRebuild() && |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6322 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6323 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6324 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6325 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6326 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6327 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6328 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6329 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6330 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6331 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6332 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6333 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6334 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6335 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6336 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6337 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6338 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6339 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6340 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6341 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6342 | if (!getDerived().AlwaysRebuild() && |
| 6343 | Cond.get() == S->getCond() && |
| 6344 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6345 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6346 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6347 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 6348 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6349 | S->getRParenLoc()); |
| 6350 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6351 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6352 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6353 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6354 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6355 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6356 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6357 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6358 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6359 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6360 | // In OpenMP loop region loop control variable must be captured and be |
| 6361 | // private. Perform analysis of first part (if any). |
| 6362 | if (getSema().getLangOpts().OpenMP && Init.isUsable()) |
| 6363 | getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get()); |
| 6364 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6365 | // Transform the condition |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6366 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6367 | S->getForLoc(), S->getConditionVariable(), S->getCond(), |
| 6368 | Sema::ConditionKind::Boolean); |
| 6369 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6370 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6371 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6372 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6373 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6374 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6375 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6376 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 6377 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6378 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6379 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6380 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6381 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6382 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6383 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6384 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6385 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6386 | if (!getDerived().AlwaysRebuild() && |
| 6387 | Init.get() == S->getInit() && |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6388 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6389 | Inc.get() == S->getInc() && |
| 6390 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6391 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6392 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6393 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6394 | Init.get(), Cond, FullInc, |
| 6395 | S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6396 | } |
| 6397 | |
| 6398 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6399 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6400 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6401 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 6402 | S->getLabel()); |
| 6403 | if (!LD) |
| 6404 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6405 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6406 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6407 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6408 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6409 | } |
| 6410 | |
| 6411 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6412 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6413 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6414 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6415 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6416 | return StmtError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6417 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6418 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6419 | if (!getDerived().AlwaysRebuild() && |
| 6420 | Target.get() == S->getTarget()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6421 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6422 | |
| 6423 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6424 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6425 | } |
| 6426 | |
| 6427 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6428 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6429 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6430 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6431 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6432 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6433 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6434 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6435 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6436 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6438 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6439 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6440 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6441 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Richard Smith | 3b71752 | 2014-08-21 20:51:13 +0000 | [diff] [blame] | 6442 | ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 6443 | /*NotCopyInit*/false); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6444 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6445 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6446 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6447 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6448 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6449 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6450 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6451 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6452 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6453 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6454 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6455 | bool DeclChanged = false; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6456 | SmallVector<Decl *, 4> Decls; |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 6457 | for (auto *D : S->decls()) { |
| 6458 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6459 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6460 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6461 | |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 6462 | if (Transformed != D) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6463 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6464 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6465 | Decls.push_back(Transformed); |
| 6466 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6467 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6468 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6469 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6470 | |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 6471 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6472 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6473 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6474 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6475 | StmtResult |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 6476 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6477 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6478 | SmallVector<Expr*, 8> Constraints; |
| 6479 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6480 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 6481 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6482 | ExprResult AsmString; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6483 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6484 | |
| 6485 | bool ExprsChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6486 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6487 | // Go through the outputs. |
| 6488 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 6489 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6490 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6491 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6492 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6493 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6494 | // Transform the output expr. |
| 6495 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6496 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6497 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6498 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6499 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6500 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6501 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6502 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6503 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6504 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6505 | // Go through the inputs. |
| 6506 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 6507 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6508 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6509 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6510 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6511 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6512 | // Transform the input expr. |
| 6513 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6514 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6515 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6516 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6517 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6518 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6519 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6520 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6521 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6522 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6523 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6524 | return S; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6525 | |
| 6526 | // Go through the clobbers. |
| 6527 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 6528 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6529 | |
| 6530 | // No need to transform the asm string literal. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6531 | AsmString = S->getAsmString(); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 6532 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 6533 | S->isVolatile(), S->getNumOutputs(), |
| 6534 | S->getNumInputs(), Names.data(), |
| 6535 | Constraints, Exprs, AsmString.get(), |
| 6536 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6537 | } |
| 6538 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6539 | template<typename Derived> |
| 6540 | StmtResult |
| 6541 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 6542 | ArrayRef<Token> AsmToks = |
| 6543 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 6544 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6545 | bool HadError = false, HadChange = false; |
| 6546 | |
| 6547 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 6548 | SmallVector<Expr*, 8> TransformedExprs; |
| 6549 | TransformedExprs.reserve(SrcExprs.size()); |
| 6550 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 6551 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 6552 | if (!Result.isUsable()) { |
| 6553 | HadError = true; |
| 6554 | } else { |
| 6555 | HadChange |= (Result.get() != SrcExprs[i]); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6556 | TransformedExprs.push_back(Result.get()); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6557 | } |
| 6558 | } |
| 6559 | |
| 6560 | if (HadError) return StmtError(); |
| 6561 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 6562 | return Owned(S); |
| 6563 | |
Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 6564 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6565 | AsmToks, S->getAsmString(), |
| 6566 | S->getNumOutputs(), S->getNumInputs(), |
| 6567 | S->getAllConstraints(), S->getClobbers(), |
| 6568 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6569 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6570 | |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 6571 | // C++ Coroutines TS |
| 6572 | |
| 6573 | template<typename Derived> |
| 6574 | StmtResult |
| 6575 | TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) { |
| 6576 | // The coroutine body should be re-formed by the caller if necessary. |
| 6577 | return getDerived().TransformStmt(S->getBody()); |
| 6578 | } |
| 6579 | |
| 6580 | template<typename Derived> |
| 6581 | StmtResult |
| 6582 | TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) { |
| 6583 | ExprResult Result = getDerived().TransformInitializer(S->getOperand(), |
| 6584 | /*NotCopyInit*/false); |
| 6585 | if (Result.isInvalid()) |
| 6586 | return StmtError(); |
| 6587 | |
| 6588 | // Always rebuild; we don't know if this needs to be injected into a new |
| 6589 | // context or if the promise type has changed. |
| 6590 | return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get()); |
| 6591 | } |
| 6592 | |
| 6593 | template<typename Derived> |
| 6594 | ExprResult |
| 6595 | TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) { |
| 6596 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 6597 | /*NotCopyInit*/false); |
| 6598 | if (Result.isInvalid()) |
| 6599 | return ExprError(); |
| 6600 | |
| 6601 | // Always rebuild; we don't know if this needs to be injected into a new |
| 6602 | // context or if the promise type has changed. |
| 6603 | return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get()); |
| 6604 | } |
| 6605 | |
| 6606 | template<typename Derived> |
| 6607 | ExprResult |
| 6608 | TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) { |
| 6609 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 6610 | /*NotCopyInit*/false); |
| 6611 | if (Result.isInvalid()) |
| 6612 | return ExprError(); |
| 6613 | |
| 6614 | // Always rebuild; we don't know if this needs to be injected into a new |
| 6615 | // context or if the promise type has changed. |
| 6616 | return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get()); |
| 6617 | } |
| 6618 | |
| 6619 | // Objective-C Statements. |
| 6620 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6621 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6622 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6623 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6624 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6625 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6626 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6627 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6628 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6629 | // Transform the @catch statements (if present). |
| 6630 | bool AnyCatchChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6631 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6632 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6633 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6634 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6635 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6636 | if (Catch.get() != S->getCatchStmt(I)) |
| 6637 | AnyCatchChanged = true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6638 | CatchStmts.push_back(Catch.get()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6639 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6640 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6641 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6642 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6643 | if (S->getFinallyStmt()) { |
| 6644 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 6645 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6646 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | // If nothing changed, just retain this statement. |
| 6650 | if (!getDerived().AlwaysRebuild() && |
| 6651 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6652 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6653 | Finally.get() == S->getFinallyStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6654 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6655 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6656 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6657 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6658 | CatchStmts, Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6659 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6660 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6661 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6662 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6663 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6664 | // Transform the @catch parameter, if there is one. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6665 | VarDecl *Var = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6666 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6667 | TypeSourceInfo *TSInfo = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6668 | if (FromVar->getTypeSourceInfo()) { |
| 6669 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 6670 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6671 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6672 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6673 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6674 | QualType T; |
| 6675 | if (TSInfo) |
| 6676 | T = TSInfo->getType(); |
| 6677 | else { |
| 6678 | T = getDerived().TransformType(FromVar->getType()); |
| 6679 | if (T.isNull()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6680 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6681 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6682 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6683 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 6684 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6685 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6686 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6687 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6688 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6689 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6690 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6691 | |
| 6692 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6693 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6694 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6695 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6696 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6697 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6698 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6699 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6700 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6701 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6702 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6703 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6704 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6705 | // If nothing changed, just retain this statement. |
| 6706 | if (!getDerived().AlwaysRebuild() && |
| 6707 | Body.get() == S->getFinallyBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6708 | return S; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6709 | |
| 6710 | // Build a new statement. |
| 6711 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6712 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6713 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6714 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6715 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6716 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6717 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6718 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6719 | if (S->getThrowExpr()) { |
| 6720 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 6721 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6722 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6723 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6724 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6725 | if (!getDerived().AlwaysRebuild() && |
| 6726 | Operand.get() == S->getThrowExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6727 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6728 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6729 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6731 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6732 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6733 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6734 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6735 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6736 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6737 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6738 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6739 | return StmtError(); |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 6740 | Object = |
| 6741 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 6742 | Object.get()); |
| 6743 | if (Object.isInvalid()) |
| 6744 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6745 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6746 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6747 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6748 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6749 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6750 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6751 | // If nothing change, just retain the current statement. |
| 6752 | if (!getDerived().AlwaysRebuild() && |
| 6753 | Object.get() == S->getSynchExpr() && |
| 6754 | Body.get() == S->getSynchBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6755 | return S; |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6756 | |
| 6757 | // Build a new statement. |
| 6758 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6759 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6760 | } |
| 6761 | |
| 6762 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6763 | StmtResult |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6764 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 6765 | ObjCAutoreleasePoolStmt *S) { |
| 6766 | // Transform the body. |
| 6767 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 6768 | if (Body.isInvalid()) |
| 6769 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6770 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6771 | // If nothing changed, just retain this statement. |
| 6772 | if (!getDerived().AlwaysRebuild() && |
| 6773 | Body.get() == S->getSubStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6774 | return S; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6775 | |
| 6776 | // Build a new statement. |
| 6777 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 6778 | S->getAtLoc(), Body.get()); |
| 6779 | } |
| 6780 | |
| 6781 | template<typename Derived> |
| 6782 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6783 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6784 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6785 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6786 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6787 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6788 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6789 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6790 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6791 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6792 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6793 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6794 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6795 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6796 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6797 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6798 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6799 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6800 | // If nothing changed, just retain this statement. |
| 6801 | if (!getDerived().AlwaysRebuild() && |
| 6802 | Element.get() == S->getElement() && |
| 6803 | Collection.get() == S->getCollection() && |
| 6804 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6805 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6806 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6807 | // Build a new statement. |
| 6808 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6809 | Element.get(), |
| 6810 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6811 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6812 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6813 | } |
| 6814 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6815 | template <typename Derived> |
| 6816 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6817 | // Transform the exception declaration, if any. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6818 | VarDecl *Var = nullptr; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6819 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 6820 | TypeSourceInfo *T = |
| 6821 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 6822 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6823 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6824 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6825 | Var = getDerived().RebuildExceptionDecl( |
| 6826 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 6827 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6828 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6829 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6830 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6831 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6832 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6833 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6834 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6835 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6836 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6837 | if (!getDerived().AlwaysRebuild() && !Var && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6838 | Handler.get() == S->getHandlerBlock()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6839 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6840 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6841 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6843 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6844 | template <typename Derived> |
| 6845 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6846 | // Transform the try block itself. |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6847 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6848 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6849 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6850 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6851 | // Transform the handlers. |
| 6852 | bool HandlerChanged = false; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6853 | SmallVector<Stmt *, 8> Handlers; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6854 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6855 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6856 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6857 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6858 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6859 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6860 | Handlers.push_back(Handler.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6861 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6862 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6863 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6864 | !HandlerChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6865 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6866 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6867 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6868 | Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6869 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6870 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6871 | template<typename Derived> |
| 6872 | StmtResult |
| 6873 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6874 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6875 | if (Range.isInvalid()) |
| 6876 | return StmtError(); |
| 6877 | |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 6878 | StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt()); |
| 6879 | if (Begin.isInvalid()) |
| 6880 | return StmtError(); |
| 6881 | StmtResult End = getDerived().TransformStmt(S->getEndStmt()); |
| 6882 | if (End.isInvalid()) |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6883 | return StmtError(); |
| 6884 | |
| 6885 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6886 | if (Cond.isInvalid()) |
| 6887 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6888 | if (Cond.get()) |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6889 | Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get()); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6890 | if (Cond.isInvalid()) |
| 6891 | return StmtError(); |
| 6892 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6893 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6894 | |
| 6895 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6896 | if (Inc.isInvalid()) |
| 6897 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6898 | if (Inc.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6899 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6900 | |
| 6901 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6902 | if (LoopVar.isInvalid()) |
| 6903 | return StmtError(); |
| 6904 | |
| 6905 | StmtResult NewStmt = S; |
| 6906 | if (getDerived().AlwaysRebuild() || |
| 6907 | Range.get() != S->getRangeStmt() || |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 6908 | Begin.get() != S->getBeginStmt() || |
| 6909 | End.get() != S->getEndStmt() || |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6910 | Cond.get() != S->getCond() || |
| 6911 | Inc.get() != S->getInc() || |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6912 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6913 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 6914 | S->getCoawaitLoc(), |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6915 | S->getColonLoc(), Range.get(), |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 6916 | Begin.get(), End.get(), |
| 6917 | Cond.get(), |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6918 | Inc.get(), LoopVar.get(), |
| 6919 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6920 | if (NewStmt.isInvalid()) |
| 6921 | return StmtError(); |
| 6922 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6923 | |
| 6924 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6925 | if (Body.isInvalid()) |
| 6926 | return StmtError(); |
| 6927 | |
| 6928 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6929 | // 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] | 6930 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6931 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 6932 | S->getCoawaitLoc(), |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6933 | S->getColonLoc(), Range.get(), |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 6934 | Begin.get(), End.get(), |
| 6935 | Cond.get(), |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6936 | Inc.get(), LoopVar.get(), |
| 6937 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6938 | if (NewStmt.isInvalid()) |
| 6939 | return StmtError(); |
| 6940 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6941 | |
| 6942 | if (NewStmt.get() == S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6943 | return S; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6944 | |
| 6945 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6946 | } |
| 6947 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6948 | template<typename Derived> |
| 6949 | StmtResult |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6950 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6951 | MSDependentExistsStmt *S) { |
| 6952 | // Transform the nested-name-specifier, if any. |
| 6953 | NestedNameSpecifierLoc QualifierLoc; |
| 6954 | if (S->getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6955 | QualifierLoc |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6956 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6957 | if (!QualifierLoc) |
| 6958 | return StmtError(); |
| 6959 | } |
| 6960 | |
| 6961 | // Transform the declaration name. |
| 6962 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6963 | if (NameInfo.getName()) { |
| 6964 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6965 | if (!NameInfo.getName()) |
| 6966 | return StmtError(); |
| 6967 | } |
| 6968 | |
| 6969 | // Check whether anything changed. |
| 6970 | if (!getDerived().AlwaysRebuild() && |
| 6971 | QualifierLoc == S->getQualifierLoc() && |
| 6972 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6973 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6974 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6975 | // Determine whether this name exists, if we can. |
| 6976 | CXXScopeSpec SS; |
| 6977 | SS.Adopt(QualifierLoc); |
| 6978 | bool Dependent = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6979 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6980 | case Sema::IER_Exists: |
| 6981 | if (S->isIfExists()) |
| 6982 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6983 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6984 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6985 | |
| 6986 | case Sema::IER_DoesNotExist: |
| 6987 | if (S->isIfNotExists()) |
| 6988 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6989 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6990 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6991 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6992 | case Sema::IER_Dependent: |
| 6993 | Dependent = true; |
| 6994 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6995 | |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6996 | case Sema::IER_Error: |
| 6997 | return StmtError(); |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6998 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6999 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7000 | // We need to continue with the instantiation, so do so now. |
| 7001 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 7002 | if (SubStmt.isInvalid()) |
| 7003 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7004 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7005 | // If we have resolved the name, just transform to the substatement. |
| 7006 | if (!Dependent) |
| 7007 | return SubStmt; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7008 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7009 | // The name is still dependent, so build a dependent expression again. |
| 7010 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 7011 | S->isIfExists(), |
| 7012 | QualifierLoc, |
| 7013 | NameInfo, |
| 7014 | SubStmt.get()); |
| 7015 | } |
| 7016 | |
| 7017 | template<typename Derived> |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 7018 | ExprResult |
| 7019 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 7020 | NestedNameSpecifierLoc QualifierLoc; |
| 7021 | if (E->getQualifierLoc()) { |
| 7022 | QualifierLoc |
| 7023 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7024 | if (!QualifierLoc) |
| 7025 | return ExprError(); |
| 7026 | } |
| 7027 | |
| 7028 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 7029 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 7030 | if (!PD) |
| 7031 | return ExprError(); |
| 7032 | |
| 7033 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 7034 | if (Base.isInvalid()) |
| 7035 | return ExprError(); |
| 7036 | |
| 7037 | return new (SemaRef.getASTContext()) |
| 7038 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 7039 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 7040 | QualifierLoc, E->getMemberLoc()); |
| 7041 | } |
| 7042 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7043 | template <typename Derived> |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 7044 | ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr( |
| 7045 | MSPropertySubscriptExpr *E) { |
| 7046 | auto BaseRes = getDerived().TransformExpr(E->getBase()); |
| 7047 | if (BaseRes.isInvalid()) |
| 7048 | return ExprError(); |
| 7049 | auto IdxRes = getDerived().TransformExpr(E->getIdx()); |
| 7050 | if (IdxRes.isInvalid()) |
| 7051 | return ExprError(); |
| 7052 | |
| 7053 | if (!getDerived().AlwaysRebuild() && |
| 7054 | BaseRes.get() == E->getBase() && |
| 7055 | IdxRes.get() == E->getIdx()) |
| 7056 | return E; |
| 7057 | |
| 7058 | return getDerived().RebuildArraySubscriptExpr( |
| 7059 | BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc()); |
| 7060 | } |
| 7061 | |
| 7062 | template <typename Derived> |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7063 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7064 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7065 | if (TryBlock.isInvalid()) |
| 7066 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7067 | |
| 7068 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7069 | if (Handler.isInvalid()) |
| 7070 | return StmtError(); |
| 7071 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7072 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 7073 | Handler.get() == S->getHandler()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7074 | return S; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7075 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 7076 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 7077 | TryBlock.get(), Handler.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7078 | } |
| 7079 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7080 | template <typename Derived> |
| 7081 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7082 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7083 | if (Block.isInvalid()) |
| 7084 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7085 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7086 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7087 | } |
| 7088 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7089 | template <typename Derived> |
| 7090 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7091 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7092 | if (FilterExpr.isInvalid()) |
| 7093 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7094 | |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7095 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7096 | if (Block.isInvalid()) |
| 7097 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7098 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7099 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 7100 | Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7101 | } |
| 7102 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7103 | template <typename Derived> |
| 7104 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 7105 | if (isa<SEHFinallyStmt>(Handler)) |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7106 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 7107 | else |
| 7108 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 7109 | } |
| 7110 | |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 7111 | template<typename Derived> |
| 7112 | StmtResult |
| 7113 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 7114 | return S; |
| 7115 | } |
| 7116 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7117 | //===----------------------------------------------------------------------===// |
| 7118 | // OpenMP directive transformation |
| 7119 | //===----------------------------------------------------------------------===// |
| 7120 | template <typename Derived> |
| 7121 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 7122 | OMPExecutableDirective *D) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7123 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7124 | // Transform the clauses |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7125 | llvm::SmallVector<OMPClause *, 16> TClauses; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7126 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 7127 | TClauses.reserve(Clauses.size()); |
| 7128 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 7129 | I != E; ++I) { |
| 7130 | if (*I) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 7131 | getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7132 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 7133 | getDerived().getSema().EndOpenMPClause(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7134 | if (Clause) |
| 7135 | TClauses.push_back(Clause); |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7136 | } else { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 7137 | TClauses.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7138 | } |
| 7139 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7140 | StmtResult AssociatedStmt; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 7141 | if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 7142 | getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), |
| 7143 | /*CurScope=*/nullptr); |
| 7144 | StmtResult Body; |
| 7145 | { |
| 7146 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 7147 | Body = getDerived().TransformStmt( |
| 7148 | cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt()); |
| 7149 | } |
| 7150 | AssociatedStmt = |
| 7151 | getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7152 | if (AssociatedStmt.isInvalid()) { |
| 7153 | return StmtError(); |
| 7154 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7155 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7156 | if (TClauses.size() != Clauses.size()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7157 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7158 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7159 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7160 | // Transform directive name for 'omp critical' directive. |
| 7161 | DeclarationNameInfo DirName; |
| 7162 | if (D->getDirectiveKind() == OMPD_critical) { |
| 7163 | DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 7164 | DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 7165 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7166 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
| 7167 | if (D->getDirectiveKind() == OMPD_cancellation_point) { |
| 7168 | CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7169 | } else if (D->getDirectiveKind() == OMPD_cancel) { |
| 7170 | CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7171 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7172 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7173 | return getDerived().RebuildOMPExecutableDirective( |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7174 | D->getDirectiveKind(), DirName, CancelRegion, TClauses, |
| 7175 | AssociatedStmt.get(), D->getLocStart(), D->getLocEnd()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7176 | } |
| 7177 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7178 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7179 | StmtResult |
| 7180 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 7181 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7182 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| 7183 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7184 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7185 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7186 | return Res; |
| 7187 | } |
| 7188 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7189 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7190 | StmtResult |
| 7191 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 7192 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7193 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| 7194 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7195 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7196 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7197 | return Res; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7198 | } |
| 7199 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7200 | template <typename Derived> |
| 7201 | StmtResult |
| 7202 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 7203 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7204 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| 7205 | D->getLocStart()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7206 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7207 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7208 | return Res; |
| 7209 | } |
| 7210 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7211 | template <typename Derived> |
| 7212 | StmtResult |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7213 | TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 7214 | DeclarationNameInfo DirName; |
| 7215 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, |
| 7216 | D->getLocStart()); |
| 7217 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7218 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7219 | return Res; |
| 7220 | } |
| 7221 | |
| 7222 | template <typename Derived> |
| 7223 | StmtResult |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7224 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 7225 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7226 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| 7227 | D->getLocStart()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7228 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7229 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7230 | return Res; |
| 7231 | } |
| 7232 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 7233 | template <typename Derived> |
| 7234 | StmtResult |
| 7235 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 7236 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7237 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| 7238 | D->getLocStart()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 7239 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7240 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7241 | return Res; |
| 7242 | } |
| 7243 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7244 | template <typename Derived> |
| 7245 | StmtResult |
| 7246 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 7247 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7248 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| 7249 | D->getLocStart()); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7250 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7251 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7252 | return Res; |
| 7253 | } |
| 7254 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7255 | template <typename Derived> |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 7256 | StmtResult |
| 7257 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 7258 | DeclarationNameInfo DirName; |
| 7259 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| 7260 | D->getLocStart()); |
| 7261 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7262 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7263 | return Res; |
| 7264 | } |
| 7265 | |
| 7266 | template <typename Derived> |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7267 | StmtResult |
| 7268 | TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 7269 | getDerived().getSema().StartOpenMPDSABlock( |
| 7270 | OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart()); |
| 7271 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7272 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7273 | return Res; |
| 7274 | } |
| 7275 | |
| 7276 | template <typename Derived> |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7277 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 7278 | OMPParallelForDirective *D) { |
| 7279 | DeclarationNameInfo DirName; |
| 7280 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| 7281 | nullptr, D->getLocStart()); |
| 7282 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7283 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7284 | return Res; |
| 7285 | } |
| 7286 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7287 | template <typename Derived> |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 7288 | StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 7289 | OMPParallelForSimdDirective *D) { |
| 7290 | DeclarationNameInfo DirName; |
| 7291 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, |
| 7292 | nullptr, D->getLocStart()); |
| 7293 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7294 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7295 | return Res; |
| 7296 | } |
| 7297 | |
| 7298 | template <typename Derived> |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7299 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 7300 | OMPParallelSectionsDirective *D) { |
| 7301 | DeclarationNameInfo DirName; |
| 7302 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| 7303 | nullptr, D->getLocStart()); |
| 7304 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7305 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7306 | return Res; |
| 7307 | } |
| 7308 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7309 | template <typename Derived> |
| 7310 | StmtResult |
| 7311 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 7312 | DeclarationNameInfo DirName; |
| 7313 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| 7314 | D->getLocStart()); |
| 7315 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7316 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7317 | return Res; |
| 7318 | } |
| 7319 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7320 | template <typename Derived> |
| 7321 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 7322 | OMPTaskyieldDirective *D) { |
| 7323 | DeclarationNameInfo DirName; |
| 7324 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| 7325 | D->getLocStart()); |
| 7326 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7327 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7328 | return Res; |
| 7329 | } |
| 7330 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 7331 | template <typename Derived> |
| 7332 | StmtResult |
| 7333 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 7334 | DeclarationNameInfo DirName; |
| 7335 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| 7336 | D->getLocStart()); |
| 7337 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7338 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7339 | return Res; |
| 7340 | } |
| 7341 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 7342 | template <typename Derived> |
| 7343 | StmtResult |
| 7344 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 7345 | DeclarationNameInfo DirName; |
| 7346 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| 7347 | D->getLocStart()); |
| 7348 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7349 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7350 | return Res; |
| 7351 | } |
| 7352 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7353 | template <typename Derived> |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 7354 | StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( |
| 7355 | OMPTaskgroupDirective *D) { |
| 7356 | DeclarationNameInfo DirName; |
| 7357 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, |
| 7358 | D->getLocStart()); |
| 7359 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7360 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7361 | return Res; |
| 7362 | } |
| 7363 | |
| 7364 | template <typename Derived> |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7365 | StmtResult |
| 7366 | TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 7367 | DeclarationNameInfo DirName; |
| 7368 | getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, |
| 7369 | D->getLocStart()); |
| 7370 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7371 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7372 | return Res; |
| 7373 | } |
| 7374 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 7375 | template <typename Derived> |
| 7376 | StmtResult |
| 7377 | TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 7378 | DeclarationNameInfo DirName; |
| 7379 | getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, |
| 7380 | D->getLocStart()); |
| 7381 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7382 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7383 | return Res; |
| 7384 | } |
| 7385 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 7386 | template <typename Derived> |
| 7387 | StmtResult |
| 7388 | TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 7389 | DeclarationNameInfo DirName; |
| 7390 | getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, |
| 7391 | D->getLocStart()); |
| 7392 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7393 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7394 | return Res; |
| 7395 | } |
| 7396 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 7397 | template <typename Derived> |
| 7398 | StmtResult |
| 7399 | TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 7400 | DeclarationNameInfo DirName; |
| 7401 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, |
| 7402 | D->getLocStart()); |
| 7403 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7404 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7405 | return Res; |
| 7406 | } |
| 7407 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7408 | template <typename Derived> |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 7409 | StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( |
| 7410 | OMPTargetDataDirective *D) { |
| 7411 | DeclarationNameInfo DirName; |
| 7412 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, |
| 7413 | D->getLocStart()); |
| 7414 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7415 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7416 | return Res; |
| 7417 | } |
| 7418 | |
| 7419 | template <typename Derived> |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7420 | StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective( |
| 7421 | OMPTargetEnterDataDirective *D) { |
| 7422 | DeclarationNameInfo DirName; |
| 7423 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName, |
| 7424 | nullptr, D->getLocStart()); |
| 7425 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7426 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7427 | return Res; |
| 7428 | } |
| 7429 | |
| 7430 | template <typename Derived> |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 7431 | StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective( |
| 7432 | OMPTargetExitDataDirective *D) { |
| 7433 | DeclarationNameInfo DirName; |
| 7434 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName, |
| 7435 | nullptr, D->getLocStart()); |
| 7436 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7437 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7438 | return Res; |
| 7439 | } |
| 7440 | |
| 7441 | template <typename Derived> |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 7442 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective( |
| 7443 | OMPTargetParallelDirective *D) { |
| 7444 | DeclarationNameInfo DirName; |
| 7445 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName, |
| 7446 | nullptr, D->getLocStart()); |
| 7447 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7448 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7449 | return Res; |
| 7450 | } |
| 7451 | |
| 7452 | template <typename Derived> |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7453 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective( |
| 7454 | OMPTargetParallelForDirective *D) { |
| 7455 | DeclarationNameInfo DirName; |
| 7456 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName, |
| 7457 | nullptr, D->getLocStart()); |
| 7458 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7459 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7460 | return Res; |
| 7461 | } |
| 7462 | |
| 7463 | template <typename Derived> |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7464 | StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective( |
| 7465 | OMPTargetUpdateDirective *D) { |
| 7466 | DeclarationNameInfo DirName; |
| 7467 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName, |
| 7468 | nullptr, D->getLocStart()); |
| 7469 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7470 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7471 | return Res; |
| 7472 | } |
| 7473 | |
| 7474 | template <typename Derived> |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7475 | StmtResult |
| 7476 | TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 7477 | DeclarationNameInfo DirName; |
| 7478 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, |
| 7479 | D->getLocStart()); |
| 7480 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7481 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7482 | return Res; |
| 7483 | } |
| 7484 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7485 | template <typename Derived> |
| 7486 | StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( |
| 7487 | OMPCancellationPointDirective *D) { |
| 7488 | DeclarationNameInfo DirName; |
| 7489 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, |
| 7490 | nullptr, D->getLocStart()); |
| 7491 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7492 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7493 | return Res; |
| 7494 | } |
| 7495 | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7496 | template <typename Derived> |
| 7497 | StmtResult |
| 7498 | TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { |
| 7499 | DeclarationNameInfo DirName; |
| 7500 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, |
| 7501 | D->getLocStart()); |
| 7502 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7503 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7504 | return Res; |
| 7505 | } |
| 7506 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7507 | template <typename Derived> |
| 7508 | StmtResult |
| 7509 | TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { |
| 7510 | DeclarationNameInfo DirName; |
| 7511 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr, |
| 7512 | D->getLocStart()); |
| 7513 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7514 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7515 | return Res; |
| 7516 | } |
| 7517 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7518 | template <typename Derived> |
| 7519 | StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective( |
| 7520 | OMPTaskLoopSimdDirective *D) { |
| 7521 | DeclarationNameInfo DirName; |
| 7522 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName, |
| 7523 | nullptr, D->getLocStart()); |
| 7524 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7525 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7526 | return Res; |
| 7527 | } |
| 7528 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7529 | template <typename Derived> |
| 7530 | StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective( |
| 7531 | OMPDistributeDirective *D) { |
| 7532 | DeclarationNameInfo DirName; |
| 7533 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr, |
| 7534 | D->getLocStart()); |
| 7535 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7536 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7537 | return Res; |
| 7538 | } |
| 7539 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7540 | template <typename Derived> |
| 7541 | StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective( |
| 7542 | OMPDistributeParallelForDirective *D) { |
| 7543 | DeclarationNameInfo DirName; |
| 7544 | getDerived().getSema().StartOpenMPDSABlock( |
| 7545 | OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart()); |
| 7546 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7547 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7548 | return Res; |
| 7549 | } |
| 7550 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame^] | 7551 | template <typename Derived> |
| 7552 | StmtResult |
| 7553 | TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective( |
| 7554 | OMPDistributeParallelForSimdDirective *D) { |
| 7555 | DeclarationNameInfo DirName; |
| 7556 | getDerived().getSema().StartOpenMPDSABlock( |
| 7557 | OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart()); |
| 7558 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7559 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7560 | return Res; |
| 7561 | } |
| 7562 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7563 | //===----------------------------------------------------------------------===// |
| 7564 | // OpenMP clause transformation |
| 7565 | //===----------------------------------------------------------------------===// |
| 7566 | template <typename Derived> |
| 7567 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 7568 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 7569 | if (Cond.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7570 | return nullptr; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7571 | return getDerived().RebuildOMPIfClause( |
| 7572 | C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(), |
| 7573 | C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd()); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7574 | } |
| 7575 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7576 | template <typename Derived> |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7577 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 7578 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 7579 | if (Cond.isInvalid()) |
| 7580 | return nullptr; |
| 7581 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(), |
| 7582 | C->getLParenLoc(), C->getLocEnd()); |
| 7583 | } |
| 7584 | |
| 7585 | template <typename Derived> |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7586 | OMPClause * |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7587 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 7588 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 7589 | if (NumThreads.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7590 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7591 | return getDerived().RebuildOMPNumThreadsClause( |
| 7592 | NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7593 | } |
| 7594 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7595 | template <typename Derived> |
| 7596 | OMPClause * |
| 7597 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 7598 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 7599 | if (E.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7600 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7601 | return getDerived().RebuildOMPSafelenClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7602 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7603 | } |
| 7604 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7605 | template <typename Derived> |
| 7606 | OMPClause * |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7607 | TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { |
| 7608 | ExprResult E = getDerived().TransformExpr(C->getSimdlen()); |
| 7609 | if (E.isInvalid()) |
| 7610 | return nullptr; |
| 7611 | return getDerived().RebuildOMPSimdlenClause( |
| 7612 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7613 | } |
| 7614 | |
| 7615 | template <typename Derived> |
| 7616 | OMPClause * |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7617 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 7618 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 7619 | if (E.isInvalid()) |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 7620 | return nullptr; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7621 | return getDerived().RebuildOMPCollapseClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7622 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7623 | } |
| 7624 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7625 | template <typename Derived> |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7626 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7627 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7628 | return getDerived().RebuildOMPDefaultClause( |
| 7629 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(), |
| 7630 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7631 | } |
| 7632 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7633 | template <typename Derived> |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7634 | OMPClause * |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7635 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7636 | return getDerived().RebuildOMPProcBindClause( |
| 7637 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(), |
| 7638 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7639 | } |
| 7640 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7641 | template <typename Derived> |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7642 | OMPClause * |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7643 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 7644 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 7645 | if (E.isInvalid()) |
| 7646 | return nullptr; |
| 7647 | return getDerived().RebuildOMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7648 | C->getFirstScheduleModifier(), C->getSecondScheduleModifier(), |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7649 | C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(), |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7650 | C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(), |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7651 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd()); |
| 7652 | } |
| 7653 | |
| 7654 | template <typename Derived> |
| 7655 | OMPClause * |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7656 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7657 | ExprResult E; |
| 7658 | if (auto *Num = C->getNumForLoops()) { |
| 7659 | E = getDerived().TransformExpr(Num); |
| 7660 | if (E.isInvalid()) |
| 7661 | return nullptr; |
| 7662 | } |
| 7663 | return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(), |
| 7664 | C->getLParenLoc(), E.get()); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7665 | } |
| 7666 | |
| 7667 | template <typename Derived> |
| 7668 | OMPClause * |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7669 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 7670 | // No need to rebuild this clause, no template-dependent parameters. |
| 7671 | return C; |
| 7672 | } |
| 7673 | |
| 7674 | template <typename Derived> |
| 7675 | OMPClause * |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7676 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 7677 | // No need to rebuild this clause, no template-dependent parameters. |
| 7678 | return C; |
| 7679 | } |
| 7680 | |
| 7681 | template <typename Derived> |
| 7682 | OMPClause * |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7683 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 7684 | // No need to rebuild this clause, no template-dependent parameters. |
| 7685 | return C; |
| 7686 | } |
| 7687 | |
| 7688 | template <typename Derived> |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7689 | OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 7690 | // No need to rebuild this clause, no template-dependent parameters. |
| 7691 | return C; |
| 7692 | } |
| 7693 | |
| 7694 | template <typename Derived> |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7695 | OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 7696 | // No need to rebuild this clause, no template-dependent parameters. |
| 7697 | return C; |
| 7698 | } |
| 7699 | |
| 7700 | template <typename Derived> |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7701 | OMPClause * |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7702 | TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 7703 | // No need to rebuild this clause, no template-dependent parameters. |
| 7704 | return C; |
| 7705 | } |
| 7706 | |
| 7707 | template <typename Derived> |
| 7708 | OMPClause * |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7709 | TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 7710 | // No need to rebuild this clause, no template-dependent parameters. |
| 7711 | return C; |
| 7712 | } |
| 7713 | |
| 7714 | template <typename Derived> |
| 7715 | OMPClause * |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7716 | TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 7717 | // No need to rebuild this clause, no template-dependent parameters. |
| 7718 | return C; |
| 7719 | } |
| 7720 | |
| 7721 | template <typename Derived> |
| 7722 | OMPClause * |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7723 | TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { |
| 7724 | // No need to rebuild this clause, no template-dependent parameters. |
| 7725 | return C; |
| 7726 | } |
| 7727 | |
| 7728 | template <typename Derived> |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7729 | OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { |
| 7730 | // No need to rebuild this clause, no template-dependent parameters. |
| 7731 | return C; |
| 7732 | } |
| 7733 | |
| 7734 | template <typename Derived> |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7735 | OMPClause * |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7736 | TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) { |
| 7737 | // No need to rebuild this clause, no template-dependent parameters. |
| 7738 | return C; |
| 7739 | } |
| 7740 | |
| 7741 | template <typename Derived> |
| 7742 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7743 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7744 | llvm::SmallVector<Expr *, 16> Vars; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7745 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7746 | for (auto *VE : C->varlists()) { |
| 7747 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7748 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7749 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7750 | Vars.push_back(EVar.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7751 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7752 | return getDerived().RebuildOMPPrivateClause( |
| 7753 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7754 | } |
| 7755 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7756 | template <typename Derived> |
| 7757 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 7758 | OMPFirstprivateClause *C) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7759 | llvm::SmallVector<Expr *, 16> Vars; |
| 7760 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7761 | for (auto *VE : C->varlists()) { |
| 7762 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7763 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7764 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7765 | Vars.push_back(EVar.get()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7766 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7767 | return getDerived().RebuildOMPFirstprivateClause( |
| 7768 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7769 | } |
| 7770 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7771 | template <typename Derived> |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7772 | OMPClause * |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7773 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 7774 | llvm::SmallVector<Expr *, 16> Vars; |
| 7775 | Vars.reserve(C->varlist_size()); |
| 7776 | for (auto *VE : C->varlists()) { |
| 7777 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7778 | if (EVar.isInvalid()) |
| 7779 | return nullptr; |
| 7780 | Vars.push_back(EVar.get()); |
| 7781 | } |
| 7782 | return getDerived().RebuildOMPLastprivateClause( |
| 7783 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7784 | } |
| 7785 | |
| 7786 | template <typename Derived> |
| 7787 | OMPClause * |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7788 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 7789 | llvm::SmallVector<Expr *, 16> Vars; |
| 7790 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7791 | for (auto *VE : C->varlists()) { |
| 7792 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7793 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7794 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7795 | Vars.push_back(EVar.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7796 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7797 | return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(), |
| 7798 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7799 | } |
| 7800 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7801 | template <typename Derived> |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7802 | OMPClause * |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7803 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 7804 | llvm::SmallVector<Expr *, 16> Vars; |
| 7805 | Vars.reserve(C->varlist_size()); |
| 7806 | for (auto *VE : C->varlists()) { |
| 7807 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7808 | if (EVar.isInvalid()) |
| 7809 | return nullptr; |
| 7810 | Vars.push_back(EVar.get()); |
| 7811 | } |
| 7812 | CXXScopeSpec ReductionIdScopeSpec; |
| 7813 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 7814 | |
| 7815 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 7816 | if (NameInfo.getName()) { |
| 7817 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7818 | if (!NameInfo.getName()) |
| 7819 | return nullptr; |
| 7820 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7821 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 7822 | // The Scope boundary is a duplication of the previous decl. |
| 7823 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 7824 | for (auto *E : C->reduction_ops()) { |
| 7825 | // Transform all the decls. |
| 7826 | if (E) { |
| 7827 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 7828 | UnresolvedSet<8> Decls; |
| 7829 | for (auto *D : ULE->decls()) { |
| 7830 | NamedDecl *InstD = |
| 7831 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 7832 | Decls.addDecl(InstD, InstD->getAccess()); |
| 7833 | } |
| 7834 | UnresolvedReductions.push_back( |
| 7835 | UnresolvedLookupExpr::Create( |
| 7836 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 7837 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), |
| 7838 | NameInfo, /*ADL=*/true, ULE->isOverloaded(), |
| 7839 | Decls.begin(), Decls.end())); |
| 7840 | } else |
| 7841 | UnresolvedReductions.push_back(nullptr); |
| 7842 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7843 | return getDerived().RebuildOMPReductionClause( |
| 7844 | Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(), |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7845 | C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7846 | } |
| 7847 | |
| 7848 | template <typename Derived> |
| 7849 | OMPClause * |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7850 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 7851 | llvm::SmallVector<Expr *, 16> Vars; |
| 7852 | Vars.reserve(C->varlist_size()); |
| 7853 | for (auto *VE : C->varlists()) { |
| 7854 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7855 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7856 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7857 | Vars.push_back(EVar.get()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7858 | } |
| 7859 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 7860 | if (Step.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7861 | return nullptr; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7862 | return getDerived().RebuildOMPLinearClause( |
| 7863 | Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(), |
| 7864 | C->getModifierLoc(), C->getColonLoc(), C->getLocEnd()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7865 | } |
| 7866 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7867 | template <typename Derived> |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7868 | OMPClause * |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7869 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 7870 | llvm::SmallVector<Expr *, 16> Vars; |
| 7871 | Vars.reserve(C->varlist_size()); |
| 7872 | for (auto *VE : C->varlists()) { |
| 7873 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7874 | if (EVar.isInvalid()) |
| 7875 | return nullptr; |
| 7876 | Vars.push_back(EVar.get()); |
| 7877 | } |
| 7878 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 7879 | if (Alignment.isInvalid()) |
| 7880 | return nullptr; |
| 7881 | return getDerived().RebuildOMPAlignedClause( |
| 7882 | Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(), |
| 7883 | C->getColonLoc(), C->getLocEnd()); |
| 7884 | } |
| 7885 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7886 | template <typename Derived> |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7887 | OMPClause * |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7888 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 7889 | llvm::SmallVector<Expr *, 16> Vars; |
| 7890 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7891 | for (auto *VE : C->varlists()) { |
| 7892 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7893 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7894 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7895 | Vars.push_back(EVar.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7896 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7897 | return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(), |
| 7898 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7899 | } |
| 7900 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7901 | template <typename Derived> |
| 7902 | OMPClause * |
| 7903 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 7904 | llvm::SmallVector<Expr *, 16> Vars; |
| 7905 | Vars.reserve(C->varlist_size()); |
| 7906 | for (auto *VE : C->varlists()) { |
| 7907 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7908 | if (EVar.isInvalid()) |
| 7909 | return nullptr; |
| 7910 | Vars.push_back(EVar.get()); |
| 7911 | } |
| 7912 | return getDerived().RebuildOMPCopyprivateClause( |
| 7913 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7914 | } |
| 7915 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7916 | template <typename Derived> |
| 7917 | OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 7918 | llvm::SmallVector<Expr *, 16> Vars; |
| 7919 | Vars.reserve(C->varlist_size()); |
| 7920 | for (auto *VE : C->varlists()) { |
| 7921 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7922 | if (EVar.isInvalid()) |
| 7923 | return nullptr; |
| 7924 | Vars.push_back(EVar.get()); |
| 7925 | } |
| 7926 | return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(), |
| 7927 | C->getLParenLoc(), C->getLocEnd()); |
| 7928 | } |
| 7929 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7930 | template <typename Derived> |
| 7931 | OMPClause * |
| 7932 | TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { |
| 7933 | llvm::SmallVector<Expr *, 16> Vars; |
| 7934 | Vars.reserve(C->varlist_size()); |
| 7935 | for (auto *VE : C->varlists()) { |
| 7936 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7937 | if (EVar.isInvalid()) |
| 7938 | return nullptr; |
| 7939 | Vars.push_back(EVar.get()); |
| 7940 | } |
| 7941 | return getDerived().RebuildOMPDependClause( |
| 7942 | C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars, |
| 7943 | C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7944 | } |
| 7945 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7946 | template <typename Derived> |
| 7947 | OMPClause * |
| 7948 | TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { |
| 7949 | ExprResult E = getDerived().TransformExpr(C->getDevice()); |
| 7950 | if (E.isInvalid()) |
| 7951 | return nullptr; |
| 7952 | return getDerived().RebuildOMPDeviceClause( |
| 7953 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7954 | } |
| 7955 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7956 | template <typename Derived> |
| 7957 | OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) { |
| 7958 | llvm::SmallVector<Expr *, 16> Vars; |
| 7959 | Vars.reserve(C->varlist_size()); |
| 7960 | for (auto *VE : C->varlists()) { |
| 7961 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7962 | if (EVar.isInvalid()) |
| 7963 | return nullptr; |
| 7964 | Vars.push_back(EVar.get()); |
| 7965 | } |
| 7966 | return getDerived().RebuildOMPMapClause( |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7967 | C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(), |
| 7968 | C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(), |
| 7969 | C->getLParenLoc(), C->getLocEnd()); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7970 | } |
| 7971 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7972 | template <typename Derived> |
| 7973 | OMPClause * |
| 7974 | TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 7975 | ExprResult E = getDerived().TransformExpr(C->getNumTeams()); |
| 7976 | if (E.isInvalid()) |
| 7977 | return nullptr; |
| 7978 | return getDerived().RebuildOMPNumTeamsClause( |
| 7979 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7980 | } |
| 7981 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7982 | template <typename Derived> |
| 7983 | OMPClause * |
| 7984 | TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 7985 | ExprResult E = getDerived().TransformExpr(C->getThreadLimit()); |
| 7986 | if (E.isInvalid()) |
| 7987 | return nullptr; |
| 7988 | return getDerived().RebuildOMPThreadLimitClause( |
| 7989 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7990 | } |
| 7991 | |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7992 | template <typename Derived> |
| 7993 | OMPClause * |
| 7994 | TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) { |
| 7995 | ExprResult E = getDerived().TransformExpr(C->getPriority()); |
| 7996 | if (E.isInvalid()) |
| 7997 | return nullptr; |
| 7998 | return getDerived().RebuildOMPPriorityClause( |
| 7999 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 8000 | } |
| 8001 | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8002 | template <typename Derived> |
| 8003 | OMPClause * |
| 8004 | TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 8005 | ExprResult E = getDerived().TransformExpr(C->getGrainsize()); |
| 8006 | if (E.isInvalid()) |
| 8007 | return nullptr; |
| 8008 | return getDerived().RebuildOMPGrainsizeClause( |
| 8009 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 8010 | } |
| 8011 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8012 | template <typename Derived> |
| 8013 | OMPClause * |
| 8014 | TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) { |
| 8015 | ExprResult E = getDerived().TransformExpr(C->getNumTasks()); |
| 8016 | if (E.isInvalid()) |
| 8017 | return nullptr; |
| 8018 | return getDerived().RebuildOMPNumTasksClause( |
| 8019 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 8020 | } |
| 8021 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8022 | template <typename Derived> |
| 8023 | OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) { |
| 8024 | ExprResult E = getDerived().TransformExpr(C->getHint()); |
| 8025 | if (E.isInvalid()) |
| 8026 | return nullptr; |
| 8027 | return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(), |
| 8028 | C->getLParenLoc(), C->getLocEnd()); |
| 8029 | } |
| 8030 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8031 | template <typename Derived> |
| 8032 | OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause( |
| 8033 | OMPDistScheduleClause *C) { |
| 8034 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 8035 | if (E.isInvalid()) |
| 8036 | return nullptr; |
| 8037 | return getDerived().RebuildOMPDistScheduleClause( |
| 8038 | C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(), |
| 8039 | C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd()); |
| 8040 | } |
| 8041 | |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8042 | template <typename Derived> |
| 8043 | OMPClause * |
| 8044 | TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 8045 | return C; |
| 8046 | } |
| 8047 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8048 | template <typename Derived> |
| 8049 | OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) { |
| 8050 | llvm::SmallVector<Expr *, 16> Vars; |
| 8051 | Vars.reserve(C->varlist_size()); |
| 8052 | for (auto *VE : C->varlists()) { |
| 8053 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8054 | if (EVar.isInvalid()) |
| 8055 | return 0; |
| 8056 | Vars.push_back(EVar.get()); |
| 8057 | } |
| 8058 | return getDerived().RebuildOMPToClause(Vars, C->getLocStart(), |
| 8059 | C->getLParenLoc(), C->getLocEnd()); |
| 8060 | } |
| 8061 | |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8062 | template <typename Derived> |
| 8063 | OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) { |
| 8064 | llvm::SmallVector<Expr *, 16> Vars; |
| 8065 | Vars.reserve(C->varlist_size()); |
| 8066 | for (auto *VE : C->varlists()) { |
| 8067 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8068 | if (EVar.isInvalid()) |
| 8069 | return 0; |
| 8070 | Vars.push_back(EVar.get()); |
| 8071 | } |
| 8072 | return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(), |
| 8073 | C->getLParenLoc(), C->getLocEnd()); |
| 8074 | } |
| 8075 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 8076 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8077 | // Expression transformation |
| 8078 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8079 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8080 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8081 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 8082 | if (!E->isTypeDependent()) |
| 8083 | return E; |
| 8084 | |
| 8085 | return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| 8086 | E->getIdentType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8087 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8088 | |
| 8089 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8090 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8091 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8092 | NestedNameSpecifierLoc QualifierLoc; |
| 8093 | if (E->getQualifierLoc()) { |
| 8094 | QualifierLoc |
| 8095 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8096 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8097 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 8098 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8099 | |
| 8100 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8101 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 8102 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8103 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8104 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8105 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 8106 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 8107 | if (NameInfo.getName()) { |
| 8108 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8109 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8110 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 8111 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8112 | |
| 8113 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8114 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 8115 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8116 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8117 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8118 | |
| 8119 | // Mark it referenced in the new context regardless. |
| 8120 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8121 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8122 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8123 | return E; |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 8124 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8125 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8126 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8127 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8128 | TemplateArgs = &TransArgs; |
| 8129 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 8130 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8131 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8132 | E->getNumTemplateArgs(), |
| 8133 | TransArgs)) |
| 8134 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8135 | } |
| 8136 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8137 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8138 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8141 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8142 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8143 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8144 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8145 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8146 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8147 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8148 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8149 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8150 | return E; |
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 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8156 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8159 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8160 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8161 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8162 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8164 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8165 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8166 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8167 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8168 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8169 | } |
| 8170 | |
| 8171 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8172 | ExprResult |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 8173 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 8174 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 8175 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 8176 | return SemaRef.MaybeBindToTemporary(E); |
| 8177 | } |
| 8178 | |
| 8179 | template<typename Derived> |
| 8180 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8181 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 8182 | ExprResult ControllingExpr = |
| 8183 | getDerived().TransformExpr(E->getControllingExpr()); |
| 8184 | if (ControllingExpr.isInvalid()) |
| 8185 | return ExprError(); |
| 8186 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 8187 | SmallVector<Expr *, 4> AssocExprs; |
| 8188 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8189 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 8190 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 8191 | if (TS) { |
| 8192 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 8193 | if (!AssocType) |
| 8194 | return ExprError(); |
| 8195 | AssocTypes.push_back(AssocType); |
| 8196 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8197 | AssocTypes.push_back(nullptr); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8198 | } |
| 8199 | |
| 8200 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 8201 | if (AssocExpr.isInvalid()) |
| 8202 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8203 | AssocExprs.push_back(AssocExpr.get()); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8204 | } |
| 8205 | |
| 8206 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 8207 | E->getDefaultLoc(), |
| 8208 | E->getRParenLoc(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8209 | ControllingExpr.get(), |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 8210 | AssocTypes, |
| 8211 | AssocExprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8212 | } |
| 8213 | |
| 8214 | template<typename Derived> |
| 8215 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8216 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8217 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8218 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8219 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8222 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8223 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8224 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8225 | E->getRParen()); |
| 8226 | } |
| 8227 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8228 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 8229 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 8230 | /// object available. |
| 8231 | template<typename Derived> |
| 8232 | ExprResult |
| 8233 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 8234 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8235 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8236 | else |
| 8237 | return getDerived().TransformExpr(E); |
| 8238 | } |
| 8239 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8240 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8241 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8242 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 8243 | ExprResult SubExpr; |
| 8244 | if (E->getOpcode() == UO_AddrOf) |
| 8245 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 8246 | else |
| 8247 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8248 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8249 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8250 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8251 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8252 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8253 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8254 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 8255 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8256 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8257 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8258 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8259 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8260 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8261 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 8262 | // Transform the type. |
| 8263 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8264 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8265 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8266 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8267 | // Transform all of the components into components similar to what the |
| 8268 | // parser uses. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8269 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 8270 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 8271 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8272 | // template code that we don't care. |
| 8273 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8274 | typedef Sema::OffsetOfComponent Component; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 8275 | SmallVector<Component, 4> Components; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8276 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 8277 | const OffsetOfNode &ON = E->getComponent(I); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8278 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 8279 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 8280 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 8281 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8282 | switch (ON.getKind()) { |
James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 8283 | case OffsetOfNode::Array: { |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8284 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8285 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8286 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8287 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8288 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8289 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 8290 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8291 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8292 | break; |
| 8293 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8294 | |
James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 8295 | case OffsetOfNode::Field: |
| 8296 | case OffsetOfNode::Identifier: |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8297 | Comp.isBrackets = false; |
| 8298 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 8299 | if (!Comp.U.IdentInfo) |
| 8300 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8301 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8302 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8303 | |
James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 8304 | case OffsetOfNode::Base: |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 8305 | // Will be recomputed during the rebuild. |
| 8306 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8307 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8308 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8309 | Components.push_back(Comp); |
| 8310 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8311 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8312 | // If nothing changed, retain the existing expression. |
| 8313 | if (!getDerived().AlwaysRebuild() && |
| 8314 | Type == E->getTypeSourceInfo() && |
| 8315 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8316 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8317 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8318 | // Build a new offsetof expression. |
| 8319 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 8320 | Components, E->getRParenLoc()); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 8321 | } |
| 8322 | |
| 8323 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8324 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 8325 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
Hubert Tong | 2cded44 | 2015-09-01 22:50:31 +0000 | [diff] [blame] | 8326 | assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 8327 | "opaque value expression requires transformation"); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8328 | return E; |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 8329 | } |
| 8330 | |
| 8331 | template<typename Derived> |
| 8332 | ExprResult |
Kaelyn Takata | e1f49d5 | 2014-10-27 18:07:20 +0000 | [diff] [blame] | 8333 | TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { |
| 8334 | return E; |
| 8335 | } |
| 8336 | |
| 8337 | template<typename Derived> |
| 8338 | ExprResult |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 8339 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 8340 | // Rebuild the syntactic form. The original syntactic form has |
| 8341 | // opaque-value expressions in it, so strip those away and rebuild |
| 8342 | // the result. This is a really awful way of doing this, but the |
| 8343 | // better solution (rebuilding the semantic expressions and |
| 8344 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 8345 | // TreeTransform to not strip away implicit conversions. |
| 8346 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 8347 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 8348 | if (result.isInvalid()) return ExprError(); |
| 8349 | |
| 8350 | // If that gives us a pseudo-object result back, the pseudo-object |
| 8351 | // expression must have been an lvalue-to-rvalue conversion which we |
| 8352 | // should reapply. |
| 8353 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8354 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 8355 | |
| 8356 | return result; |
| 8357 | } |
| 8358 | |
| 8359 | template<typename Derived> |
| 8360 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 8361 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 8362 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8363 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 8364 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 8365 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 8366 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 8367 | if (!NewT) |
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 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 8370 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8371 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8372 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 8373 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 8374 | E->getKind(), |
| 8375 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8376 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8377 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 8378 | // C++0x [expr.sizeof]p1: |
| 8379 | // The operand is either an expression, which is an unevaluated operand |
| 8380 | // [...] |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 8381 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 8382 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8383 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8384 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 8385 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 8386 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 8387 | ExprResult SubExpr; |
| 8388 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 8389 | if (auto *DRE = |
| 8390 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 8391 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 8392 | PE, DRE, false, &RecoveryTSI); |
| 8393 | else |
| 8394 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 8395 | |
| 8396 | if (RecoveryTSI) { |
| 8397 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 8398 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 8399 | } else if (SubExpr.isInvalid()) |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 8400 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8401 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 8402 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8403 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8404 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 8405 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 8406 | E->getOperatorLoc(), |
| 8407 | E->getKind(), |
| 8408 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8409 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8410 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8411 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8412 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8413 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8414 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8415 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8416 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8417 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8418 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8419 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8420 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8421 | |
| 8422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8423 | if (!getDerived().AlwaysRebuild() && |
| 8424 | LHS.get() == E->getLHS() && |
| 8425 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8426 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8427 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8428 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8429 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8430 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8431 | E->getRBracketLoc()); |
| 8432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8433 | |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 8434 | template <typename Derived> |
| 8435 | ExprResult |
| 8436 | TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) { |
| 8437 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 8438 | if (Base.isInvalid()) |
| 8439 | return ExprError(); |
| 8440 | |
| 8441 | ExprResult LowerBound; |
| 8442 | if (E->getLowerBound()) { |
| 8443 | LowerBound = getDerived().TransformExpr(E->getLowerBound()); |
| 8444 | if (LowerBound.isInvalid()) |
| 8445 | return ExprError(); |
| 8446 | } |
| 8447 | |
| 8448 | ExprResult Length; |
| 8449 | if (E->getLength()) { |
| 8450 | Length = getDerived().TransformExpr(E->getLength()); |
| 8451 | if (Length.isInvalid()) |
| 8452 | return ExprError(); |
| 8453 | } |
| 8454 | |
| 8455 | if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 8456 | LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength()) |
| 8457 | return E; |
| 8458 | |
| 8459 | return getDerived().RebuildOMPArraySectionExpr( |
| 8460 | Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(), |
| 8461 | Length.get(), E->getRBracketLoc()); |
| 8462 | } |
| 8463 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8464 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8465 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8466 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8467 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8468 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8469 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8470 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8471 | |
| 8472 | // Transform arguments. |
| 8473 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8474 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8475 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8476 | &ArgChanged)) |
| 8477 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8478 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8479 | if (!getDerived().AlwaysRebuild() && |
| 8480 | Callee.get() == E->getCallee() && |
| 8481 | !ArgChanged) |
Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 8482 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8483 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8484 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8485 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8486 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8487 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8488 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8489 | E->getRParenLoc()); |
| 8490 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8491 | |
| 8492 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8493 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8494 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8495 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8496 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8497 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8498 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8499 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 8500 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8501 | QualifierLoc |
| 8502 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8503 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8504 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8505 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 8506 | } |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8507 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8508 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 8509 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8510 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 8511 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8512 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8513 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8514 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 8515 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 8516 | if (FoundDecl == E->getMemberDecl()) { |
| 8517 | FoundDecl = Member; |
| 8518 | } else { |
| 8519 | FoundDecl = cast_or_null<NamedDecl>( |
| 8520 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 8521 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8522 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 8523 | } |
| 8524 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8525 | if (!getDerived().AlwaysRebuild() && |
| 8526 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8527 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 8528 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 8529 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8530 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8531 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 8532 | // Mark it referenced in the new context regardless. |
| 8533 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8534 | SemaRef.MarkMemberReferenced(E); |
| 8535 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8536 | return E; |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 8537 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8538 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8539 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8540 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8541 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 8542 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8543 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8544 | E->getNumTemplateArgs(), |
| 8545 | TransArgs)) |
| 8546 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 8547 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8548 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8549 | // FIXME: Bogus source location for the operator |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 8550 | SourceLocation FakeOperatorLoc = |
| 8551 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8552 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8553 | // FIXME: to do this check properly, we will need to preserve the |
| 8554 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8555 | // base (and therefore couldn't do the check) and a |
| 8556 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8557 | NamedDecl *FirstQualifierInScope = nullptr; |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8558 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8559 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8560 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8561 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8562 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8563 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 8564 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 8565 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8566 | (E->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8567 | ? &TransArgs : nullptr), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8568 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8569 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8570 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8571 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8572 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8573 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8574 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8575 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8576 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8577 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8578 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8579 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8580 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8581 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8582 | if (!getDerived().AlwaysRebuild() && |
| 8583 | LHS.get() == E->getLHS() && |
| 8584 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8585 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8586 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 8587 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 8588 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 8589 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8590 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8591 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8592 | } |
| 8593 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8594 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8595 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8596 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8597 | CompoundAssignOperator *E) { |
| 8598 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8599 | } |
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 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8602 | ExprResult TreeTransform<Derived>:: |
| 8603 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 8604 | // Just rebuild the common and RHS expressions and see whether we |
| 8605 | // get any changes. |
| 8606 | |
| 8607 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 8608 | if (commonExpr.isInvalid()) |
| 8609 | return ExprError(); |
| 8610 | |
| 8611 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 8612 | if (rhs.isInvalid()) |
| 8613 | return ExprError(); |
| 8614 | |
| 8615 | if (!getDerived().AlwaysRebuild() && |
| 8616 | commonExpr.get() == e->getCommon() && |
| 8617 | rhs.get() == e->getFalseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8618 | return e; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8619 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8620 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8621 | e->getQuestionLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8622 | nullptr, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 8623 | e->getColonLoc(), |
| 8624 | rhs.get()); |
| 8625 | } |
| 8626 | |
| 8627 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8628 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8629 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8630 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8631 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8632 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8633 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8634 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8635 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8636 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8637 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8638 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8639 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8640 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8641 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8642 | if (!getDerived().AlwaysRebuild() && |
| 8643 | Cond.get() == E->getCond() && |
| 8644 | LHS.get() == E->getLHS() && |
| 8645 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8646 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8647 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8648 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 8649 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8650 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 8651 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8652 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8653 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8654 | |
| 8655 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8656 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8657 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 8658 | // Implicit casts are eliminated during transformation, since they |
| 8659 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8660 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8661 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8663 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8664 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8665 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8666 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8667 | if (!Type) |
| 8668 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8669 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8670 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8671 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8672 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8673 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8674 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8675 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8676 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8677 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8678 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8679 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 8680 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8681 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8682 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8683 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8684 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8685 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8686 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8687 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8688 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8689 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 8690 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 8691 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8692 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8693 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8694 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8695 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8696 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8697 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8698 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8699 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8700 | Init.get() == E->getInitializer()) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8701 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8702 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 8703 | // Note: the expression type doesn't necessarily match the |
| 8704 | // type-as-written, but that's okay, because it should always be |
| 8705 | // derivable from the initializer. |
| 8706 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 8707 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8708 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8709 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8711 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8712 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8713 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8714 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8715 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8716 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8717 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8718 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8719 | if (!getDerived().AlwaysRebuild() && |
| 8720 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8721 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8722 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8723 | // FIXME: Bad source location |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 8724 | SourceLocation FakeOperatorLoc = |
| 8725 | SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8726 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8727 | E->getAccessorLoc(), |
| 8728 | E->getAccessor()); |
| 8729 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8730 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8731 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8732 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8733 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 8734 | if (InitListExpr *Syntactic = E->getSyntacticForm()) |
| 8735 | E = Syntactic; |
| 8736 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8737 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8738 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8739 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8740 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8741 | Inits, &InitChanged)) |
| 8742 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8743 | |
Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 8744 | if (!getDerived().AlwaysRebuild() && !InitChanged) { |
| 8745 | // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr |
| 8746 | // in some cases. We can't reuse it in general, because the syntactic and |
| 8747 | // semantic forms are linked, and we can't know that semantic form will |
| 8748 | // match even if the syntactic form does. |
| 8749 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8750 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8751 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 8752 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8754 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8755 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8756 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8757 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8758 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8759 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 8760 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8761 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8762 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8763 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8764 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 8765 | // transform the designators. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8766 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8767 | bool ExprChanged = false; |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8768 | for (const DesignatedInitExpr::Designator &D : E->designators()) { |
| 8769 | if (D.isFieldDesignator()) { |
| 8770 | Desig.AddDesignator(Designator::getField(D.getFieldName(), |
| 8771 | D.getDotLoc(), |
| 8772 | D.getFieldLoc())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8773 | continue; |
| 8774 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8775 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8776 | if (D.isArrayDesignator()) { |
| 8777 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8778 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8779 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8780 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8781 | Desig.AddDesignator( |
| 8782 | Designator::getArray(Index.get(), D.getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8783 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8784 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8785 | ArrayExprs.push_back(Index.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8786 | continue; |
| 8787 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8788 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8789 | assert(D.isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8790 | ExprResult Start |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8791 | = getDerived().TransformExpr(E->getArrayRangeStart(D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8792 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8793 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8794 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8795 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8796 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8797 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8798 | |
| 8799 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8800 | End.get(), |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8801 | D.getLBracketLoc(), |
| 8802 | D.getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8803 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 8804 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) || |
| 8805 | End.get() != E->getArrayRangeEnd(D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8806 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8807 | ArrayExprs.push_back(Start.get()); |
| 8808 | ArrayExprs.push_back(End.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8809 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8810 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8811 | if (!getDerived().AlwaysRebuild() && |
| 8812 | Init.get() == E->getInit() && |
| 8813 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8814 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8815 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8816 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8817 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8818 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8819 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8820 | |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 8821 | // Seems that if TransformInitListExpr() only works on the syntactic form of an |
| 8822 | // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. |
| 8823 | template<typename Derived> |
| 8824 | ExprResult |
| 8825 | TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( |
| 8826 | DesignatedInitUpdateExpr *E) { |
| 8827 | llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " |
| 8828 | "initializer"); |
| 8829 | return ExprError(); |
| 8830 | } |
| 8831 | |
| 8832 | template<typename Derived> |
| 8833 | ExprResult |
| 8834 | TreeTransform<Derived>::TransformNoInitExpr( |
| 8835 | NoInitExpr *E) { |
| 8836 | llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); |
| 8837 | return ExprError(); |
| 8838 | } |
| 8839 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8840 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8841 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8842 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8843 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 8844 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8845 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 8846 | // FIXME: Will we ever have proper type location here? Will we actually |
| 8847 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8848 | QualType T = getDerived().TransformType(E->getType()); |
| 8849 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8850 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8851 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8852 | if (!getDerived().AlwaysRebuild() && |
| 8853 | T == E->getType()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8854 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8855 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8856 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 8857 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8858 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8859 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8860 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8861 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 8862 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 8863 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8864 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8865 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8866 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8867 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8868 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8869 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8870 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 8871 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8872 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8873 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8874 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8875 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 8876 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8877 | } |
| 8878 | |
| 8879 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8880 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8881 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8882 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8883 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8884 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 8885 | &ArgumentChanged)) |
| 8886 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8887 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8888 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8889 | Inits, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8890 | E->getRParenLoc()); |
| 8891 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8892 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8893 | /// \brief Transform an address-of-label expression. |
| 8894 | /// |
| 8895 | /// By default, the transformation of an address-of-label expression always |
| 8896 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 8897 | /// the corresponding label statement by semantic analysis. |
| 8898 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8899 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8900 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 8901 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 8902 | E->getLabel()); |
| 8903 | if (!LD) |
| 8904 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8905 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8906 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 8907 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8908 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8909 | |
| 8910 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8911 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8912 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8913 | SemaRef.ActOnStartStmtExpr(); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8914 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8915 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8916 | if (SubStmt.isInvalid()) { |
| 8917 | SemaRef.ActOnStmtExprError(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8918 | return ExprError(); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8919 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8920 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8921 | if (!getDerived().AlwaysRebuild() && |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8922 | SubStmt.get() == E->getSubStmt()) { |
| 8923 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 8924 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8925 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 8926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8927 | |
| 8928 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8929 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8930 | E->getRParenLoc()); |
| 8931 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8932 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8933 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8934 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8935 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8936 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8937 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8938 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8939 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8940 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8941 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8942 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8943 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8944 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8945 | if (RHS.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 | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8948 | if (!getDerived().AlwaysRebuild() && |
| 8949 | Cond.get() == E->getCond() && |
| 8950 | LHS.get() == E->getLHS() && |
| 8951 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8952 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8953 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8954 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8955 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8956 | E->getRParenLoc()); |
| 8957 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8958 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8959 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8960 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8961 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8962 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8963 | } |
| 8964 | |
| 8965 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8966 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8967 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8968 | switch (E->getOperator()) { |
| 8969 | case OO_New: |
| 8970 | case OO_Delete: |
| 8971 | case OO_Array_New: |
| 8972 | case OO_Array_Delete: |
| 8973 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8974 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8975 | case OO_Call: { |
| 8976 | // This is a call to an object's operator(). |
| 8977 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 8978 | |
| 8979 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8980 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8981 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8982 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8983 | |
| 8984 | // FIXME: Poor location information |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 8985 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| 8986 | static_cast<Expr *>(Object.get())->getLocEnd()); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8987 | |
| 8988 | // Transform the call arguments. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8989 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8990 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8991 | Args)) |
| 8992 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8993 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8994 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8995 | Args, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 8996 | E->getLocEnd()); |
| 8997 | } |
| 8998 | |
| 8999 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 9000 | case OO_##Name: |
| 9001 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 9002 | #include "clang/Basic/OperatorKinds.def" |
| 9003 | case OO_Subscript: |
| 9004 | // Handled below. |
| 9005 | break; |
| 9006 | |
| 9007 | case OO_Conditional: |
| 9008 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9009 | |
| 9010 | case OO_None: |
| 9011 | case NUM_OVERLOADED_OPERATORS: |
| 9012 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9013 | } |
| 9014 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9015 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9016 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9017 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9018 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9019 | ExprResult First; |
| 9020 | if (E->getOperator() == OO_Amp) |
| 9021 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 9022 | else |
| 9023 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9024 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9025 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9026 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9027 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9028 | if (E->getNumArgs() == 2) { |
| 9029 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 9030 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9031 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9032 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9034 | if (!getDerived().AlwaysRebuild() && |
| 9035 | Callee.get() == E->getCallee() && |
| 9036 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9037 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9038 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9039 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9040 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 9041 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 9042 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9043 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 9044 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9045 | Callee.get(), |
| 9046 | First.get(), |
| 9047 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9049 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9050 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9051 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9052 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 9053 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9054 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9055 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9056 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9057 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 9058 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 9059 | // Transform the callee. |
| 9060 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 9061 | if (Callee.isInvalid()) |
| 9062 | return ExprError(); |
| 9063 | |
| 9064 | // Transform exec config. |
| 9065 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 9066 | if (EC.isInvalid()) |
| 9067 | return ExprError(); |
| 9068 | |
| 9069 | // Transform arguments. |
| 9070 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9071 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9072 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 9073 | &ArgChanged)) |
| 9074 | return ExprError(); |
| 9075 | |
| 9076 | if (!getDerived().AlwaysRebuild() && |
| 9077 | Callee.get() == E->getCallee() && |
| 9078 | !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9079 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 9080 | |
| 9081 | // FIXME: Wrong source location information for the '('. |
| 9082 | SourceLocation FakeLParenLoc |
| 9083 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 9084 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9085 | Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 9086 | E->getRParenLoc(), EC.get()); |
| 9087 | } |
| 9088 | |
| 9089 | template<typename Derived> |
| 9090 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9091 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9092 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9093 | if (!Type) |
| 9094 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9095 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9096 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9097 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9098 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9099 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9100 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9101 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9102 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9103 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9104 | return E; |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 9105 | return getDerived().RebuildCXXNamedCastExpr( |
| 9106 | E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 9107 | Type, E->getAngleBrackets().getEnd(), |
| 9108 | // FIXME. this should be '(' location |
| 9109 | E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9110 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9112 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9113 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9114 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 9115 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9116 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9117 | |
| 9118 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9119 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9120 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 9121 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9122 | } |
| 9123 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9124 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9125 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9126 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9127 | CXXReinterpretCastExpr *E) { |
| 9128 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9129 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9130 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9131 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9132 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9133 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 9134 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9135 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9137 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9138 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9139 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9140 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9141 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9142 | if (!Type) |
| 9143 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9144 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9145 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9146 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9147 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9148 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9150 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9151 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9152 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9153 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9154 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9155 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 9156 | E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9157 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9158 | E->getRParenLoc()); |
| 9159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9161 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9162 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9163 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9164 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 9165 | TypeSourceInfo *TInfo |
| 9166 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 9167 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9168 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9169 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9170 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 9171 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9172 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9173 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 9174 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 9175 | E->getLocStart(), |
| 9176 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9177 | E->getLocEnd()); |
| 9178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9179 | |
Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 9180 | // We don't know whether the subexpression is potentially evaluated until |
| 9181 | // after we perform semantic analysis. We speculatively assume it is |
| 9182 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9183 | // potentially evaluated. |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 9184 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 9185 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9186 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9187 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9188 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9189 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9190 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9191 | if (!getDerived().AlwaysRebuild() && |
| 9192 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9193 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9194 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 9195 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 9196 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9197 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9198 | E->getLocEnd()); |
| 9199 | } |
| 9200 | |
| 9201 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9202 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 9203 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 9204 | if (E->isTypeOperand()) { |
| 9205 | TypeSourceInfo *TInfo |
| 9206 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 9207 | if (!TInfo) |
| 9208 | return ExprError(); |
| 9209 | |
| 9210 | if (!getDerived().AlwaysRebuild() && |
| 9211 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9212 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 9213 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 9214 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 9215 | E->getLocStart(), |
| 9216 | TInfo, |
| 9217 | E->getLocEnd()); |
| 9218 | } |
| 9219 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 9220 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 9221 | |
| 9222 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 9223 | if (SubExpr.isInvalid()) |
| 9224 | return ExprError(); |
| 9225 | |
| 9226 | if (!getDerived().AlwaysRebuild() && |
| 9227 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9228 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 9229 | |
| 9230 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 9231 | E->getLocStart(), |
| 9232 | SubExpr.get(), |
| 9233 | E->getLocEnd()); |
| 9234 | } |
| 9235 | |
| 9236 | template<typename Derived> |
| 9237 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9238 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9239 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9240 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9241 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9242 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9243 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9244 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9245 | CXXNullPtrLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9246 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9247 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9248 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9249 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9250 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9251 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 9252 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9253 | |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 9254 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 9255 | // Make sure that we capture 'this'. |
| 9256 | getSema().CheckCXXThisCapture(E->getLocStart()); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9257 | return E; |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 9258 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9259 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 9260 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9262 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9263 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9264 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9265 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9266 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9267 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9268 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9269 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9270 | if (!getDerived().AlwaysRebuild() && |
| 9271 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9272 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9273 | |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 9274 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 9275 | E->isThrownVariableInScope()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9276 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9277 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9278 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9279 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9280 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9281 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9282 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 9283 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9284 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9285 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9286 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 9287 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9288 | Param == E->getParam()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9289 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9290 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 9291 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9292 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9293 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9294 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9295 | ExprResult |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 9296 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 9297 | FieldDecl *Field |
| 9298 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 9299 | E->getField())); |
| 9300 | if (!Field) |
| 9301 | return ExprError(); |
| 9302 | |
| 9303 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9304 | return E; |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 9305 | |
| 9306 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 9307 | } |
| 9308 | |
| 9309 | template<typename Derived> |
| 9310 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9311 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 9312 | CXXScalarValueInitExpr *E) { |
| 9313 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9314 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9315 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9316 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9317 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9318 | T == E->getTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9319 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9320 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9321 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9322 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 9323 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9324 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9325 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9326 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9327 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9328 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9329 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 9330 | TypeSourceInfo *AllocTypeInfo |
| 9331 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 9332 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9333 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9334 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9335 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9336 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9337 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9338 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9339 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9340 | // Transform the placement arguments (if any). |
| 9341 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9342 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9343 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9344 | E->getNumPlacementArgs(), true, |
| 9345 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9346 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9347 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9348 | // Transform the initializer (if any). |
| 9349 | Expr *OldInit = E->getInitializer(); |
| 9350 | ExprResult NewInit; |
| 9351 | if (OldInit) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 9352 | NewInit = getDerived().TransformInitializer(OldInit, true); |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9353 | if (NewInit.isInvalid()) |
| 9354 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9355 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9356 | // Transform new operator and delete operator. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9357 | FunctionDecl *OperatorNew = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9358 | if (E->getOperatorNew()) { |
| 9359 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9360 | getDerived().TransformDecl(E->getLocStart(), |
| 9361 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9362 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9363 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9364 | } |
| 9365 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9366 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9367 | if (E->getOperatorDelete()) { |
| 9368 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9369 | getDerived().TransformDecl(E->getLocStart(), |
| 9370 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9371 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9372 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9373 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9374 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9375 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 9376 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9377 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9378 | NewInit.get() == OldInit && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9379 | OperatorNew == E->getOperatorNew() && |
| 9380 | OperatorDelete == E->getOperatorDelete() && |
| 9381 | !ArgumentChanged) { |
| 9382 | // Mark any declarations we need as referenced. |
| 9383 | // FIXME: instantiation-specific. |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9384 | if (OperatorNew) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9385 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9386 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9387 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9388 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9389 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 9390 | QualType ElementType |
| 9391 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 9392 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 9393 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 9394 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9395 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 9396 | } |
| 9397 | } |
| 9398 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9399 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9400 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9402 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 9403 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 9404 | if (!ArraySize.get()) { |
| 9405 | // If no array size was specified, but the new expression was |
| 9406 | // instantiated with an array type (e.g., "new T" where T is |
| 9407 | // instantiated with "int[4]"), extract the outer bound from the |
| 9408 | // array type as our array size. We do this with constant and |
| 9409 | // dependently-sized array types. |
| 9410 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 9411 | if (!ArrayT) { |
| 9412 | // Do nothing |
| 9413 | } else if (const ConstantArrayType *ConsArrayT |
| 9414 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9415 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 9416 | SemaRef.Context.getSizeType(), |
| 9417 | /*FIXME:*/ E->getLocStart()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 9418 | AllocType = ConsArrayT->getElementType(); |
| 9419 | } else if (const DependentSizedArrayType *DepArrayT |
| 9420 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 9421 | if (DepArrayT->getSizeExpr()) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9422 | ArraySize = DepArrayT->getSizeExpr(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 9423 | AllocType = DepArrayT->getElementType(); |
| 9424 | } |
| 9425 | } |
| 9426 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9427 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9428 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 9429 | E->isGlobalNew(), |
| 9430 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9431 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9432 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 9433 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9434 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 9435 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9436 | ArraySize.get(), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 9437 | E->getDirectInitRange(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9438 | NewInit.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9439 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9440 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9441 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9442 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9443 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9444 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9445 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9446 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9447 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9448 | // Transform the delete operator, if known. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9449 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9450 | if (E->getOperatorDelete()) { |
| 9451 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9452 | getDerived().TransformDecl(E->getLocStart(), |
| 9453 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9454 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9455 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9456 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9457 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9458 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9459 | Operand.get() == E->getArgument() && |
| 9460 | OperatorDelete == E->getOperatorDelete()) { |
| 9461 | // Mark any declarations we need as referenced. |
| 9462 | // FIXME: instantiation-specific. |
| 9463 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9464 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9465 | |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 9466 | if (!E->getArgument()->isTypeDependent()) { |
| 9467 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 9468 | E->getDestroyedType()); |
| 9469 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 9470 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9471 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9472 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 9473 | } |
| 9474 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9475 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9476 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9477 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9478 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9479 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 9480 | E->isGlobalDelete(), |
| 9481 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9482 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9483 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9484 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9485 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9486 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9487 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9488 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9489 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9490 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9491 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9492 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9493 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9494 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9495 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9496 | E->getOperatorLoc(), |
| 9497 | E->isArrow()? tok::arrow : tok::period, |
| 9498 | ObjectTypePtr, |
| 9499 | MayBePseudoDestructor); |
| 9500 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9501 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9502 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9503 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9504 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 9505 | if (QualifierLoc) { |
| 9506 | QualifierLoc |
| 9507 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 9508 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9509 | return ExprError(); |
| 9510 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9511 | CXXScopeSpec SS; |
| 9512 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9513 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9514 | PseudoDestructorTypeStorage Destroyed; |
| 9515 | if (E->getDestroyedTypeInfo()) { |
| 9516 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9517 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9518 | ObjectType, nullptr, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9519 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9520 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9521 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 9522 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9523 | // We aren't likely to be able to resolve the identifier down to a type |
| 9524 | // now anyway, so just retain the identifier. |
| 9525 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 9526 | E->getDestroyedTypeLoc()); |
| 9527 | } else { |
| 9528 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9529 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9530 | *E->getDestroyedTypeIdentifier(), |
| 9531 | E->getDestroyedTypeLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9532 | /*Scope=*/nullptr, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9533 | SS, ObjectTypePtr, |
| 9534 | false); |
| 9535 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9536 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9537 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9538 | Destroyed |
| 9539 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 9540 | E->getDestroyedTypeLoc()); |
| 9541 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9542 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9543 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9544 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 9545 | CXXScopeSpec EmptySS; |
| 9546 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9547 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9548 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9549 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9550 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9551 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9552 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9553 | E->getOperatorLoc(), |
| 9554 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9555 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9556 | ScopeTypeInfo, |
| 9557 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9558 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9559 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9560 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9561 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9562 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9563 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9564 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9565 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9566 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 9567 | Sema::LookupOrdinaryName); |
| 9568 | |
| 9569 | // Transform all the decls. |
| 9570 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 9571 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9572 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 9573 | getDerived().TransformDecl(Old->getNameLoc(), |
| 9574 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9575 | if (!InstD) { |
| 9576 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 9577 | // This can happen because of dependent hiding. |
| 9578 | if (isa<UsingShadowDecl>(*I)) |
| 9579 | continue; |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9580 | else { |
| 9581 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9582 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9583 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9584 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9585 | |
| 9586 | // Expand using declarations. |
| 9587 | if (isa<UsingDecl>(InstD)) { |
| 9588 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 9589 | for (auto *I : UD->shadows()) |
| 9590 | R.addDecl(I); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9591 | continue; |
| 9592 | } |
| 9593 | |
| 9594 | R.addDecl(InstD); |
| 9595 | } |
| 9596 | |
| 9597 | // Resolve a kind, but don't do any further analysis. If it's |
| 9598 | // ambiguous, the callee needs to deal with it. |
| 9599 | R.resolveKind(); |
| 9600 | |
| 9601 | // Rebuild the nested-name qualifier, if present. |
| 9602 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9603 | if (Old->getQualifierLoc()) { |
| 9604 | NestedNameSpecifierLoc QualifierLoc |
| 9605 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 9606 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9607 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9608 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9609 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9610 | } |
| 9611 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9612 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9613 | CXXRecordDecl *NamingClass |
| 9614 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 9615 | Old->getNameLoc(), |
| 9616 | Old->getNamingClass())); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9617 | if (!NamingClass) { |
| 9618 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9619 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9620 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9621 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9622 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9623 | } |
| 9624 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9625 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 9626 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 9627 | // If we have neither explicit template arguments, nor the template keyword, |
Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 9628 | // it's a normal declaration name or member reference. |
| 9629 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { |
| 9630 | NamedDecl *D = R.getAsSingle<NamedDecl>(); |
| 9631 | // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an |
| 9632 | // instance member. In other contexts, BuildPossibleImplicitMemberExpr will |
| 9633 | // give a good diagnostic. |
| 9634 | if (D && D->isCXXInstanceMember()) { |
| 9635 | return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, |
| 9636 | /*TemplateArgs=*/nullptr, |
| 9637 | /*Scope=*/nullptr); |
| 9638 | } |
| 9639 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9640 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 9641 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9642 | |
| 9643 | // If we have template arguments, rebuild them, then rebuild the |
| 9644 | // templateid expression. |
| 9645 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 9646 | if (Old->hasExplicitTemplateArgs() && |
| 9647 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9648 | Old->getNumTemplateArgs(), |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9649 | TransArgs)) { |
| 9650 | R.clear(); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9651 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 9652 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9653 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9654 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 9655 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9658 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9659 | ExprResult |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9660 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 9661 | bool ArgChanged = false; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9662 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9663 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 9664 | TypeSourceInfo *From = E->getArg(I); |
| 9665 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 9666 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9667 | TypeLocBuilder TLB; |
| 9668 | TLB.reserve(FromTL.getFullDataSize()); |
| 9669 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 9670 | if (To.isNull()) |
| 9671 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9672 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9673 | if (To == From->getType()) |
| 9674 | Args.push_back(From); |
| 9675 | else { |
| 9676 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9677 | ArgChanged = true; |
| 9678 | } |
| 9679 | continue; |
| 9680 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9681 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9682 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9683 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9684 | // We have a pack expansion. Instantiate it. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 9685 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9686 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 9687 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 9688 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9689 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9690 | // Determine whether the set of unexpanded parameter packs can and should |
| 9691 | // be expanded. |
| 9692 | bool Expand = true; |
| 9693 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9694 | Optional<unsigned> OrigNumExpansions = |
| 9695 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 9696 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9697 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 9698 | PatternTL.getSourceRange(), |
| 9699 | Unexpanded, |
| 9700 | Expand, RetainExpansion, |
| 9701 | NumExpansions)) |
| 9702 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9703 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9704 | if (!Expand) { |
| 9705 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9706 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9707 | // expansion. |
| 9708 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9709 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9710 | TypeLocBuilder TLB; |
| 9711 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 9712 | |
| 9713 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9714 | if (To.isNull()) |
| 9715 | return ExprError(); |
| 9716 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9717 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9718 | PatternTL.getSourceRange(), |
| 9719 | ExpansionTL.getEllipsisLoc(), |
| 9720 | NumExpansions); |
| 9721 | if (To.isNull()) |
| 9722 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9723 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9724 | PackExpansionTypeLoc ToExpansionTL |
| 9725 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9726 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9727 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9728 | continue; |
| 9729 | } |
| 9730 | |
| 9731 | // Expand the pack expansion by substituting for each argument in the |
| 9732 | // pack(s). |
| 9733 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9734 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 9735 | TypeLocBuilder TLB; |
| 9736 | TLB.reserve(PatternTL.getFullDataSize()); |
| 9737 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9738 | if (To.isNull()) |
| 9739 | return ExprError(); |
| 9740 | |
Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 9741 | if (To->containsUnexpandedParameterPack()) { |
| 9742 | To = getDerived().RebuildPackExpansionType(To, |
| 9743 | PatternTL.getSourceRange(), |
| 9744 | ExpansionTL.getEllipsisLoc(), |
| 9745 | NumExpansions); |
| 9746 | if (To.isNull()) |
| 9747 | return ExprError(); |
| 9748 | |
| 9749 | PackExpansionTypeLoc ToExpansionTL |
| 9750 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9751 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9752 | } |
| 9753 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9754 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9755 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9756 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9757 | if (!RetainExpansion) |
| 9758 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9759 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9760 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 9761 | // forgetting the partially-substituted parameter pack. |
| 9762 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 9763 | |
| 9764 | TypeLocBuilder TLB; |
| 9765 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9766 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9767 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 9768 | if (To.isNull()) |
| 9769 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9770 | |
| 9771 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9772 | PatternTL.getSourceRange(), |
| 9773 | ExpansionTL.getEllipsisLoc(), |
| 9774 | NumExpansions); |
| 9775 | if (To.isNull()) |
| 9776 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9777 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9778 | PackExpansionTypeLoc ToExpansionTL |
| 9779 | = TLB.push<PackExpansionTypeLoc>(To); |
| 9780 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 9781 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 9782 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9783 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9784 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9785 | return E; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 9786 | |
| 9787 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 9788 | E->getLocStart(), |
| 9789 | Args, |
| 9790 | E->getLocEnd()); |
| 9791 | } |
| 9792 | |
| 9793 | template<typename Derived> |
| 9794 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9795 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 9796 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 9797 | if (!T) |
| 9798 | return ExprError(); |
| 9799 | |
| 9800 | if (!getDerived().AlwaysRebuild() && |
| 9801 | T == E->getQueriedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9802 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9803 | |
| 9804 | ExprResult SubExpr; |
| 9805 | { |
| 9806 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 9807 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 9808 | if (SubExpr.isInvalid()) |
| 9809 | return ExprError(); |
| 9810 | |
| 9811 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9812 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 9813 | } |
| 9814 | |
| 9815 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 9816 | E->getLocStart(), |
| 9817 | T, |
| 9818 | SubExpr.get(), |
| 9819 | E->getLocEnd()); |
| 9820 | } |
| 9821 | |
| 9822 | template<typename Derived> |
| 9823 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 9824 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 9825 | ExprResult SubExpr; |
| 9826 | { |
| 9827 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 9828 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 9829 | if (SubExpr.isInvalid()) |
| 9830 | return ExprError(); |
| 9831 | |
| 9832 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9833 | return E; |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 9834 | } |
| 9835 | |
| 9836 | return getDerived().RebuildExpressionTrait( |
| 9837 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 9838 | } |
| 9839 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9840 | template <typename Derived> |
| 9841 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 9842 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 9843 | TypeSourceInfo **RecoveryTSI) { |
| 9844 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 9845 | DRE, AddrTaken, RecoveryTSI); |
| 9846 | |
| 9847 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 9848 | if (!NewDRE.isUsable()) |
| 9849 | return NewDRE; |
| 9850 | |
| 9851 | // We got an expr, wrap it up in parens. |
| 9852 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 9853 | return PE; |
| 9854 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 9855 | PE->getRParen()); |
| 9856 | } |
| 9857 | |
| 9858 | template <typename Derived> |
| 9859 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 9860 | DependentScopeDeclRefExpr *E) { |
| 9861 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 9862 | nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9863 | } |
| 9864 | |
| 9865 | template<typename Derived> |
| 9866 | ExprResult |
| 9867 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 9868 | DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9869 | bool IsAddressOfOperand, |
| 9870 | TypeSourceInfo **RecoveryTSI) { |
Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 9871 | assert(E->getQualifierLoc()); |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 9872 | NestedNameSpecifierLoc QualifierLoc |
| 9873 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 9874 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9875 | return ExprError(); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9876 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9877 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9878 | // TODO: If this is a conversion-function-id, verify that the |
| 9879 | // destination type name (if present) resolves the same way after |
| 9880 | // instantiation as it did in the local scope. |
| 9881 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9882 | DeclarationNameInfo NameInfo |
| 9883 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 9884 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9885 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9886 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 9887 | if (!E->hasExplicitTemplateArgs()) { |
| 9888 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 9889 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9890 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 9891 | // if name has not changed, DNLoc has not changed either. |
| 9892 | NameInfo.getName() == E->getDeclName()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9893 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9894 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9895 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 9896 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 9897 | IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 9898 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9899 | |
| 9900 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9901 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9902 | E->getNumTemplateArgs(), |
| 9903 | TransArgs)) |
| 9904 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9905 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9906 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 9907 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 9908 | RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9909 | } |
| 9910 | |
| 9911 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9912 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9913 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9914 | // CXXConstructExprs other than for list-initialization and |
| 9915 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 9916 | // a 1-argument construction we just transform that argument. |
Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 9917 | if ((E->getNumArgs() == 1 || |
| 9918 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9919 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 9920 | !E->isListInitialization()) |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 9921 | return getDerived().TransformExpr(E->getArg(0)); |
| 9922 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9923 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 9924 | |
| 9925 | QualType T = getDerived().TransformType(E->getType()); |
| 9926 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9927 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9928 | |
| 9929 | CXXConstructorDecl *Constructor |
| 9930 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9931 | getDerived().TransformDecl(E->getLocStart(), |
| 9932 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9933 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9934 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9935 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9936 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9937 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9938 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9939 | &ArgumentChanged)) |
| 9940 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9941 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9942 | if (!getDerived().AlwaysRebuild() && |
| 9943 | T == E->getType() && |
| 9944 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 9945 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 9946 | // Mark the constructor as referenced. |
| 9947 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9948 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9949 | return E; |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 9950 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9951 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 9952 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 9953 | Constructor, |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 9954 | E->isElidable(), Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 9955 | E->hadMultipleCandidates(), |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 9956 | E->isListInitialization(), |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 9957 | E->isStdInitListInitialization(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 9958 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 9959 | E->getConstructionKind(), |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 9960 | E->getParenOrBraceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9962 | |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 9963 | template<typename Derived> |
| 9964 | ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr( |
| 9965 | CXXInheritedCtorInitExpr *E) { |
| 9966 | QualType T = getDerived().TransformType(E->getType()); |
| 9967 | if (T.isNull()) |
| 9968 | return ExprError(); |
| 9969 | |
| 9970 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 9971 | getDerived().TransformDecl(E->getLocStart(), E->getConstructor())); |
| 9972 | if (!Constructor) |
| 9973 | return ExprError(); |
| 9974 | |
| 9975 | if (!getDerived().AlwaysRebuild() && |
| 9976 | T == E->getType() && |
| 9977 | Constructor == E->getConstructor()) { |
| 9978 | // Mark the constructor as referenced. |
| 9979 | // FIXME: Instantiation-specific |
| 9980 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
| 9981 | return E; |
| 9982 | } |
| 9983 | |
| 9984 | return getDerived().RebuildCXXInheritedCtorInitExpr( |
| 9985 | T, E->getLocation(), Constructor, |
| 9986 | E->constructsVBase(), E->inheritedFromVBase()); |
| 9987 | } |
| 9988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9989 | /// \brief Transform a C++ temporary-binding expression. |
| 9990 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9991 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 9992 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9993 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9994 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9995 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 9996 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9998 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 9999 | /// \brief Transform a C++ expression that contains cleanups that should |
| 10000 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10001 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 10002 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 10003 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10004 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10005 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 10006 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 10007 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10009 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10010 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10011 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10012 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10013 | CXXTemporaryObjectExpr *E) { |
| 10014 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 10015 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10016 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10018 | CXXConstructorDecl *Constructor |
| 10019 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10020 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 10021 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10022 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10023 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10024 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10025 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10026 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10027 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10028 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10029 | &ArgumentChanged)) |
| 10030 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10031 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10032 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10033 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10034 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 10035 | !ArgumentChanged) { |
| 10036 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 10037 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 10038 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 10039 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10040 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 10041 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10042 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 10043 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10044 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10045 | E->getLocEnd()); |
| 10046 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10047 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10048 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10049 | ExprResult |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 10050 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10051 | // Transform any init-capture expressions before entering the scope of the |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10052 | // lambda body, because they are not semantically within that scope. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10053 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10054 | SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes; |
| 10055 | InitCaptureExprsAndTypes.resize(E->explicit_capture_end() - |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10056 | E->explicit_capture_begin()); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10057 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10058 | CEnd = E->capture_end(); |
| 10059 | C != CEnd; ++C) { |
James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 10060 | if (!E->isInitCapture(C)) |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10061 | continue; |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10062 | EnterExpressionEvaluationContext EEEC(getSema(), |
| 10063 | Sema::PotentiallyEvaluated); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10064 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 10065 | C->getCapturedVar()->getInit(), |
| 10066 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10067 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10068 | if (NewExprInitResult.isInvalid()) |
| 10069 | return ExprError(); |
| 10070 | Expr *NewExprInit = NewExprInitResult.get(); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10071 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10072 | VarDecl *OldVD = C->getCapturedVar(); |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10073 | QualType NewInitCaptureType = |
Richard Smith | 42b1057 | 2015-11-11 01:36:17 +0000 | [diff] [blame] | 10074 | getSema().buildLambdaInitCaptureInitialization( |
| 10075 | C->getLocation(), OldVD->getType()->isReferenceType(), |
| 10076 | OldVD->getIdentifier(), |
| 10077 | C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10078 | NewExprInitResult = NewExprInit; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10079 | InitCaptureExprsAndTypes[C - E->capture_begin()] = |
| 10080 | std::make_pair(NewExprInitResult, NewInitCaptureType); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10081 | } |
| 10082 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10083 | // Transform the template parameters, and add them to the current |
| 10084 | // instantiation scope. The null case is handled correctly. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10085 | auto TPL = getDerived().TransformTemplateParameterList( |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10086 | E->getTemplateParameterList()); |
| 10087 | |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10088 | // Transform the type of the original lambda's call operator. |
| 10089 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 10090 | // it introduces a mapping of the original to the newly created |
| 10091 | // transformed parameters. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10092 | TypeSourceInfo *NewCallOpTSI = nullptr; |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10093 | { |
| 10094 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 10095 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 10096 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10097 | |
| 10098 | TypeLocBuilder NewCallOpTLBuilder; |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 10099 | SmallVector<QualType, 4> ExceptionStorage; |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 10100 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 10101 | QualType NewCallOpType = TransformFunctionProtoType( |
| 10102 | NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0, |
Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 10103 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 10104 | return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, |
| 10105 | ExceptionStorage, Changed); |
Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 10106 | }); |
Reid Kleckner | aac43c6 | 2014-12-15 21:07:16 +0000 | [diff] [blame] | 10107 | if (NewCallOpType.isNull()) |
| 10108 | return ExprError(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10109 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 10110 | NewCallOpType); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 10111 | } |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10112 | |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10113 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
| 10114 | Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); |
| 10115 | LSI->GLTemplateParameterList = TPL; |
| 10116 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 10117 | // Create the local class that will describe the lambda. |
| 10118 | CXXRecordDecl *Class |
| 10119 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10120 | NewCallOpTSI, |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 10121 | /*KnownDependent=*/false, |
| 10122 | E->getCaptureDefault()); |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 10123 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 10124 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10125 | // Build the call operator. |
Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10126 | CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition( |
| 10127 | Class, E->getIntroducerRange(), NewCallOpTSI, |
| 10128 | E->getCallOperator()->getLocEnd(), |
Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 10129 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(), |
| 10130 | E->getCallOperator()->isConstexpr()); |
| 10131 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10132 | LSI->CallOperator = NewCallOperator; |
Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 10133 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10134 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10135 | getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 10136 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 10137 | // Introduce the context of the call operator. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10138 | Sema::ContextRAII SavedContext(getSema(), NewCallOperator, |
Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 10139 | /*NewThisContext*/false); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 10140 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10141 | // Enter the scope of the lambda. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10142 | getSema().buildLambdaScope(LSI, NewCallOperator, |
| 10143 | E->getIntroducerRange(), |
| 10144 | E->getCaptureDefault(), |
| 10145 | E->getCaptureDefaultLoc(), |
| 10146 | E->hasExplicitParameters(), |
| 10147 | E->hasExplicitResultType(), |
| 10148 | E->isMutable()); |
| 10149 | |
| 10150 | bool Invalid = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10151 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10152 | // Transform captures. |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10153 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10154 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10155 | CEnd = E->capture_end(); |
| 10156 | C != CEnd; ++C) { |
| 10157 | // When we hit the first implicit capture, tell Sema that we've finished |
| 10158 | // the list of explicit captures. |
| 10159 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 10160 | getSema().finishLambdaExplicitCaptures(LSI); |
| 10161 | FinishedExplicitCaptures = true; |
| 10162 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10163 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10164 | // Capturing 'this' is trivial. |
| 10165 | if (C->capturesThis()) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 10166 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 10167 | /*BuildAndDiagnose*/ true, nullptr, |
| 10168 | C->getCaptureKind() == LCK_StarThis); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10169 | continue; |
| 10170 | } |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 10171 | // Captured expression will be recaptured during captured variables |
| 10172 | // rebuilding. |
| 10173 | if (C->capturesVLAType()) |
| 10174 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10175 | |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 10176 | // Rebuild init-captures, including the implied field declaration. |
James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 10177 | if (E->isInitCapture(C)) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10178 | InitCaptureInfoTy InitExprTypePair = |
| 10179 | InitCaptureExprsAndTypes[C - E->capture_begin()]; |
| 10180 | ExprResult Init = InitExprTypePair.first; |
| 10181 | QualType InitQualType = InitExprTypePair.second; |
| 10182 | if (Init.isInvalid() || InitQualType.isNull()) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 10183 | Invalid = true; |
| 10184 | continue; |
| 10185 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 10186 | VarDecl *OldVD = C->getCapturedVar(); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10187 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
Richard Smith | 42b1057 | 2015-11-11 01:36:17 +0000 | [diff] [blame] | 10188 | OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(), |
| 10189 | OldVD->getInitStyle(), Init.get()); |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 10190 | if (!NewVD) |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 10191 | Invalid = true; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10192 | else { |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 10193 | getDerived().transformedLocalDecl(OldVD, NewVD); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10194 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 10195 | getSema().buildInitCaptureField(LSI, NewVD); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 10196 | continue; |
| 10197 | } |
| 10198 | |
| 10199 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 10200 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 10201 | // Determine the capture kind for Sema. |
| 10202 | Sema::TryCaptureKind Kind |
| 10203 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 10204 | : C->getCaptureKind() == LCK_ByCopy |
| 10205 | ? Sema::TryCapture_ExplicitByVal |
| 10206 | : Sema::TryCapture_ExplicitByRef; |
| 10207 | SourceLocation EllipsisLoc; |
| 10208 | if (C->isPackExpansion()) { |
| 10209 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 10210 | bool ShouldExpand = false; |
| 10211 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 10212 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10213 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 10214 | C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 10215 | Unexpanded, |
| 10216 | ShouldExpand, RetainExpansion, |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 10217 | NumExpansions)) { |
| 10218 | Invalid = true; |
| 10219 | continue; |
| 10220 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10221 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 10222 | if (ShouldExpand) { |
| 10223 | // The transform has determined that we should perform an expansion; |
| 10224 | // transform and capture each of the arguments. |
| 10225 | // expansion of the pattern. Do so. |
| 10226 | VarDecl *Pack = C->getCapturedVar(); |
| 10227 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10228 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 10229 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10230 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 10231 | Pack)); |
| 10232 | if (!CapturedVar) { |
| 10233 | Invalid = true; |
| 10234 | continue; |
| 10235 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10236 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 10237 | // Capture the transformed variable. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10238 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 10239 | } |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 10240 | |
| 10241 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 10242 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 10243 | continue; |
| 10244 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10245 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 10246 | EllipsisLoc = C->getEllipsisLoc(); |
| 10247 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10248 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10249 | // Transform the captured variable. |
| 10250 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10251 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10252 | C->getCapturedVar())); |
Richard Trieu | b292604 | 2014-09-02 19:32:44 +0000 | [diff] [blame] | 10253 | if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10254 | Invalid = true; |
| 10255 | continue; |
| 10256 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10257 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10258 | // Capture the transformed variable. |
Meador Inge | 4f9dee7 | 2015-06-26 00:09:55 +0000 | [diff] [blame] | 10259 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, |
| 10260 | EllipsisLoc); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10261 | } |
| 10262 | if (!FinishedExplicitCaptures) |
| 10263 | getSema().finishLambdaExplicitCaptures(LSI); |
| 10264 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10265 | // Enter a new evaluation context to insulate the lambda from any |
| 10266 | // cleanups from the enclosing full-expression. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10267 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10268 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10269 | // Instantiate the body of the lambda expression. |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10270 | StmtResult Body = |
| 10271 | Invalid ? StmtError() : getDerived().TransformStmt(E->getBody()); |
| 10272 | |
| 10273 | // ActOnLambda* will pop the function scope for us. |
| 10274 | FuncScopeCleanup.disable(); |
| 10275 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 10276 | if (Body.isInvalid()) { |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10277 | SavedContext.pop(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10278 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 10279 | /*IsInstantiation=*/true); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10280 | return ExprError(); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 10281 | } |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 10282 | |
Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10283 | // Copy the LSI before ActOnFinishFunctionBody removes it. |
| 10284 | // FIXME: This is dumb. Store the lambda information somewhere that outlives |
| 10285 | // the call operator. |
| 10286 | auto LSICopy = *LSI; |
| 10287 | getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), |
| 10288 | /*IsInstantiation*/ true); |
| 10289 | SavedContext.pop(); |
| 10290 | |
| 10291 | return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(), |
| 10292 | &LSICopy); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 10293 | } |
| 10294 | |
| 10295 | template<typename Derived> |
| 10296 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10297 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10298 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10299 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 10300 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10301 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10302 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10303 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10304 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10305 | Args.reserve(E->arg_size()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10306 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10307 | &ArgumentChanged)) |
| 10308 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10309 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10310 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10311 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10312 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10313 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10314 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10315 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10316 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10317 | E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10318 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10319 | E->getRParenLoc()); |
| 10320 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10321 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10322 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10323 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 10324 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10325 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10326 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10327 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10328 | Expr *OldBase; |
| 10329 | QualType BaseType; |
| 10330 | QualType ObjectType; |
| 10331 | if (!E->isImplicitAccess()) { |
| 10332 | OldBase = E->getBase(); |
| 10333 | Base = getDerived().TransformExpr(OldBase); |
| 10334 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10335 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10336 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10337 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10338 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 10339 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10340 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10341 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 10342 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 10343 | ObjectTy, |
| 10344 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10345 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10346 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10347 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10348 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10349 | BaseType = ((Expr*) Base.get())->getType(); |
| 10350 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10351 | OldBase = nullptr; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10352 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 10353 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 10354 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10355 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 10356 | // Transform the first part of the nested-name-specifier that qualifies |
| 10357 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 10358 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 10359 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 10360 | E->getFirstQualifierFoundInScope(), |
| 10361 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10362 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 10363 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 10364 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 10365 | QualifierLoc |
| 10366 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 10367 | ObjectType, |
| 10368 | FirstQualifierInScope); |
| 10369 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10370 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 10371 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10372 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10373 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 10374 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10375 | // TODO: If this is a conversion-function-id, verify that the |
| 10376 | // destination type name (if present) resolves the same way after |
| 10377 | // instantiation as it did in the local scope. |
| 10378 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10379 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10380 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10381 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10382 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10383 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10384 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 10385 | // This is a reference to a member without an explicitly-specified |
| 10386 | // template argument list. Optimize for this common case. |
| 10387 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10388 | Base.get() == OldBase && |
| 10389 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 10390 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10391 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 10392 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10393 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10394 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10395 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10396 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 10397 | E->isArrow(), |
| 10398 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 10399 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10400 | TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10401 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10402 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10403 | /*TemplateArgs*/nullptr); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 10404 | } |
| 10405 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 10406 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10407 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 10408 | E->getNumTemplateArgs(), |
| 10409 | TransArgs)) |
| 10410 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10411 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10412 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10413 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10414 | E->isArrow(), |
| 10415 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 10416 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10417 | TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 10418 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10419 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10420 | &TransArgs); |
| 10421 | } |
| 10422 | |
| 10423 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10424 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10425 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10426 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10427 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10428 | QualType BaseType; |
| 10429 | if (!Old->isImplicitAccess()) { |
| 10430 | Base = getDerived().TransformExpr(Old->getBase()); |
| 10431 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10432 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 10433 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 10434 | Old->isArrow()); |
| 10435 | if (Base.isInvalid()) |
| 10436 | return ExprError(); |
| 10437 | BaseType = Base.get()->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10438 | } else { |
| 10439 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 10440 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10441 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 10442 | NestedNameSpecifierLoc QualifierLoc; |
| 10443 | if (Old->getQualifierLoc()) { |
| 10444 | QualifierLoc |
| 10445 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 10446 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10447 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10448 | } |
| 10449 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10450 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 10451 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10452 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10453 | Sema::LookupOrdinaryName); |
| 10454 | |
| 10455 | // Transform all the decls. |
| 10456 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 10457 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 10458 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 10459 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 10460 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 10461 | if (!InstD) { |
| 10462 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 10463 | // This can happen because of dependent hiding. |
| 10464 | if (isa<UsingShadowDecl>(*I)) |
| 10465 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 10466 | else { |
| 10467 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10468 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 10469 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 10470 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10471 | |
| 10472 | // Expand using declarations. |
| 10473 | if (isa<UsingDecl>(InstD)) { |
| 10474 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 10475 | for (auto *I : UD->shadows()) |
| 10476 | R.addDecl(I); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10477 | continue; |
| 10478 | } |
| 10479 | |
| 10480 | R.addDecl(InstD); |
| 10481 | } |
| 10482 | |
| 10483 | R.resolveKind(); |
| 10484 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 10485 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 10486 | if (Old->getNamingClass()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10487 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 10488 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 10489 | Old->getMemberLoc(), |
| 10490 | Old->getNamingClass())); |
| 10491 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10492 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10493 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 10494 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 10495 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10496 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10497 | TemplateArgumentListInfo TransArgs; |
| 10498 | if (Old->hasExplicitTemplateArgs()) { |
| 10499 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 10500 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10501 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 10502 | Old->getNumTemplateArgs(), |
| 10503 | TransArgs)) |
| 10504 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10505 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 10506 | |
| 10507 | // FIXME: to do this check properly, we will need to preserve the |
| 10508 | // first-qualifier-in-scope here, just in case we had a dependent |
| 10509 | // base (and therefore couldn't do the check) and a |
| 10510 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10511 | NamedDecl *FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10512 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10513 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 10514 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10515 | Old->getOperatorLoc(), |
| 10516 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 10517 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10518 | TemplateKWLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 10519 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 10520 | R, |
| 10521 | (Old->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10522 | ? &TransArgs : nullptr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10523 | } |
| 10524 | |
| 10525 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10526 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 10527 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Alexis Hunt | 414e3e3 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 10528 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 10529 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 10530 | if (SubExpr.isInvalid()) |
| 10531 | return ExprError(); |
| 10532 | |
| 10533 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10534 | return E; |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 10535 | |
| 10536 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 10537 | } |
| 10538 | |
| 10539 | template<typename Derived> |
| 10540 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 10541 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 10542 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 10543 | if (Pattern.isInvalid()) |
| 10544 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10545 | |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 10546 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10547 | return E; |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 10548 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 10549 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 10550 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 10551 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 10552 | |
| 10553 | template<typename Derived> |
| 10554 | ExprResult |
| 10555 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 10556 | // If E is not value-dependent, then nothing will change when we transform it. |
| 10557 | // Note: This is an instantiation-centric view. |
| 10558 | if (!E->isValueDependent()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10559 | return E; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 10560 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10561 | EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10562 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10563 | ArrayRef<TemplateArgument> PackArgs; |
| 10564 | TemplateArgument ArgStorage; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10565 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10566 | // Find the argument list to transform. |
| 10567 | if (E->isPartiallySubstituted()) { |
| 10568 | PackArgs = E->getPartialArguments(); |
| 10569 | } else if (E->isValueDependent()) { |
| 10570 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 10571 | bool ShouldExpand = false; |
| 10572 | bool RetainExpansion = false; |
| 10573 | Optional<unsigned> NumExpansions; |
| 10574 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 10575 | Unexpanded, |
| 10576 | ShouldExpand, RetainExpansion, |
| 10577 | NumExpansions)) |
| 10578 | return ExprError(); |
| 10579 | |
| 10580 | // If we need to expand the pack, build a template argument from it and |
| 10581 | // expand that. |
| 10582 | if (ShouldExpand) { |
| 10583 | auto *Pack = E->getPack(); |
| 10584 | if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { |
| 10585 | ArgStorage = getSema().Context.getPackExpansionType( |
| 10586 | getSema().Context.getTypeDeclType(TTPD), None); |
| 10587 | } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { |
| 10588 | ArgStorage = TemplateArgument(TemplateName(TTPD), None); |
| 10589 | } else { |
| 10590 | auto *VD = cast<ValueDecl>(Pack); |
| 10591 | ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(), |
| 10592 | VK_RValue, E->getPackLoc()); |
| 10593 | if (DRE.isInvalid()) |
| 10594 | return ExprError(); |
| 10595 | ArgStorage = new (getSema().Context) PackExpansionExpr( |
| 10596 | getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None); |
| 10597 | } |
| 10598 | PackArgs = ArgStorage; |
| 10599 | } |
| 10600 | } |
| 10601 | |
| 10602 | // If we're not expanding the pack, just transform the decl. |
| 10603 | if (!PackArgs.size()) { |
| 10604 | auto *Pack = cast_or_null<NamedDecl>( |
| 10605 | getDerived().TransformDecl(E->getPackLoc(), E->getPack())); |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 10606 | if (!Pack) |
| 10607 | return ExprError(); |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10608 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 10609 | E->getPackLoc(), |
| 10610 | E->getRParenLoc(), None, None); |
| 10611 | } |
| 10612 | |
| 10613 | TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), |
| 10614 | E->getPackLoc()); |
| 10615 | { |
| 10616 | TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); |
| 10617 | typedef TemplateArgumentLocInventIterator< |
| 10618 | Derived, const TemplateArgument*> PackLocIterator; |
| 10619 | if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), |
| 10620 | PackLocIterator(*this, PackArgs.end()), |
| 10621 | TransformedPackArgs, /*Uneval*/true)) |
| 10622 | return ExprError(); |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 10623 | } |
| 10624 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10625 | SmallVector<TemplateArgument, 8> Args; |
| 10626 | bool PartialSubstitution = false; |
| 10627 | for (auto &Loc : TransformedPackArgs.arguments()) { |
| 10628 | Args.push_back(Loc.getArgument()); |
| 10629 | if (Loc.getArgument().isPackExpansion()) |
| 10630 | PartialSubstitution = true; |
| 10631 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10632 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10633 | if (PartialSubstitution) |
| 10634 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 10635 | E->getPackLoc(), |
| 10636 | E->getRParenLoc(), None, Args); |
| 10637 | |
| 10638 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10639 | E->getPackLoc(), E->getRParenLoc(), |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 10640 | Args.size(), None); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 10641 | } |
| 10642 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 10643 | template<typename Derived> |
| 10644 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 10645 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 10646 | SubstNonTypeTemplateParmPackExpr *E) { |
| 10647 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10648 | return E; |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 10649 | } |
| 10650 | |
| 10651 | template<typename Derived> |
| 10652 | ExprResult |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 10653 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 10654 | SubstNonTypeTemplateParmExpr *E) { |
| 10655 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10656 | return E; |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 10657 | } |
| 10658 | |
| 10659 | template<typename Derived> |
| 10660 | ExprResult |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 10661 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 10662 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10663 | return E; |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 10664 | } |
| 10665 | |
| 10666 | template<typename Derived> |
| 10667 | ExprResult |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 10668 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 10669 | MaterializeTemporaryExpr *E) { |
| 10670 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 10671 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10672 | |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 10673 | template<typename Derived> |
| 10674 | ExprResult |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 10675 | TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { |
| 10676 | Expr *Pattern = E->getPattern(); |
| 10677 | |
| 10678 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10679 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 10680 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 10681 | |
| 10682 | // Determine whether the set of unexpanded parameter packs can and should |
| 10683 | // be expanded. |
| 10684 | bool Expand = true; |
| 10685 | bool RetainExpansion = false; |
| 10686 | Optional<unsigned> NumExpansions; |
| 10687 | if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), |
| 10688 | Pattern->getSourceRange(), |
| 10689 | Unexpanded, |
| 10690 | Expand, RetainExpansion, |
| 10691 | NumExpansions)) |
| 10692 | return true; |
| 10693 | |
| 10694 | if (!Expand) { |
| 10695 | // Do not expand any packs here, just transform and rebuild a fold |
| 10696 | // expression. |
| 10697 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 10698 | |
| 10699 | ExprResult LHS = |
| 10700 | E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); |
| 10701 | if (LHS.isInvalid()) |
| 10702 | return true; |
| 10703 | |
| 10704 | ExprResult RHS = |
| 10705 | E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); |
| 10706 | if (RHS.isInvalid()) |
| 10707 | return true; |
| 10708 | |
| 10709 | if (!getDerived().AlwaysRebuild() && |
| 10710 | LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) |
| 10711 | return E; |
| 10712 | |
| 10713 | return getDerived().RebuildCXXFoldExpr( |
| 10714 | E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(), |
| 10715 | RHS.get(), E->getLocEnd()); |
| 10716 | } |
| 10717 | |
| 10718 | // The transform has determined that we should perform an elementwise |
| 10719 | // expansion of the pattern. Do so. |
| 10720 | ExprResult Result = getDerived().TransformExpr(E->getInit()); |
| 10721 | if (Result.isInvalid()) |
| 10722 | return true; |
| 10723 | bool LeftFold = E->isLeftFold(); |
| 10724 | |
| 10725 | // If we're retaining an expansion for a right fold, it is the innermost |
| 10726 | // component and takes the init (if any). |
| 10727 | if (!LeftFold && RetainExpansion) { |
| 10728 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10729 | |
| 10730 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10731 | if (Out.isInvalid()) |
| 10732 | return true; |
| 10733 | |
| 10734 | Result = getDerived().RebuildCXXFoldExpr( |
| 10735 | E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(), |
| 10736 | Result.get(), E->getLocEnd()); |
| 10737 | if (Result.isInvalid()) |
| 10738 | return true; |
| 10739 | } |
| 10740 | |
| 10741 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10742 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( |
| 10743 | getSema(), LeftFold ? I : *NumExpansions - I - 1); |
| 10744 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10745 | if (Out.isInvalid()) |
| 10746 | return true; |
| 10747 | |
| 10748 | if (Out.get()->containsUnexpandedParameterPack()) { |
| 10749 | // We still have a pack; retain a pack expansion for this slice. |
| 10750 | Result = getDerived().RebuildCXXFoldExpr( |
| 10751 | E->getLocStart(), |
| 10752 | LeftFold ? Result.get() : Out.get(), |
| 10753 | E->getOperator(), E->getEllipsisLoc(), |
| 10754 | LeftFold ? Out.get() : Result.get(), |
| 10755 | E->getLocEnd()); |
| 10756 | } else if (Result.isUsable()) { |
| 10757 | // We've got down to a single element; build a binary operator. |
| 10758 | Result = getDerived().RebuildBinaryOperator( |
| 10759 | E->getEllipsisLoc(), E->getOperator(), |
| 10760 | LeftFold ? Result.get() : Out.get(), |
| 10761 | LeftFold ? Out.get() : Result.get()); |
| 10762 | } else |
| 10763 | Result = Out; |
| 10764 | |
| 10765 | if (Result.isInvalid()) |
| 10766 | return true; |
| 10767 | } |
| 10768 | |
| 10769 | // If we're retaining an expansion for a left fold, it is the outermost |
| 10770 | // component and takes the complete expansion so far as its init (if any). |
| 10771 | if (LeftFold && RetainExpansion) { |
| 10772 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10773 | |
| 10774 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 10775 | if (Out.isInvalid()) |
| 10776 | return true; |
| 10777 | |
| 10778 | Result = getDerived().RebuildCXXFoldExpr( |
| 10779 | E->getLocStart(), Result.get(), |
| 10780 | E->getOperator(), E->getEllipsisLoc(), |
| 10781 | Out.get(), E->getLocEnd()); |
| 10782 | if (Result.isInvalid()) |
| 10783 | return true; |
| 10784 | } |
| 10785 | |
| 10786 | // If we had no init and an empty pack, and we're not retaining an expansion, |
| 10787 | // then produce a fallback value or error. |
| 10788 | if (Result.isUnset()) |
| 10789 | return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), |
| 10790 | E->getOperator()); |
| 10791 | |
| 10792 | return Result; |
| 10793 | } |
| 10794 | |
| 10795 | template<typename Derived> |
| 10796 | ExprResult |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 10797 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 10798 | CXXStdInitializerListExpr *E) { |
| 10799 | return getDerived().TransformExpr(E->getSubExpr()); |
| 10800 | } |
| 10801 | |
| 10802 | template<typename Derived> |
| 10803 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10804 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10805 | return SemaRef.MaybeBindToTemporary(E); |
| 10806 | } |
| 10807 | |
| 10808 | template<typename Derived> |
| 10809 | ExprResult |
| 10810 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10811 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10812 | } |
| 10813 | |
| 10814 | template<typename Derived> |
| 10815 | ExprResult |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 10816 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 10817 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 10818 | if (SubExpr.isInvalid()) |
| 10819 | return ExprError(); |
| 10820 | |
| 10821 | if (!getDerived().AlwaysRebuild() && |
| 10822 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10823 | return E; |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 10824 | |
| 10825 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10826 | } |
| 10827 | |
| 10828 | template<typename Derived> |
| 10829 | ExprResult |
| 10830 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 10831 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10832 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10833 | bool ArgChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10834 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10835 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 10836 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10837 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10838 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 10839 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10840 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10841 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 10842 | Elements.data(), |
| 10843 | Elements.size()); |
| 10844 | } |
| 10845 | |
| 10846 | template<typename Derived> |
| 10847 | ExprResult |
| 10848 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10849 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10850 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10851 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10852 | bool ArgChanged = false; |
| 10853 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 10854 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10855 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10856 | if (OrigElement.isPackExpansion()) { |
| 10857 | // This key/value element is a pack expansion. |
| 10858 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10859 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 10860 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 10861 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 10862 | |
| 10863 | // Determine whether the set of unexpanded parameter packs can |
| 10864 | // and should be expanded. |
| 10865 | bool Expand = true; |
| 10866 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 10867 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 10868 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10869 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 10870 | OrigElement.Value->getLocEnd()); |
| 10871 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 10872 | PatternRange, |
| 10873 | Unexpanded, |
| 10874 | Expand, RetainExpansion, |
| 10875 | NumExpansions)) |
| 10876 | return ExprError(); |
| 10877 | |
| 10878 | if (!Expand) { |
| 10879 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10880 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10881 | // expansion. |
| 10882 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 10883 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10884 | if (Key.isInvalid()) |
| 10885 | return ExprError(); |
| 10886 | |
| 10887 | if (Key.get() != OrigElement.Key) |
| 10888 | ArgChanged = true; |
| 10889 | |
| 10890 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 10891 | if (Value.isInvalid()) |
| 10892 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10893 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10894 | if (Value.get() != OrigElement.Value) |
| 10895 | ArgChanged = true; |
| 10896 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10897 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10898 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 10899 | }; |
| 10900 | Elements.push_back(Expansion); |
| 10901 | continue; |
| 10902 | } |
| 10903 | |
| 10904 | // Record right away that the argument was changed. This needs |
| 10905 | // to happen even if the array expands to nothing. |
| 10906 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10907 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10908 | // The transform has determined that we should perform an elementwise |
| 10909 | // expansion of the pattern. Do so. |
| 10910 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10911 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 10912 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10913 | if (Key.isInvalid()) |
| 10914 | return ExprError(); |
| 10915 | |
| 10916 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 10917 | if (Value.isInvalid()) |
| 10918 | return ExprError(); |
| 10919 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10920 | ObjCDictionaryElement Element = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10921 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 10922 | }; |
| 10923 | |
| 10924 | // If any unexpanded parameter packs remain, we still have a |
| 10925 | // pack expansion. |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 10926 | // FIXME: Can this really happen? |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10927 | if (Key.get()->containsUnexpandedParameterPack() || |
| 10928 | Value.get()->containsUnexpandedParameterPack()) |
| 10929 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10930 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10931 | Elements.push_back(Element); |
| 10932 | } |
| 10933 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 10934 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 10935 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10936 | // We've finished with this pack expansion. |
| 10937 | continue; |
| 10938 | } |
| 10939 | |
| 10940 | // Transform and check key. |
| 10941 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 10942 | if (Key.isInvalid()) |
| 10943 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10944 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10945 | if (Key.get() != OrigElement.Key) |
| 10946 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10947 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10948 | // Transform and check value. |
| 10949 | ExprResult Value |
| 10950 | = getDerived().TransformExpr(OrigElement.Value); |
| 10951 | if (Value.isInvalid()) |
| 10952 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10953 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10954 | if (Value.get() != OrigElement.Value) |
| 10955 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10956 | |
| 10957 | ObjCDictionaryElement Element = { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 10958 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10959 | }; |
| 10960 | Elements.push_back(Element); |
| 10961 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10962 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 10963 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 10964 | return SemaRef.MaybeBindToTemporary(E); |
| 10965 | |
| 10966 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
Craig Topper | d4336e0 | 2015-12-24 23:58:15 +0000 | [diff] [blame] | 10967 | Elements); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10968 | } |
| 10969 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10970 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10971 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10972 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10973 | TypeSourceInfo *EncodedTypeInfo |
| 10974 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 10975 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10976 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10977 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10978 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10979 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10980 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10981 | |
| 10982 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 10983 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10984 | E->getRParenLoc()); |
| 10985 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10986 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10987 | template<typename Derived> |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10988 | ExprResult TreeTransform<Derived>:: |
| 10989 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 10990 | // This is a kind of implicit conversion, and it needs to get dropped |
| 10991 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 10992 | // do, as well a more specific one: this expression is only valid when |
| 10993 | // it appears *immediately* as an argument expression. |
| 10994 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 10995 | } |
| 10996 | |
| 10997 | template<typename Derived> |
| 10998 | ExprResult TreeTransform<Derived>:: |
| 10999 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11000 | TypeSourceInfo *TSInfo |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11001 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 11002 | if (!TSInfo) |
| 11003 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11004 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11005 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11006 | if (Result.isInvalid()) |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11007 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11008 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11009 | if (!getDerived().AlwaysRebuild() && |
| 11010 | TSInfo == E->getTypeInfoAsWritten() && |
| 11011 | Result.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11012 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11013 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11014 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11015 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11016 | Result.get()); |
| 11017 | } |
| 11018 | |
| 11019 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11020 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11021 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11022 | // Transform arguments. |
| 11023 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11024 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11025 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11026 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11027 | &ArgChanged)) |
| 11028 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11029 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11030 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 11031 | // Class message: transform the receiver type. |
| 11032 | TypeSourceInfo *ReceiverTypeInfo |
| 11033 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 11034 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11035 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11036 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11037 | // If nothing changed, just retain the existing message send. |
| 11038 | if (!getDerived().AlwaysRebuild() && |
| 11039 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 11040 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11041 | |
| 11042 | // Build a new class message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 11043 | SmallVector<SourceLocation, 16> SelLocs; |
| 11044 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11045 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 11046 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 11047 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11048 | E->getMethodDecl(), |
| 11049 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11050 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11051 | E->getRightLoc()); |
| 11052 | } |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 11053 | else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || |
| 11054 | E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { |
| 11055 | // Build a new class message send to 'super'. |
| 11056 | SmallVector<SourceLocation, 16> SelLocs; |
| 11057 | E->getSelectorLocs(SelLocs); |
| 11058 | return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), |
| 11059 | E->getSelector(), |
| 11060 | SelLocs, |
Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 11061 | E->getReceiverType(), |
Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 11062 | E->getMethodDecl(), |
| 11063 | E->getLeftLoc(), |
| 11064 | Args, |
| 11065 | E->getRightLoc()); |
| 11066 | } |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11067 | |
| 11068 | // Instance message: transform the receiver |
| 11069 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 11070 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11071 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11072 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 11073 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11074 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11075 | |
| 11076 | // If nothing changed, just retain the existing message send. |
| 11077 | if (!getDerived().AlwaysRebuild() && |
| 11078 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 11079 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11080 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11081 | // Build a new instance message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 11082 | SmallVector<SourceLocation, 16> SelLocs; |
| 11083 | E->getSelectorLocs(SelLocs); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11084 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11085 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 11086 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11087 | E->getMethodDecl(), |
| 11088 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11089 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11090 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11091 | } |
| 11092 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11093 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11094 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11095 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11096 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11097 | } |
| 11098 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11099 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11100 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11101 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11102 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11103 | } |
| 11104 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11105 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11106 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11107 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11108 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11109 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11110 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11111 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11112 | |
| 11113 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11114 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11115 | // If nothing changed, just retain the existing expression. |
| 11116 | if (!getDerived().AlwaysRebuild() && |
| 11117 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11118 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11119 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11120 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11121 | E->getLocation(), |
| 11122 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11123 | } |
| 11124 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11125 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11126 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11127 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 11128 | // 'super' and types never change. Property never changes. Just |
| 11129 | // retain the existing expression. |
| 11130 | if (!E->isObjectReceiver()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11131 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11132 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 11133 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11134 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 11135 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11136 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11137 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 11138 | // We don't need to transform the property; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11139 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 11140 | // If nothing changed, just retain the existing expression. |
| 11141 | if (!getDerived().AlwaysRebuild() && |
| 11142 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11143 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11144 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 11145 | if (E->isExplicitProperty()) |
| 11146 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 11147 | E->getExplicitProperty(), |
| 11148 | E->getLocation()); |
| 11149 | |
| 11150 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 11151 | SemaRef.Context.PseudoObjectTy, |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 11152 | E->getImplicitPropertyGetter(), |
| 11153 | E->getImplicitPropertySetter(), |
| 11154 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11155 | } |
| 11156 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11157 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11158 | ExprResult |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11159 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 11160 | // Transform the base expression. |
| 11161 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 11162 | if (Base.isInvalid()) |
| 11163 | return ExprError(); |
| 11164 | |
| 11165 | // Transform the key expression. |
| 11166 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 11167 | if (Key.isInvalid()) |
| 11168 | return ExprError(); |
| 11169 | |
| 11170 | // If nothing changed, just retain the existing expression. |
| 11171 | if (!getDerived().AlwaysRebuild() && |
| 11172 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11173 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11174 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11175 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11176 | Base.get(), Key.get(), |
| 11177 | E->getAtIndexMethodDecl(), |
| 11178 | E->setAtIndexMethodDecl()); |
| 11179 | } |
| 11180 | |
| 11181 | template<typename Derived> |
| 11182 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11183 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11184 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11185 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11186 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11187 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11188 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11189 | // If nothing changed, just retain the existing expression. |
| 11190 | if (!getDerived().AlwaysRebuild() && |
| 11191 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11192 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11193 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11194 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 11195 | E->getOpLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11196 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11197 | } |
| 11198 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11199 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11200 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11201 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11202 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11203 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11204 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11205 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11206 | SubExprs, &ArgumentChanged)) |
| 11207 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11208 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11209 | if (!getDerived().AlwaysRebuild() && |
| 11210 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11211 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11212 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11213 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11214 | SubExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11215 | E->getRParenLoc()); |
| 11216 | } |
| 11217 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11218 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11219 | ExprResult |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 11220 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 11221 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 11222 | if (SrcExpr.isInvalid()) |
| 11223 | return ExprError(); |
| 11224 | |
| 11225 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 11226 | if (!Type) |
| 11227 | return ExprError(); |
| 11228 | |
| 11229 | if (!getDerived().AlwaysRebuild() && |
| 11230 | Type == E->getTypeSourceInfo() && |
| 11231 | SrcExpr.get() == E->getSrcExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11232 | return E; |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 11233 | |
| 11234 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 11235 | SrcExpr.get(), Type, |
| 11236 | E->getRParenLoc()); |
| 11237 | } |
| 11238 | |
| 11239 | template<typename Derived> |
| 11240 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11241 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11242 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11243 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11244 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11245 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 11246 | |
| 11247 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 11248 | blockScope->TheDecl->setBlockMissingReturnType( |
| 11249 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11250 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 11251 | SmallVector<ParmVarDecl*, 4> params; |
| 11252 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11253 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 11254 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
| 11255 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 11256 | // Parameter substitution. |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 11257 | Sema::ExtParameterInfoBuilder extParamInfos; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 11258 | if (getDerived().TransformFunctionTypeParams( |
| 11259 | E->getCaretLocation(), oldBlock->parameters(), nullptr, |
| 11260 | exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, |
| 11261 | extParamInfos)) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11262 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 11263 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 11264 | } |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11265 | |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 11266 | QualType exprResultType = |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 11267 | getDerived().TransformType(exprFunctionType->getReturnType()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 11268 | |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 11269 | auto epi = exprFunctionType->getExtProtoInfo(); |
| 11270 | epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size()); |
| 11271 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 11272 | QualType functionType = |
John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 11273 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11274 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 11275 | |
| 11276 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11277 | if (!params.empty()) |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 11278 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 11279 | |
| 11280 | if (!oldBlock->blockMissingReturnType()) { |
| 11281 | blockScope->HasImplicitReturnType = false; |
| 11282 | blockScope->ReturnType = exprResultType; |
| 11283 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11284 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 11285 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11286 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 11287 | if (body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11288 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 11289 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 11290 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 11291 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11292 | #ifndef NDEBUG |
| 11293 | // In builds with assertions, make sure that we captured everything we |
| 11294 | // captured before. |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 11295 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 11296 | for (const auto &I : oldBlock->captures()) { |
| 11297 | VarDecl *oldCapture = I.getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11298 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 11299 | // Ignore parameter packs. |
| 11300 | if (isa<ParmVarDecl>(oldCapture) && |
| 11301 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 11302 | continue; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11303 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 11304 | VarDecl *newCapture = |
| 11305 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 11306 | oldCapture)); |
| 11307 | assert(blockScope->CaptureMap.count(newCapture)); |
| 11308 | } |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 11309 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 11310 | } |
| 11311 | #endif |
| 11312 | |
| 11313 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11314 | /*Scope=*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11315 | } |
| 11316 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11317 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11318 | ExprResult |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 11319 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 11320 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 11321 | } |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 11322 | |
| 11323 | template<typename Derived> |
| 11324 | ExprResult |
| 11325 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 11326 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 11327 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11328 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 11329 | SubExprs.reserve(E->getNumSubExprs()); |
| 11330 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 11331 | SubExprs, &ArgumentChanged)) |
| 11332 | return ExprError(); |
| 11333 | |
| 11334 | if (!getDerived().AlwaysRebuild() && |
| 11335 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11336 | return E; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 11337 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11338 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 11339 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 11340 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11341 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11342 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11343 | // Type reconstruction |
| 11344 | //===----------------------------------------------------------------------===// |
| 11345 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11346 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11347 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 11348 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 11349 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11350 | getDerived().getBaseEntity()); |
| 11351 | } |
| 11352 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11353 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11354 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 11355 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 11356 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11357 | getDerived().getBaseEntity()); |
| 11358 | } |
| 11359 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11360 | template<typename Derived> |
| 11361 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11362 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 11363 | bool WrittenAsLValue, |
| 11364 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 11365 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11366 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11367 | } |
| 11368 | |
| 11369 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11370 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11371 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 11372 | QualType ClassType, |
| 11373 | SourceLocation Sigil) { |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 11374 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 11375 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11376 | } |
| 11377 | |
| 11378 | template<typename Derived> |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 11379 | QualType TreeTransform<Derived>::RebuildObjCObjectType( |
| 11380 | QualType BaseType, |
| 11381 | SourceLocation Loc, |
| 11382 | SourceLocation TypeArgsLAngleLoc, |
| 11383 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 11384 | SourceLocation TypeArgsRAngleLoc, |
| 11385 | SourceLocation ProtocolLAngleLoc, |
| 11386 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 11387 | ArrayRef<SourceLocation> ProtocolLocs, |
| 11388 | SourceLocation ProtocolRAngleLoc) { |
| 11389 | return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, |
| 11390 | TypeArgs, TypeArgsRAngleLoc, |
| 11391 | ProtocolLAngleLoc, Protocols, ProtocolLocs, |
| 11392 | ProtocolRAngleLoc, |
| 11393 | /*FailOnError=*/true); |
| 11394 | } |
| 11395 | |
| 11396 | template<typename Derived> |
| 11397 | QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( |
| 11398 | QualType PointeeType, |
| 11399 | SourceLocation Star) { |
| 11400 | return SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 11401 | } |
| 11402 | |
| 11403 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11404 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11405 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 11406 | ArrayType::ArraySizeModifier SizeMod, |
| 11407 | const llvm::APInt *Size, |
| 11408 | Expr *SizeExpr, |
| 11409 | unsigned IndexTypeQuals, |
| 11410 | SourceRange BracketsRange) { |
| 11411 | if (SizeExpr || !Size) |
| 11412 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 11413 | IndexTypeQuals, BracketsRange, |
| 11414 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11415 | |
| 11416 | QualType Types[] = { |
| 11417 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 11418 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 11419 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11420 | }; |
Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 11421 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11422 | QualType SizeType; |
| 11423 | for (unsigned I = 0; I != NumTypes; ++I) |
| 11424 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 11425 | SizeType = Types[I]; |
| 11426 | break; |
| 11427 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11428 | |
Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 11429 | // Note that we can return a VariableArrayType here in the case where |
| 11430 | // the element type was a dependent VariableArrayType. |
| 11431 | IntegerLiteral *ArraySize |
| 11432 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 11433 | /*FIXME*/BracketsRange.getBegin()); |
| 11434 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11435 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11436 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11438 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11439 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11440 | QualType |
| 11441 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11442 | ArrayType::ArraySizeModifier SizeMod, |
| 11443 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11444 | unsigned IndexTypeQuals, |
| 11445 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11446 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11447 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11448 | } |
| 11449 | |
| 11450 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11451 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11452 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11453 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11454 | unsigned IndexTypeQuals, |
| 11455 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11456 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 11457 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11458 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11459 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11460 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11461 | QualType |
| 11462 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11463 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11464 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11465 | unsigned IndexTypeQuals, |
| 11466 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11467 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11468 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11469 | IndexTypeQuals, BracketsRange); |
| 11470 | } |
| 11471 | |
| 11472 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11473 | QualType |
| 11474 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11475 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11476 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11477 | unsigned IndexTypeQuals, |
| 11478 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11479 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11480 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11481 | IndexTypeQuals, BracketsRange); |
| 11482 | } |
| 11483 | |
| 11484 | template<typename Derived> |
| 11485 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 11486 | unsigned NumElements, |
| 11487 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11488 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 11489 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11490 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11491 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11492 | template<typename Derived> |
| 11493 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 11494 | unsigned NumElements, |
| 11495 | SourceLocation AttributeLoc) { |
| 11496 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 11497 | NumElements, true); |
| 11498 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 11499 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 11500 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11501 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11502 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11503 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11504 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11505 | QualType |
| 11506 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11507 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11508 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11509 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11510 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11511 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11512 | template<typename Derived> |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 11513 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 11514 | QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 11515 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 11516 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 11517 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11518 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 11519 | getDerived().getBaseEntity(), |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 11520 | EPI); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11521 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11522 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11523 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 11524 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 11525 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 11526 | } |
| 11527 | |
| 11528 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 11529 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 11530 | assert(D && "no decl found"); |
| 11531 | if (D->isInvalidDecl()) return QualType(); |
| 11532 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11533 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 11534 | TypeDecl *Ty; |
| 11535 | if (isa<UsingDecl>(D)) { |
| 11536 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 11537 | assert(Using->hasTypename() && |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 11538 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 11539 | |
| 11540 | // A valid resolved using typename decl points to exactly one type decl. |
| 11541 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 11542 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11543 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 11544 | } else { |
| 11545 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 11546 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 11547 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 11548 | } |
| 11549 | |
| 11550 | return SemaRef.Context.getTypeDeclType(Ty); |
| 11551 | } |
| 11552 | |
| 11553 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 11554 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 11555 | SourceLocation Loc) { |
| 11556 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11557 | } |
| 11558 | |
| 11559 | template<typename Derived> |
| 11560 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 11561 | return SemaRef.Context.getTypeOfType(Underlying); |
| 11562 | } |
| 11563 | |
| 11564 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 11565 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 11566 | SourceLocation Loc) { |
| 11567 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11568 | } |
| 11569 | |
| 11570 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 11571 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 11572 | UnaryTransformType::UTTKind UKind, |
| 11573 | SourceLocation Loc) { |
| 11574 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 11575 | } |
| 11576 | |
| 11577 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11578 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 11579 | TemplateName Template, |
| 11580 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 11581 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 11582 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11583 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11584 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 11585 | template<typename Derived> |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 11586 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 11587 | SourceLocation KWLoc) { |
| 11588 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 11589 | } |
| 11590 | |
| 11591 | template<typename Derived> |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 11592 | QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType, |
| 11593 | SourceLocation KWLoc) { |
| 11594 | return SemaRef.BuildPipeType(ValueType, KWLoc); |
| 11595 | } |
| 11596 | |
| 11597 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11598 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11599 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 11600 | bool TemplateKW, |
| 11601 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11602 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 11603 | Template); |
| 11604 | } |
| 11605 | |
| 11606 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11607 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11608 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 11609 | const IdentifierInfo &Name, |
| 11610 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11611 | QualType ObjectType, |
| 11612 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11613 | UnqualifiedId TemplateName; |
| 11614 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 11615 | Sema::TemplateTy Template; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11616 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11617 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11618 | SS, TemplateKWLoc, TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11619 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 11620 | /*EnteringContext=*/false, |
| 11621 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11622 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 11623 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11624 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11625 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11626 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11627 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11628 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11629 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11630 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11631 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11632 | // FIXME: Bogus location information. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11633 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 11634 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11635 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 11636 | Sema::TemplateTy Template; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11637 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11638 | SS, TemplateKWLoc, Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11639 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 11640 | /*EnteringContext=*/false, |
| 11641 | Template); |
Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 11642 | return Template.get(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11643 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11644 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 11645 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11646 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11647 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 11648 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11649 | Expr *OrigCallee, |
| 11650 | Expr *First, |
| 11651 | Expr *Second) { |
| 11652 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 11653 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11654 | |
Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 11655 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 11656 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 11657 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 11658 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 11659 | First, Second); |
| 11660 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 11661 | if (Result.isInvalid()) |
| 11662 | return ExprError(); |
| 11663 | First = Result.get(); |
| 11664 | } |
| 11665 | |
| 11666 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 11667 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 11668 | if (Result.isInvalid()) |
| 11669 | return ExprError(); |
| 11670 | Second = Result.get(); |
| 11671 | } |
| 11672 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11673 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 11674 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11675 | if (!First->getType()->isOverloadableType() && |
| 11676 | !Second->getType()->isOverloadableType()) |
| 11677 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 11678 | Callee->getLocStart(), |
| 11679 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 11680 | } else if (Op == OO_Arrow) { |
| 11681 | // -> is never a builtin operation. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11682 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 11683 | } else if (Second == nullptr || isPostIncDec) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11684 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11685 | // The argument is not of overloadable type, so try to create a |
| 11686 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11687 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11688 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11689 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11690 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11691 | } |
| 11692 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11693 | if (!First->getType()->isOverloadableType() && |
| 11694 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11695 | // Neither of the arguments is an overloadable type, so try to |
| 11696 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11697 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11698 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11699 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11700 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11701 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11702 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11703 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11704 | } |
| 11705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11706 | |
| 11707 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11708 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 11709 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11710 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11711 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11712 | assert(ULE->requiresADL()); |
Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 11713 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11714 | } else { |
Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 11715 | // If we've resolved this to a particular non-member function, just call |
| 11716 | // that function. If we resolved it to a member function, |
| 11717 | // CreateOverloaded* will find that function for us. |
| 11718 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 11719 | if (!isa<CXXMethodDecl>(ND)) |
| 11720 | Functions.addDecl(ND); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 11721 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11722 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11723 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11724 | Expr *Args[2] = { First, Second }; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11725 | unsigned NumArgs = 1 + (Second != nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11726 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11727 | // Create the overloaded operator invocation for unary operators. |
| 11728 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11729 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11730 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11731 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11732 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11733 | |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 11734 | if (Op == OO_Subscript) { |
| 11735 | SourceLocation LBrace; |
| 11736 | SourceLocation RBrace; |
| 11737 | |
| 11738 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
NAKAMURA Takumi | 44d4d9a | 2014-10-29 08:11:47 +0000 | [diff] [blame] | 11739 | DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo(); |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 11740 | LBrace = SourceLocation::getFromRawEncoding( |
| 11741 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 11742 | RBrace = SourceLocation::getFromRawEncoding( |
| 11743 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 11744 | } else { |
| 11745 | LBrace = Callee->getLocStart(); |
| 11746 | RBrace = OpLoc; |
| 11747 | } |
| 11748 | |
| 11749 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 11750 | First, Second); |
| 11751 | } |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 11752 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11753 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 11754 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11755 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11756 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 11757 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11758 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11759 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11760 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11761 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11762 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11763 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11764 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11765 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11766 | SourceLocation OperatorLoc, |
| 11767 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 11768 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11769 | TypeSourceInfo *ScopeType, |
| 11770 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 11771 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 11772 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11773 | QualType BaseType = Base->getType(); |
| 11774 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11775 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11776 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 11777 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 11778 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11779 | // This pseudo-destructor expression is still a pseudo-destructor. |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 11780 | return SemaRef.BuildPseudoDestructorExpr( |
| 11781 | Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, |
| 11782 | CCLoc, TildeLoc, Destroyed); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11783 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11784 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 11785 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11786 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 11787 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 11788 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 11789 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 11790 | |
Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 11791 | // The scope type is now known to be a valid nested name specifier |
| 11792 | // component. Tack it on to the end of the nested name specifier. |
Alexey Bataev | 2a06681 | 2014-10-16 03:04:35 +0000 | [diff] [blame] | 11793 | if (ScopeType) { |
| 11794 | if (!ScopeType->getType()->getAs<TagType>()) { |
| 11795 | getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 11796 | diag::err_expected_class_or_namespace) |
| 11797 | << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 11798 | return ExprError(); |
| 11799 | } |
| 11800 | SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), |
| 11801 | CCLoc); |
| 11802 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11803 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11804 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11805 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11806 | OperatorLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11807 | SS, TemplateKWLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11808 | /*FIXME: FirstQualifier*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11809 | NameInfo, |
Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 11810 | /*TemplateArgs*/ nullptr, |
| 11811 | /*S*/nullptr); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 11812 | } |
| 11813 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 11814 | template<typename Derived> |
| 11815 | StmtResult |
| 11816 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 11817 | SourceLocation Loc = S->getLocStart(); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 11818 | CapturedDecl *CD = S->getCapturedDecl(); |
| 11819 | unsigned NumParams = CD->getNumParams(); |
| 11820 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 11821 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 11822 | for (unsigned I = 0; I < NumParams; ++I) { |
| 11823 | if (I != ContextParamPos) { |
| 11824 | Params.push_back( |
| 11825 | std::make_pair( |
| 11826 | CD->getParam(I)->getName(), |
| 11827 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 11828 | } else { |
| 11829 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 11830 | } |
| 11831 | } |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11832 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 11833 | S->getCapturedRegionKind(), Params); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11834 | StmtResult Body; |
| 11835 | { |
| 11836 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 11837 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 11838 | } |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 11839 | |
| 11840 | if (Body.isInvalid()) { |
| 11841 | getSema().ActOnCapturedRegionError(); |
| 11842 | return StmtError(); |
| 11843 | } |
| 11844 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11845 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 11846 | } |
| 11847 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 11848 | } // end namespace clang |
| 11849 | |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 11850 | #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |