Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 16 | |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "TypeLocBuilder.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
| 23 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 24 | #include "clang/AST/Stmt.h" |
| 25 | #include "clang/AST/StmtCXX.h" |
| 26 | #include "clang/AST/StmtObjC.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/AST/StmtOpenMP.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Designator.h" |
| 29 | #include "clang/Sema/Lookup.h" |
| 30 | #include "clang/Sema/Ownership.h" |
| 31 | #include "clang/Sema/ParsedTemplate.h" |
| 32 | #include "clang/Sema/ScopeInfo.h" |
| 33 | #include "clang/Sema/SemaDiagnostic.h" |
| 34 | #include "clang/Sema/SemaInternal.h" |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/ArrayRef.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 36 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 37 | #include <algorithm> |
| 38 | |
| 39 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 40 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 42 | /// \brief A semantic tree transformation that allows one to transform one |
| 43 | /// abstract syntax tree into another. |
| 44 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 46 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 47 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 48 | /// instantiation is implemented as a tree transformation where the |
| 49 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 50 | /// template arguments for their corresponding template parameters; a similar |
| 51 | /// transformation is performed for non-type template parameters and |
| 52 | /// template template parameters. |
| 53 | /// |
| 54 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 56 | /// override any of the transformation or rebuild operators by providing an |
| 57 | /// operation with the same signature as the default implementation. The |
| 58 | /// overridding function should not be virtual. |
| 59 | /// |
| 60 | /// Semantic tree transformations are split into two stages, either of which |
| 61 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 62 | /// or the parts of an AST node using the various transformation functions, |
| 63 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 64 | /// node of the appropriate kind from the pieces. The default transformation |
| 65 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 66 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 67 | /// were changed by the transformation, invokes the rebuild operation to create |
| 68 | /// a new AST node. |
| 69 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 71 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 72 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 73 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 74 | /// new implementations. |
| 75 | /// |
| 76 | /// For more fine-grained transformations, subclasses can replace any of the |
| 77 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 78 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 79 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 81 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 82 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 83 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 84 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 85 | /// be able to use more efficient rebuild steps. |
| 86 | /// |
| 87 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 89 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 90 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 91 | /// default locations and entity names used for type-checking |
| 92 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 93 | template<typename Derived> |
| 94 | class TreeTransform { |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 95 | /// \brief Private RAII object that helps us forget and then re-remember |
| 96 | /// the template argument corresponding to a partially-substituted parameter |
| 97 | /// pack. |
| 98 | class ForgetPartiallySubstitutedPackRAII { |
| 99 | Derived &Self; |
| 100 | TemplateArgument Old; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 102 | public: |
| 103 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 104 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 105 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 106 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 107 | ~ForgetPartiallySubstitutedPackRAII() { |
| 108 | Self.RememberPartiallySubstitutedPack(Old); |
| 109 | } |
| 110 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 111 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 112 | protected: |
| 113 | Sema &SemaRef; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 115 | /// \brief The set of local declarations that have been transformed, for |
| 116 | /// cases where we are forced to build new declarations within the transformer |
| 117 | /// rather than in the subclass (e.g., lambda closure types). |
| 118 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 119 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 121 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 122 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 124 | /// \brief Retrieves a reference to the derived class. |
| 125 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 126 | |
| 127 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | const Derived &getDerived() const { |
| 129 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | } |
| 131 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 132 | static inline ExprResult Owned(Expr *E) { return E; } |
| 133 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 134 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 135 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 136 | /// this tree transform. |
| 137 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 139 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 140 | /// if none of the children have changed. |
| 141 | /// |
| 142 | /// Subclasses may override this function to specify when the transformation |
| 143 | /// should rebuild all AST nodes. |
Richard Smith | 2aa81a7 | 2013-11-07 20:07:17 +0000 | [diff] [blame] | 144 | /// |
| 145 | /// We must always rebuild all AST nodes when performing variadic template |
| 146 | /// pack expansion, in order to avoid violating the AST invariant that each |
| 147 | /// statement node appears at most once in its containing declaration. |
| 148 | bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 150 | /// \brief Returns the location of the entity being transformed, if that |
| 151 | /// information was not available elsewhere in the AST. |
| 152 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 154 | /// provide an alternative implementation that provides better location |
| 155 | /// information. |
| 156 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 158 | /// \brief Returns the name of the entity being transformed, if that |
| 159 | /// information was not available elsewhere in the AST. |
| 160 | /// |
| 161 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 162 | /// implementation with a more precise name. |
| 163 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 164 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 165 | /// \brief Sets the "base" location and entity when that |
| 166 | /// information is known based on another transformation. |
| 167 | /// |
| 168 | /// By default, the source location and entity are ignored. Subclasses can |
| 169 | /// override this function to provide a customized implementation. |
| 170 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 172 | /// \brief RAII object that temporarily sets the base location and entity |
| 173 | /// used for reporting diagnostics in types. |
| 174 | class TemporaryBase { |
| 175 | TreeTransform &Self; |
| 176 | SourceLocation OldLocation; |
| 177 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 179 | public: |
| 180 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 182 | OldLocation = Self.getDerived().getBaseLocation(); |
| 183 | OldEntity = Self.getDerived().getBaseEntity(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 184 | |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 185 | if (Location.isValid()) |
| 186 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 187 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 189 | ~TemporaryBase() { |
| 190 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 191 | } |
| 192 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | |
| 194 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 195 | /// transformed. |
| 196 | /// |
| 197 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 198 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 199 | /// not change. For example, template instantiation need not traverse |
| 200 | /// non-dependent types. |
| 201 | bool AlreadyTransformed(QualType T) { |
| 202 | return T.isNull(); |
| 203 | } |
| 204 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 205 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 206 | /// because it is a default argument. |
| 207 | /// |
| 208 | /// Subclasses can provide an alternative implementation of this routine to |
| 209 | /// determine which kinds of call arguments get dropped. By default, |
| 210 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 211 | bool DropCallArgument(Expr *E) { |
| 212 | return E->isDefaultArgument(); |
| 213 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 214 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 215 | /// \brief Determine whether we should expand a pack expansion with the |
| 216 | /// given set of parameter packs into separate arguments by repeatedly |
| 217 | /// transforming the pattern. |
| 218 | /// |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 219 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 220 | /// Subclasses can override this routine to provide different behavior. |
| 221 | /// |
| 222 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 223 | /// pack expansion. |
| 224 | /// |
| 225 | /// \param PatternRange The source range that covers the entire pattern of |
| 226 | /// the pack expansion. |
| 227 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 228 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 229 | /// pattern. |
| 230 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 231 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 232 | /// expand the corresponding pack expansions into separate arguments. When |
| 233 | /// set, \c NumExpansions must also be set. |
| 234 | /// |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 235 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 236 | /// pack expansion after all of the expanded arguments. This is used |
| 237 | /// when extending explicitly-specified template argument packs per |
| 238 | /// C++0x [temp.arg.explicit]p9. |
| 239 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 240 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 241 | /// the expanded form of the corresponding pack expansion. This is both an |
| 242 | /// input and an output parameter, which can be set by the caller if the |
| 243 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 244 | /// and will be set by the callee when the number of expansions is known. |
| 245 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 246 | /// set this value in other cases. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 247 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 248 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 249 | /// are to be instantiated with arguments of different lengths), false |
| 250 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 251 | /// must be set. |
| 252 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 253 | SourceRange PatternRange, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 254 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 255 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 256 | bool &RetainExpansion, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 257 | Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 258 | ShouldExpand = false; |
| 259 | return false; |
| 260 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 261 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 262 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 263 | /// when performing an instantiation that must preserve the parameter pack |
| 264 | /// use. |
| 265 | /// |
| 266 | /// This routine is meant to be overridden by the template instantiator. |
| 267 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 268 | return TemplateArgument(); |
| 269 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 270 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 271 | /// \brief "Remember" the partially-substituted pack template argument |
| 272 | /// after performing an instantiation that must preserve the parameter pack |
| 273 | /// use. |
| 274 | /// |
| 275 | /// This routine is meant to be overridden by the template instantiator. |
| 276 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 277 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 278 | /// \brief Note to the derived class when a function parameter pack is |
| 279 | /// being expanded. |
| 280 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 281 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 282 | /// \brief Transforms the given type into another type. |
| 283 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 284 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 285 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 286 | /// function. This is expensive, but we don't mind, because |
| 287 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 288 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 289 | /// |
| 290 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 291 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 293 | /// \brief Transforms the given type-with-location into a new |
| 294 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 295 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 296 | /// By default, this routine transforms a type by delegating to the |
| 297 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 298 | /// may override this function (to take over all type |
| 299 | /// transformations) or some set of the TransformXXXType functions |
| 300 | /// to alter the transformation. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 301 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 302 | |
| 303 | /// \brief Transform the given type-with-location into a new |
| 304 | /// type, collecting location information in the given builder |
| 305 | /// as necessary. |
| 306 | /// |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 307 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 309 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 310 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 312 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 313 | /// statement or the TransformExpr() function to transform an expression. |
| 314 | /// Subclasses may override this function to transform statements using some |
| 315 | /// other mechanism. |
| 316 | /// |
| 317 | /// \returns the transformed statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 318 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 320 | /// \brief Transform the given statement. |
| 321 | /// |
| 322 | /// By default, this routine transforms a statement by delegating to the |
| 323 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 324 | /// of clause. Subclasses may override this function to transform statements |
| 325 | /// using some other mechanism. |
| 326 | /// |
| 327 | /// \returns the transformed OpenMP clause. |
| 328 | OMPClause *TransformOMPClause(OMPClause *S); |
| 329 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 330 | /// \brief Transform the given attribute. |
| 331 | /// |
| 332 | /// By default, this routine transforms a statement by delegating to the |
| 333 | /// appropriate TransformXXXAttr function to transform a specific kind |
| 334 | /// of attribute. Subclasses may override this function to transform |
| 335 | /// attributed statements using some other mechanism. |
| 336 | /// |
| 337 | /// \returns the transformed attribute |
| 338 | const Attr *TransformAttr(const Attr *S); |
| 339 | |
| 340 | /// \brief Transform the specified attribute. |
| 341 | /// |
| 342 | /// Subclasses should override the transformation of attributes with a pragma |
| 343 | /// spelling to transform expressions stored within the attribute. |
| 344 | /// |
| 345 | /// \returns the transformed attribute. |
| 346 | #define ATTR(X) |
| 347 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 348 | const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } |
| 349 | #include "clang/Basic/AttrList.inc" |
| 350 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 351 | /// \brief Transform the given expression. |
| 352 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 353 | /// By default, this routine transforms an expression by delegating to the |
| 354 | /// appropriate TransformXXXExpr function to build a new expression. |
| 355 | /// Subclasses may override this function to transform expressions using some |
| 356 | /// other mechanism. |
| 357 | /// |
| 358 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 359 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 361 | /// \brief Transform the given initializer. |
| 362 | /// |
| 363 | /// By default, this routine transforms an initializer by stripping off the |
| 364 | /// semantic nodes added by initialization, then passing the result to |
| 365 | /// TransformExpr or TransformExprs. |
| 366 | /// |
| 367 | /// \returns the transformed initializer. |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 368 | ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 369 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 370 | /// \brief Transform the given list of expressions. |
| 371 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 372 | /// This routine transforms a list of expressions by invoking |
| 373 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 374 | /// support for variadic templates by expanding any pack expansions (if the |
| 375 | /// derived class permits such expansion) along the way. When pack expansions |
| 376 | /// are present, the number of outputs may not equal the number of inputs. |
| 377 | /// |
| 378 | /// \param Inputs The set of expressions to be transformed. |
| 379 | /// |
| 380 | /// \param NumInputs The number of expressions in \c Inputs. |
| 381 | /// |
| 382 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 383 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 384 | /// be. |
| 385 | /// |
| 386 | /// \param Outputs The transformed input expressions will be added to this |
| 387 | /// vector. |
| 388 | /// |
| 389 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 390 | /// due to transformation. |
| 391 | /// |
| 392 | /// \returns true if an error occurred, false otherwise. |
| 393 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 394 | SmallVectorImpl<Expr *> &Outputs, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 395 | bool *ArgChanged = nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 396 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 397 | /// \brief Transform the given declaration, which is referenced from a type |
| 398 | /// or expression. |
| 399 | /// |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 400 | /// By default, acts as the identity function on declarations, unless the |
| 401 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 402 | /// may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 403 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 404 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 405 | = TransformedLocalDecls.find(D); |
| 406 | if (Known != TransformedLocalDecls.end()) |
| 407 | return Known->second; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 408 | |
| 409 | return D; |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 410 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 411 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 412 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 413 | /// place them on the new declaration. |
| 414 | /// |
| 415 | /// By default, this operation does nothing. Subclasses may override this |
| 416 | /// behavior to transform attributes. |
| 417 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 418 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 419 | /// \brief Note that a local declaration has been transformed by this |
| 420 | /// transformer. |
| 421 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 422 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 423 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 424 | /// the transformer itself has to transform the declarations. This routine |
| 425 | /// can be overridden by a subclass that keeps track of such mappings. |
| 426 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 427 | TransformedLocalDecls[Old] = New; |
| 428 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 429 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 430 | /// \brief Transform the definition of the given declaration. |
| 431 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 433 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 434 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 435 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 438 | /// \brief Transform the given declaration, which was the first part of a |
| 439 | /// nested-name-specifier in a member access expression. |
| 440 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 441 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 442 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 443 | /// the \c T in \c x->T::member |
| 444 | /// |
| 445 | /// By default, invokes TransformDecl() to transform the declaration. |
| 446 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 447 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 448 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 449 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 451 | /// \brief Transform the given nested-name-specifier with source-location |
| 452 | /// information. |
| 453 | /// |
| 454 | /// By default, transforms all of the types and declarations within the |
| 455 | /// nested-name-specifier. Subclasses may override this function to provide |
| 456 | /// alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 457 | NestedNameSpecifierLoc |
| 458 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 459 | QualType ObjectType = QualType(), |
| 460 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 461 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 462 | /// \brief Transform the given declaration name. |
| 463 | /// |
| 464 | /// By default, transforms the types of conversion function, constructor, |
| 465 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 466 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 467 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 468 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 469 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 470 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 471 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | /// |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 473 | /// \param SS The nested-name-specifier that qualifies the template |
| 474 | /// name. This nested-name-specifier must already have been transformed. |
| 475 | /// |
| 476 | /// \param Name The template name to transform. |
| 477 | /// |
| 478 | /// \param NameLoc The source location of the template name. |
| 479 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 480 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 481 | /// access expression, this is the type of the object whose member template |
| 482 | /// is being referenced. |
| 483 | /// |
| 484 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 485 | /// also refers to a name within the current (lexical) scope, this is the |
| 486 | /// declaration it refers to. |
| 487 | /// |
| 488 | /// By default, transforms the template name by transforming the declarations |
| 489 | /// and nested-name-specifiers that occur within the template name. |
| 490 | /// Subclasses may override this function to provide alternate behavior. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 491 | TemplateName |
| 492 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 493 | SourceLocation NameLoc, |
| 494 | QualType ObjectType = QualType(), |
| 495 | NamedDecl *FirstQualifierInScope = nullptr); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 496 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 497 | /// \brief Transform the given template argument. |
| 498 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | /// By default, this operation transforms the type, expression, or |
| 500 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 501 | /// new template argument from the transformed result. Subclasses may |
| 502 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 503 | /// |
| 504 | /// Returns true if there was an error. |
| 505 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 506 | TemplateArgumentLoc &Output); |
| 507 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 508 | /// \brief Transform the given set of template arguments. |
| 509 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 510 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 511 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 512 | /// the transformed arguments to the output list. |
| 513 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 514 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 515 | /// a convenience function. Subclasses that wish to override this behavior |
| 516 | /// should override the iterator-based member template version. |
| 517 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 518 | /// \param Inputs The set of template arguments to be transformed. |
| 519 | /// |
| 520 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 521 | /// |
| 522 | /// \param Outputs The set of transformed template arguments output by this |
| 523 | /// routine. |
| 524 | /// |
| 525 | /// Returns true if an error occurred. |
| 526 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 527 | unsigned NumInputs, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 528 | TemplateArgumentListInfo &Outputs) { |
| 529 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 530 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 531 | |
| 532 | /// \brief Transform the given set of template arguments. |
| 533 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 534 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 535 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 536 | /// the transformed arguments to the output list. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 537 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 538 | /// \param First An iterator to the first template argument. |
| 539 | /// |
| 540 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 541 | /// |
| 542 | /// \param Outputs The set of transformed template arguments output by this |
| 543 | /// routine. |
| 544 | /// |
| 545 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 546 | template<typename InputIterator> |
| 547 | bool TransformTemplateArguments(InputIterator First, |
| 548 | InputIterator Last, |
| 549 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 550 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 551 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 552 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 553 | TemplateArgumentLoc &ArgLoc); |
| 554 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 555 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 556 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 557 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 558 | getDerived().getBaseLocation()); |
| 559 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 560 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 561 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 562 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 563 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 564 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 565 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 566 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 567 | FunctionProtoTypeLoc TL, |
| 568 | CXXRecordDecl *ThisContext, |
NAKAMURA Takumi | 2322415 | 2014-10-17 12:48:37 +0000 | [diff] [blame] | 569 | unsigned ThisTypeQuals); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 570 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 571 | StmtResult TransformSEHHandler(Stmt *Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 572 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 573 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 574 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 575 | TemplateSpecializationTypeLoc TL, |
| 576 | TemplateName Template); |
| 577 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 578 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 579 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 580 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 581 | TemplateName Template, |
| 582 | CXXScopeSpec &SS); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 583 | |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 584 | QualType TransformDependentTemplateSpecializationType( |
| 585 | TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, |
| 586 | NestedNameSpecifierLoc QualifierLoc); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 587 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 588 | /// \brief Transforms the parameters of a function type into the |
| 589 | /// given vectors. |
| 590 | /// |
| 591 | /// The result vectors should be kept in sync; null entries in the |
| 592 | /// variables vector are acceptable. |
| 593 | /// |
| 594 | /// Return true on error. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 595 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 596 | ParmVarDecl **Params, unsigned NumParams, |
| 597 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 598 | SmallVectorImpl<QualType> &PTypes, |
| 599 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 600 | |
| 601 | /// \brief Transforms a single function-type parameter. Return null |
| 602 | /// on error. |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 603 | /// |
| 604 | /// \param indexAdjustment - A number to add to the parameter's |
| 605 | /// scope index; can be negative |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 606 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 607 | int indexAdjustment, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 608 | Optional<unsigned> NumExpansions, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 609 | bool ExpectParameterPack); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 610 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 611 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 612 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 613 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 614 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 615 | |
| 616 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 617 | /// \brief Transform the captures and body of a lambda expression. |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 618 | ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator, |
| 619 | ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 620 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 621 | TemplateParameterList *TransformTemplateParameterList( |
| 622 | TemplateParameterList *TPL) { |
| 623 | return TPL; |
| 624 | } |
| 625 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 626 | ExprResult TransformAddressOfOperand(Expr *E); |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 627 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 628 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 629 | bool IsAddressOfOperand, |
| 630 | TypeSourceInfo **RecoveryTSI); |
| 631 | |
| 632 | ExprResult TransformParenDependentScopeDeclRefExpr( |
| 633 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 634 | TypeSourceInfo **RecoveryTSI); |
| 635 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 636 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 637 | |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 638 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 639 | // amount of stack usage with clang. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 640 | #define STMT(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 641 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 642 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 643 | #define EXPR(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 644 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 645 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 646 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 647 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 648 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 649 | #define OPENMP_CLAUSE(Name, Class) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 650 | LLVM_ATTRIBUTE_NOINLINE \ |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 651 | OMPClause *Transform ## Class(Class *S); |
| 652 | #include "clang/Basic/OpenMPKinds.def" |
| 653 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 654 | /// \brief Build a new pointer type given its pointee type. |
| 655 | /// |
| 656 | /// By default, performs semantic analysis when building the pointer type. |
| 657 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 658 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 659 | |
| 660 | /// \brief Build a new block pointer type given its pointee type. |
| 661 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 662 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 663 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 664 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 665 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 666 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 667 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 668 | /// By default, performs semantic analysis when building the |
| 669 | /// reference type. Subclasses may override this routine to provide |
| 670 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 671 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 672 | /// \param LValue whether the type was written with an lvalue sigil |
| 673 | /// or an rvalue sigil. |
| 674 | QualType RebuildReferenceType(QualType ReferentType, |
| 675 | bool LValue, |
| 676 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 678 | /// \brief Build a new member pointer type given the pointee type and the |
| 679 | /// class type it refers into. |
| 680 | /// |
| 681 | /// By default, performs semantic analysis when building the member pointer |
| 682 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 683 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 684 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 685 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 686 | /// \brief Build a new array type given the element type, size |
| 687 | /// modifier, size of the array (if known), size expression, and index type |
| 688 | /// qualifiers. |
| 689 | /// |
| 690 | /// By default, performs semantic analysis when building the array type. |
| 691 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 693 | QualType RebuildArrayType(QualType ElementType, |
| 694 | ArrayType::ArraySizeModifier SizeMod, |
| 695 | const llvm::APInt *Size, |
| 696 | Expr *SizeExpr, |
| 697 | unsigned IndexTypeQuals, |
| 698 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 699 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 700 | /// \brief Build a new constant array type given the element type, size |
| 701 | /// modifier, (known) size of the array, and index type qualifiers. |
| 702 | /// |
| 703 | /// By default, performs semantic analysis when building the array type. |
| 704 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 706 | ArrayType::ArraySizeModifier SizeMod, |
| 707 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 708 | unsigned IndexTypeQuals, |
| 709 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 710 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 711 | /// \brief Build a new incomplete array type given the element type, size |
| 712 | /// modifier, and index type qualifiers. |
| 713 | /// |
| 714 | /// By default, performs semantic analysis when building the array type. |
| 715 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 716 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 717 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 718 | unsigned IndexTypeQuals, |
| 719 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 720 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 721 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 722 | /// size modifier, size expression, and index type qualifiers. |
| 723 | /// |
| 724 | /// By default, performs semantic analysis when building the array type. |
| 725 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 727 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 728 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 729 | unsigned IndexTypeQuals, |
| 730 | SourceRange BracketsRange); |
| 731 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 733 | /// size modifier, size expression, and index type qualifiers. |
| 734 | /// |
| 735 | /// By default, performs semantic analysis when building the array type. |
| 736 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 737 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 738 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 739 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 740 | unsigned IndexTypeQuals, |
| 741 | SourceRange BracketsRange); |
| 742 | |
| 743 | /// \brief Build a new vector type given the element type and |
| 744 | /// number of elements. |
| 745 | /// |
| 746 | /// By default, performs semantic analysis when building the vector type. |
| 747 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 748 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 749 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 751 | /// \brief Build a new extended vector type given the element type and |
| 752 | /// number of elements. |
| 753 | /// |
| 754 | /// By default, performs semantic analysis when building the vector type. |
| 755 | /// Subclasses may override this routine to provide different behavior. |
| 756 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 757 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | |
| 759 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 760 | /// given the element type and number of elements. |
| 761 | /// |
| 762 | /// By default, performs semantic analysis when building the vector type. |
| 763 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
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 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 768 | /// \brief Build a new function type. |
| 769 | /// |
| 770 | /// By default, performs semantic analysis when building the function type. |
| 771 | /// Subclasses may override this routine to provide different behavior. |
| 772 | QualType RebuildFunctionProtoType(QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 773 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 774 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 776 | /// \brief Build a new unprototyped function type. |
| 777 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 778 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 779 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 780 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 781 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 782 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 783 | /// \brief Build a new typedef type. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 784 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 785 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 786 | } |
| 787 | |
| 788 | /// \brief Build a new class/struct/union type. |
| 789 | QualType RebuildRecordType(RecordDecl *Record) { |
| 790 | return SemaRef.Context.getTypeDeclType(Record); |
| 791 | } |
| 792 | |
| 793 | /// \brief Build a new Enum type. |
| 794 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 795 | return SemaRef.Context.getTypeDeclType(Enum); |
| 796 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 797 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 799 | /// |
| 800 | /// By default, performs semantic analysis when building the typeof type. |
| 801 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 802 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 803 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 805 | /// |
| 806 | /// By default, builds a new TypeOfType with the given underlying type. |
| 807 | QualType RebuildTypeOfType(QualType Underlying); |
| 808 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 809 | /// \brief Build a new unary transform type. |
| 810 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 811 | UnaryTransformType::UTTKind UKind, |
| 812 | SourceLocation Loc); |
| 813 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 814 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 815 | /// |
| 816 | /// By default, performs semantic analysis when building the decltype type. |
| 817 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 818 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 819 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 820 | /// \brief Build a new C++11 auto type. |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 821 | /// |
| 822 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 823 | QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) { |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 824 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 825 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 826 | // that we'll retry deduction after the transformation. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 827 | return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto, |
| 828 | /*IsDependent*/ false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 831 | /// \brief Build a new template specialization type. |
| 832 | /// |
| 833 | /// By default, performs semantic analysis when building the template |
| 834 | /// specialization type. Subclasses may override this routine to provide |
| 835 | /// different behavior. |
| 836 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 837 | SourceLocation TemplateLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 838 | TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 840 | /// \brief Build a new parenthesized type. |
| 841 | /// |
| 842 | /// By default, builds a new ParenType type from the inner type. |
| 843 | /// Subclasses may override this routine to provide different behavior. |
| 844 | QualType RebuildParenType(QualType InnerType) { |
| 845 | return SemaRef.Context.getParenType(InnerType); |
| 846 | } |
| 847 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 848 | /// \brief Build a new qualified name type. |
| 849 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 850 | /// By default, builds a new ElaboratedType type from the keyword, |
| 851 | /// the nested-name-specifier and the named type. |
| 852 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 853 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 854 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 855 | NestedNameSpecifierLoc QualifierLoc, |
| 856 | QualType Named) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 857 | return SemaRef.Context.getElaboratedType(Keyword, |
| 858 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 859 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 861 | |
| 862 | /// \brief Build a new typename type that refers to a template-id. |
| 863 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 864 | /// By default, builds a new DependentNameType type from the |
| 865 | /// nested-name-specifier and the given type. Subclasses may override |
| 866 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 867 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 868 | ElaboratedTypeKeyword Keyword, |
| 869 | NestedNameSpecifierLoc QualifierLoc, |
| 870 | const IdentifierInfo *Name, |
| 871 | SourceLocation NameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 872 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 873 | // Rebuild the template name. |
| 874 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 875 | CXXScopeSpec SS; |
| 876 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 877 | TemplateName InstName |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 878 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), |
| 879 | nullptr); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 880 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 881 | if (InstName.isNull()) |
| 882 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 883 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 884 | // If it's still dependent, make a dependent specialization. |
| 885 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 886 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 887 | QualifierLoc.getNestedNameSpecifier(), |
| 888 | Name, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 889 | Args); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 890 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 891 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 892 | // specialization. |
| 893 | QualType T = |
| 894 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 895 | if (T.isNull()) return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 896 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 897 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 898 | return T; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 899 | |
| 900 | return SemaRef.Context.getElaboratedType(Keyword, |
| 901 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 902 | T); |
| 903 | } |
| 904 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 905 | /// \brief Build a new typename type that refers to an identifier. |
| 906 | /// |
| 907 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 908 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 909 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 910 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 911 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 912 | NestedNameSpecifierLoc QualifierLoc, |
| 913 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 914 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 915 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 916 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 917 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 918 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 919 | // If the name is still dependent, just build a new dependent name type. |
| 920 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 921 | return SemaRef.Context.getDependentNameType(Keyword, |
| 922 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 923 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 926 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 927 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 928 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 929 | |
| 930 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 931 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 932 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 933 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 934 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 935 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 936 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 937 | if (!DC) |
| 938 | return QualType(); |
| 939 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 940 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 941 | return QualType(); |
| 942 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 943 | TagDecl *Tag = nullptr; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 944 | SemaRef.LookupQualifiedName(Result, DC); |
| 945 | switch (Result.getResultKind()) { |
| 946 | case LookupResult::NotFound: |
| 947 | case LookupResult::NotFoundInCurrentInstantiation: |
| 948 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 949 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 950 | case LookupResult::Found: |
| 951 | Tag = Result.getAsSingle<TagDecl>(); |
| 952 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 953 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 954 | case LookupResult::FoundOverloaded: |
| 955 | case LookupResult::FoundUnresolvedValue: |
| 956 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 957 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 958 | case LookupResult::Ambiguous: |
| 959 | // Let the LookupResult structure handle ambiguities. |
| 960 | return QualType(); |
| 961 | } |
| 962 | |
| 963 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 964 | // Check where the name exists but isn't a tag type and use that to emit |
| 965 | // better diagnostics. |
| 966 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 967 | SemaRef.LookupQualifiedName(Result, DC); |
| 968 | switch (Result.getResultKind()) { |
| 969 | case LookupResult::Found: |
| 970 | case LookupResult::FoundOverloaded: |
| 971 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 972 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 973 | unsigned Kind = 0; |
| 974 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 975 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 976 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 977 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 978 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 979 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 980 | } |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 981 | default: |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 982 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Stephan Tolksdorf | eb7708d | 2014-03-13 20:34:03 +0000 | [diff] [blame] | 983 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 984 | break; |
| 985 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 986 | return QualType(); |
| 987 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 988 | |
Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 989 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 990 | IdLoc, *Id)) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 991 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 992 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 993 | return QualType(); |
| 994 | } |
| 995 | |
| 996 | // Build the elaborated-type-specifier type. |
| 997 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 998 | return SemaRef.Context.getElaboratedType(Keyword, |
| 999 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1000 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1001 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1003 | /// \brief Build a new pack expansion type. |
| 1004 | /// |
| 1005 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 1006 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1007 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1008 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1009 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1010 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1011 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 1012 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1015 | /// \brief Build a new atomic type given its value type. |
| 1016 | /// |
| 1017 | /// By default, performs semantic analysis when building the atomic type. |
| 1018 | /// Subclasses may override this routine to provide different behavior. |
| 1019 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1020 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1021 | /// \brief Build a new template name given a nested name specifier, a flag |
| 1022 | /// indicating whether the "template" keyword was provided, and the template |
| 1023 | /// that the template name refers to. |
| 1024 | /// |
| 1025 | /// By default, builds the new template name directly. Subclasses may override |
| 1026 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1027 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1028 | bool TemplateKW, |
| 1029 | TemplateDecl *Template); |
| 1030 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1031 | /// \brief Build a new template name given a nested name specifier and the |
| 1032 | /// name that is referred to as a template. |
| 1033 | /// |
| 1034 | /// By default, performs semantic analysis to determine whether the name can |
| 1035 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1036 | /// template name. Subclasses may override this routine to provide different |
| 1037 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1038 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1039 | const IdentifierInfo &Name, |
| 1040 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1041 | QualType ObjectType, |
| 1042 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1043 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1044 | /// \brief Build a new template name given a nested name specifier and the |
| 1045 | /// overloaded operator name that is referred to as a template. |
| 1046 | /// |
| 1047 | /// By default, performs semantic analysis to determine whether the name can |
| 1048 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1049 | /// template name. Subclasses may override this routine to provide different |
| 1050 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1051 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1052 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1053 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1054 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1055 | |
| 1056 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1057 | /// and the |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1058 | /// |
| 1059 | /// By default, performs semantic analysis to determine whether the name can |
| 1060 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1061 | /// template name. Subclasses may override this routine to provide different |
| 1062 | /// behavior. |
| 1063 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1064 | const TemplateArgument &ArgPack) { |
| 1065 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1066 | } |
| 1067 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1068 | /// \brief Build a new compound statement. |
| 1069 | /// |
| 1070 | /// By default, performs semantic analysis to build the new statement. |
| 1071 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1072 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1073 | MultiStmtArg Statements, |
| 1074 | SourceLocation RBraceLoc, |
| 1075 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1076 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1077 | IsStmtExpr); |
| 1078 | } |
| 1079 | |
| 1080 | /// \brief Build a new case statement. |
| 1081 | /// |
| 1082 | /// By default, performs semantic analysis to build the new statement. |
| 1083 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1084 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1085 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1086 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1087 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1088 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1089 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1090 | ColonLoc); |
| 1091 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1093 | /// \brief Attach the body to a new case statement. |
| 1094 | /// |
| 1095 | /// By default, performs semantic analysis to build the new statement. |
| 1096 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1097 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1098 | getSema().ActOnCaseStmtBody(S, Body); |
| 1099 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1100 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1102 | /// \brief Build a new default statement. |
| 1103 | /// |
| 1104 | /// By default, performs semantic analysis to build the new statement. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1106 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1107 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1108 | Stmt *SubStmt) { |
| 1109 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1110 | /*CurScope=*/nullptr); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1111 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1113 | /// \brief Build a new label statement. |
| 1114 | /// |
| 1115 | /// By default, performs semantic analysis to build the new statement. |
| 1116 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1117 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1118 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1119 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1120 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1122 | /// \brief Build a new label statement. |
| 1123 | /// |
| 1124 | /// By default, performs semantic analysis to build the new statement. |
| 1125 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1126 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1127 | ArrayRef<const Attr*> Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1128 | Stmt *SubStmt) { |
| 1129 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1130 | } |
| 1131 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1132 | /// \brief Build a new "if" statement. |
| 1133 | /// |
| 1134 | /// By default, performs semantic analysis to build the new statement. |
| 1135 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1136 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1137 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1138 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1139 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
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 Start building a new switch 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 RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1147 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1148 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1149 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1152 | /// \brief Attach the body to the switch statement. |
| 1153 | /// |
| 1154 | /// By default, performs semantic analysis to build the new statement. |
| 1155 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1156 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1157 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1158 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /// \brief Build a new while statement. |
| 1162 | /// |
| 1163 | /// By default, performs semantic analysis to build the new statement. |
| 1164 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1165 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1166 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1167 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1170 | /// \brief Build a new do-while statement. |
| 1171 | /// |
| 1172 | /// By default, performs semantic analysis to build the new statement. |
| 1173 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1174 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1175 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1176 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1177 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1178 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | /// \brief Build a new for statement. |
| 1182 | /// |
| 1183 | /// By default, performs semantic analysis to build the new statement. |
| 1184 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1185 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1186 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1187 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1188 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1189 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1190 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1191 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1193 | /// \brief Build a new goto statement. |
| 1194 | /// |
| 1195 | /// By default, performs semantic analysis to build the new statement. |
| 1196 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1197 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1198 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1199 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | /// \brief Build a new indirect goto statement. |
| 1203 | /// |
| 1204 | /// By default, performs semantic analysis to build the new statement. |
| 1205 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1206 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1207 | SourceLocation StarLoc, |
| 1208 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1209 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1210 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1212 | /// \brief Build a new return statement. |
| 1213 | /// |
| 1214 | /// By default, performs semantic analysis to build the new statement. |
| 1215 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1216 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
Nick Lewycky | d78f92f | 2014-05-03 00:41:18 +0000 | [diff] [blame] | 1217 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1218 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1220 | /// \brief Build a new declaration statement. |
| 1221 | /// |
| 1222 | /// By default, performs semantic analysis to build the new statement. |
| 1223 | /// Subclasses may override this routine to provide different behavior. |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 1224 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1225 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1226 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1227 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1228 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1230 | /// \brief Build a new inline asm statement. |
| 1231 | /// |
| 1232 | /// By default, performs semantic analysis to build the new statement. |
| 1233 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1234 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1235 | bool IsVolatile, unsigned NumOutputs, |
| 1236 | unsigned NumInputs, IdentifierInfo **Names, |
| 1237 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1238 | Expr *AsmString, MultiExprArg Clobbers, |
| 1239 | SourceLocation RParenLoc) { |
| 1240 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1241 | NumInputs, Names, Constraints, Exprs, |
| 1242 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1243 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1244 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1245 | /// \brief Build a new MS style inline asm statement. |
| 1246 | /// |
| 1247 | /// By default, performs semantic analysis to build the new statement. |
| 1248 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1249 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1250 | ArrayRef<Token> AsmToks, |
| 1251 | StringRef AsmString, |
| 1252 | unsigned NumOutputs, unsigned NumInputs, |
| 1253 | ArrayRef<StringRef> Constraints, |
| 1254 | ArrayRef<StringRef> Clobbers, |
| 1255 | ArrayRef<Expr*> Exprs, |
| 1256 | SourceLocation EndLoc) { |
| 1257 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1258 | NumOutputs, NumInputs, |
| 1259 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1262 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1263 | /// |
| 1264 | /// By default, performs semantic analysis to build the new statement. |
| 1265 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1266 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1267 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1268 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1269 | Stmt *Finally) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1270 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1271 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1274 | /// \brief Rebuild an Objective-C exception declaration. |
| 1275 | /// |
| 1276 | /// By default, performs semantic analysis to build the new declaration. |
| 1277 | /// Subclasses may override this routine to provide different behavior. |
| 1278 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1279 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1280 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1281 | ExceptionDecl->getInnerLocStart(), |
| 1282 | ExceptionDecl->getLocation(), |
| 1283 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1284 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1285 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1286 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1287 | /// |
| 1288 | /// By default, performs semantic analysis to build the new statement. |
| 1289 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1290 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1291 | SourceLocation RParenLoc, |
| 1292 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1293 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1294 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1295 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1296 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1297 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1298 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1299 | /// |
| 1300 | /// By default, performs semantic analysis to build the new statement. |
| 1301 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1302 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1303 | Stmt *Body) { |
| 1304 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1305 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1306 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1307 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1308 | /// |
| 1309 | /// By default, performs semantic analysis to build the new statement. |
| 1310 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1311 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1312 | Expr *Operand) { |
| 1313 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1314 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1315 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1316 | /// \brief Build a new OpenMP executable directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1317 | /// |
| 1318 | /// By default, performs semantic analysis to build the new statement. |
| 1319 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1320 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1321 | DeclarationNameInfo DirName, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1322 | ArrayRef<OMPClause *> Clauses, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1323 | Stmt *AStmt, SourceLocation StartLoc, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1324 | SourceLocation EndLoc) { |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1325 | return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses, |
| 1326 | AStmt, StartLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1329 | /// \brief Build a new OpenMP 'if' clause. |
| 1330 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1331 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1332 | /// Subclasses may override this routine to provide different behavior. |
| 1333 | OMPClause *RebuildOMPIfClause(Expr *Condition, |
| 1334 | SourceLocation StartLoc, |
| 1335 | SourceLocation LParenLoc, |
| 1336 | SourceLocation EndLoc) { |
| 1337 | return getSema().ActOnOpenMPIfClause(Condition, StartLoc, |
| 1338 | LParenLoc, EndLoc); |
| 1339 | } |
| 1340 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1341 | /// \brief Build a new OpenMP 'final' clause. |
| 1342 | /// |
| 1343 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1344 | /// Subclasses may override this routine to provide different behavior. |
| 1345 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1346 | SourceLocation LParenLoc, |
| 1347 | SourceLocation EndLoc) { |
| 1348 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
| 1349 | EndLoc); |
| 1350 | } |
| 1351 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1352 | /// \brief Build a new OpenMP 'num_threads' clause. |
| 1353 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1354 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1355 | /// Subclasses may override this routine to provide different behavior. |
| 1356 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
| 1357 | SourceLocation StartLoc, |
| 1358 | SourceLocation LParenLoc, |
| 1359 | SourceLocation EndLoc) { |
| 1360 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
| 1361 | LParenLoc, EndLoc); |
| 1362 | } |
| 1363 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1364 | /// \brief Build a new OpenMP 'safelen' clause. |
| 1365 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1366 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1367 | /// Subclasses may override this routine to provide different behavior. |
| 1368 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1369 | SourceLocation LParenLoc, |
| 1370 | SourceLocation EndLoc) { |
| 1371 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1372 | } |
| 1373 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1374 | /// \brief Build a new OpenMP 'collapse' clause. |
| 1375 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1376 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1377 | /// Subclasses may override this routine to provide different behavior. |
| 1378 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1379 | SourceLocation LParenLoc, |
| 1380 | SourceLocation EndLoc) { |
| 1381 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
| 1382 | EndLoc); |
| 1383 | } |
| 1384 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1385 | /// \brief Build a new OpenMP 'default' clause. |
| 1386 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1387 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1388 | /// Subclasses may override this routine to provide different behavior. |
| 1389 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1390 | SourceLocation KindKwLoc, |
| 1391 | SourceLocation StartLoc, |
| 1392 | SourceLocation LParenLoc, |
| 1393 | SourceLocation EndLoc) { |
| 1394 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1395 | StartLoc, LParenLoc, EndLoc); |
| 1396 | } |
| 1397 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1398 | /// \brief Build a new OpenMP 'proc_bind' clause. |
| 1399 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1400 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1401 | /// Subclasses may override this routine to provide different behavior. |
| 1402 | OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 1403 | SourceLocation KindKwLoc, |
| 1404 | SourceLocation StartLoc, |
| 1405 | SourceLocation LParenLoc, |
| 1406 | SourceLocation EndLoc) { |
| 1407 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
| 1408 | StartLoc, LParenLoc, EndLoc); |
| 1409 | } |
| 1410 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1411 | /// \brief Build a new OpenMP 'schedule' clause. |
| 1412 | /// |
| 1413 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1414 | /// Subclasses may override this routine to provide different behavior. |
| 1415 | OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind, |
| 1416 | Expr *ChunkSize, |
| 1417 | SourceLocation StartLoc, |
| 1418 | SourceLocation LParenLoc, |
| 1419 | SourceLocation KindLoc, |
| 1420 | SourceLocation CommaLoc, |
| 1421 | SourceLocation EndLoc) { |
| 1422 | return getSema().ActOnOpenMPScheduleClause( |
| 1423 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 1424 | } |
| 1425 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1426 | /// \brief Build a new OpenMP 'private' clause. |
| 1427 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1428 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1429 | /// Subclasses may override this routine to provide different behavior. |
| 1430 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1431 | SourceLocation StartLoc, |
| 1432 | SourceLocation LParenLoc, |
| 1433 | SourceLocation EndLoc) { |
| 1434 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1435 | EndLoc); |
| 1436 | } |
| 1437 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1438 | /// \brief Build a new OpenMP 'firstprivate' clause. |
| 1439 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1440 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1441 | /// Subclasses may override this routine to provide different behavior. |
| 1442 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1443 | SourceLocation StartLoc, |
| 1444 | SourceLocation LParenLoc, |
| 1445 | SourceLocation EndLoc) { |
| 1446 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1447 | EndLoc); |
| 1448 | } |
| 1449 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1450 | /// \brief Build a new OpenMP 'lastprivate' clause. |
| 1451 | /// |
| 1452 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1453 | /// Subclasses may override this routine to provide different behavior. |
| 1454 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1455 | SourceLocation StartLoc, |
| 1456 | SourceLocation LParenLoc, |
| 1457 | SourceLocation EndLoc) { |
| 1458 | return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, |
| 1459 | EndLoc); |
| 1460 | } |
| 1461 | |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1462 | /// \brief Build a new OpenMP 'shared' clause. |
| 1463 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1464 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1465 | /// Subclasses may override this routine to provide different behavior. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1466 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1467 | SourceLocation StartLoc, |
| 1468 | SourceLocation LParenLoc, |
| 1469 | SourceLocation EndLoc) { |
| 1470 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1471 | EndLoc); |
| 1472 | } |
| 1473 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1474 | /// \brief Build a new OpenMP 'reduction' clause. |
| 1475 | /// |
| 1476 | /// By default, performs semantic analysis to build the new statement. |
| 1477 | /// Subclasses may override this routine to provide different behavior. |
| 1478 | OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList, |
| 1479 | SourceLocation StartLoc, |
| 1480 | SourceLocation LParenLoc, |
| 1481 | SourceLocation ColonLoc, |
| 1482 | SourceLocation EndLoc, |
| 1483 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1484 | const DeclarationNameInfo &ReductionId) { |
| 1485 | return getSema().ActOnOpenMPReductionClause( |
| 1486 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1487 | ReductionId); |
| 1488 | } |
| 1489 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1490 | /// \brief Build a new OpenMP 'linear' clause. |
| 1491 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1492 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1493 | /// Subclasses may override this routine to provide different behavior. |
| 1494 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1495 | SourceLocation StartLoc, |
| 1496 | SourceLocation LParenLoc, |
| 1497 | SourceLocation ColonLoc, |
| 1498 | SourceLocation EndLoc) { |
| 1499 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
| 1500 | ColonLoc, EndLoc); |
| 1501 | } |
| 1502 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1503 | /// \brief Build a new OpenMP 'aligned' clause. |
| 1504 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1505 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1506 | /// Subclasses may override this routine to provide different behavior. |
| 1507 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 1508 | SourceLocation StartLoc, |
| 1509 | SourceLocation LParenLoc, |
| 1510 | SourceLocation ColonLoc, |
| 1511 | SourceLocation EndLoc) { |
| 1512 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
| 1513 | LParenLoc, ColonLoc, EndLoc); |
| 1514 | } |
| 1515 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1516 | /// \brief Build a new OpenMP 'copyin' clause. |
| 1517 | /// |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1518 | /// By default, performs semantic analysis to build the new OpenMP clause. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1519 | /// Subclasses may override this routine to provide different behavior. |
| 1520 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1521 | SourceLocation StartLoc, |
| 1522 | SourceLocation LParenLoc, |
| 1523 | SourceLocation EndLoc) { |
| 1524 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
| 1525 | EndLoc); |
| 1526 | } |
| 1527 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1528 | /// \brief Build a new OpenMP 'copyprivate' clause. |
| 1529 | /// |
| 1530 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1531 | /// Subclasses may override this routine to provide different behavior. |
| 1532 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 1533 | SourceLocation StartLoc, |
| 1534 | SourceLocation LParenLoc, |
| 1535 | SourceLocation EndLoc) { |
| 1536 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
| 1537 | EndLoc); |
| 1538 | } |
| 1539 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1540 | /// \brief Build a new OpenMP 'flush' pseudo clause. |
| 1541 | /// |
| 1542 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1543 | /// Subclasses may override this routine to provide different behavior. |
| 1544 | OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
| 1545 | SourceLocation StartLoc, |
| 1546 | SourceLocation LParenLoc, |
| 1547 | SourceLocation EndLoc) { |
| 1548 | return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, |
| 1549 | EndLoc); |
| 1550 | } |
| 1551 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1552 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1553 | /// |
| 1554 | /// By default, performs semantic analysis to build the new statement. |
| 1555 | /// Subclasses may override this routine to provide different behavior. |
| 1556 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1557 | Expr *object) { |
| 1558 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1559 | } |
| 1560 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1561 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1562 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1563 | /// By default, performs semantic analysis to build the new statement. |
| 1564 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1565 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1566 | Expr *Object, Stmt *Body) { |
| 1567 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1568 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1569 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1570 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1571 | /// |
| 1572 | /// By default, performs semantic analysis to build the new statement. |
| 1573 | /// Subclasses may override this routine to provide different behavior. |
| 1574 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1575 | Stmt *Body) { |
| 1576 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1577 | } |
John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1578 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1579 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1580 | /// |
| 1581 | /// By default, performs semantic analysis to build the new statement. |
| 1582 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1583 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1584 | Stmt *Element, |
| 1585 | Expr *Collection, |
| 1586 | SourceLocation RParenLoc, |
| 1587 | Stmt *Body) { |
Sam Panzer | 2c4ca0f | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1588 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1589 | Element, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1590 | Collection, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1591 | RParenLoc); |
| 1592 | if (ForEachStmt.isInvalid()) |
| 1593 | return StmtError(); |
| 1594 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1595 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1596 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1597 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1598 | /// \brief Build a new C++ exception declaration. |
| 1599 | /// |
| 1600 | /// By default, performs semantic analysis to build the new decaration. |
| 1601 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1602 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1603 | TypeSourceInfo *Declarator, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1604 | SourceLocation StartLoc, |
| 1605 | SourceLocation IdLoc, |
| 1606 | IdentifierInfo *Id) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1607 | VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1608 | StartLoc, IdLoc, Id); |
| 1609 | if (Var) |
| 1610 | getSema().CurContext->addDecl(Var); |
| 1611 | return Var; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | /// \brief Build a new C++ catch statement. |
| 1615 | /// |
| 1616 | /// By default, performs semantic analysis to build the new statement. |
| 1617 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1618 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1619 | VarDecl *ExceptionDecl, |
| 1620 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1621 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1622 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1623 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1624 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1625 | /// \brief Build a new C++ try statement. |
| 1626 | /// |
| 1627 | /// By default, performs semantic analysis to build the new statement. |
| 1628 | /// Subclasses may override this routine to provide different behavior. |
Robert Wilhelm | cafda82 | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 1629 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 1630 | ArrayRef<Stmt *> Handlers) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1631 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1632 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1634 | /// \brief Build a new C++0x range-based for statement. |
| 1635 | /// |
| 1636 | /// By default, performs semantic analysis to build the new statement. |
| 1637 | /// Subclasses may override this routine to provide different behavior. |
| 1638 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1639 | SourceLocation ColonLoc, |
| 1640 | Stmt *Range, Stmt *BeginEnd, |
| 1641 | Expr *Cond, Expr *Inc, |
| 1642 | Stmt *LoopVar, |
| 1643 | SourceLocation RParenLoc) { |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1644 | // If we've just learned that the range is actually an Objective-C |
| 1645 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1646 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1647 | if (RangeStmt->isSingleDecl()) { |
| 1648 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1649 | if (RangeVar->isInvalidDecl()) |
| 1650 | return StmtError(); |
| 1651 | |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1652 | Expr *RangeExpr = RangeVar->getInit(); |
| 1653 | if (!RangeExpr->isTypeDependent() && |
| 1654 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1655 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1656 | RParenLoc); |
| 1657 | } |
| 1658 | } |
| 1659 | } |
| 1660 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1661 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | a05b3b5 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1662 | Cond, Inc, LoopVar, RParenLoc, |
| 1663 | Sema::BFRK_Rebuild); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1664 | } |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1665 | |
| 1666 | /// \brief Build a new C++0x range-based for statement. |
| 1667 | /// |
| 1668 | /// By default, performs semantic analysis to build the new statement. |
| 1669 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1670 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1671 | bool IsIfExists, |
| 1672 | NestedNameSpecifierLoc QualifierLoc, |
| 1673 | DeclarationNameInfo NameInfo, |
| 1674 | Stmt *Nested) { |
| 1675 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1676 | QualifierLoc, NameInfo, Nested); |
| 1677 | } |
| 1678 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1679 | /// \brief Attach body to a C++0x range-based for statement. |
| 1680 | /// |
| 1681 | /// By default, performs semantic analysis to finish the new statement. |
| 1682 | /// Subclasses may override this routine to provide different behavior. |
| 1683 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1684 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1685 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1686 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1687 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1688 | Stmt *TryBlock, Stmt *Handler) { |
| 1689 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1692 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1693 | Stmt *Block) { |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1694 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1697 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| 1698 | return getSema().ActOnSEHFinallyBlock(Loc, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 1701 | /// \brief Build a new predefined expression. |
| 1702 | /// |
| 1703 | /// By default, performs semantic analysis to build the new expression. |
| 1704 | /// Subclasses may override this routine to provide different behavior. |
| 1705 | ExprResult RebuildPredefinedExpr(SourceLocation Loc, |
| 1706 | PredefinedExpr::IdentType IT) { |
| 1707 | return getSema().BuildPredefinedExpr(Loc, IT); |
| 1708 | } |
| 1709 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | /// \brief Build a new expression that references a declaration. |
| 1711 | /// |
| 1712 | /// By default, performs semantic analysis to build the new expression. |
| 1713 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1714 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1715 | LookupResult &R, |
| 1716 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1717 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1718 | } |
| 1719 | |
| 1720 | |
| 1721 | /// \brief Build a new expression that references a declaration. |
| 1722 | /// |
| 1723 | /// By default, performs semantic analysis to build the new expression. |
| 1724 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1725 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1726 | ValueDecl *VD, |
| 1727 | const DeclarationNameInfo &NameInfo, |
| 1728 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1729 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1730 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1731 | |
| 1732 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1733 | |
| 1734 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1735 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1737 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1738 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1739 | /// By default, performs semantic analysis to build the new expression. |
| 1740 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1741 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1743 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1746 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1747 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1748 | /// By default, performs semantic analysis to build the new expression. |
| 1749 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1750 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1751 | SourceLocation OperatorLoc, |
| 1752 | bool isArrow, |
| 1753 | CXXScopeSpec &SS, |
| 1754 | TypeSourceInfo *ScopeType, |
| 1755 | SourceLocation CCLoc, |
| 1756 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1757 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1759 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1761 | /// By default, performs semantic analysis to build the new expression. |
| 1762 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1763 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1764 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1765 | Expr *SubExpr) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1766 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1769 | /// \brief Build a new builtin offsetof expression. |
| 1770 | /// |
| 1771 | /// By default, performs semantic analysis to build the new expression. |
| 1772 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1773 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1774 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1775 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1776 | unsigned NumComponents, |
| 1777 | SourceLocation RParenLoc) { |
| 1778 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1779 | NumComponents, RParenLoc); |
| 1780 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1781 | |
| 1782 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1783 | /// type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1785 | /// By default, performs semantic analysis to build the new expression. |
| 1786 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1787 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1788 | SourceLocation OpLoc, |
| 1789 | UnaryExprOrTypeTrait ExprKind, |
| 1790 | SourceRange R) { |
| 1791 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1794 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1795 | /// expression argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | /// By default, performs semantic analysis to build the new expression. |
| 1798 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1799 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1800 | UnaryExprOrTypeTrait ExprKind, |
| 1801 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1802 | ExprResult Result |
Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1803 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1804 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1805 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1806 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1807 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1808 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1809 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1810 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1811 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1812 | /// By default, performs semantic analysis to build the new expression. |
| 1813 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1814 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1815 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1816 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1817 | SourceLocation RBracketLoc) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1818 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1819 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1820 | RBracketLoc); |
| 1821 | } |
| 1822 | |
| 1823 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1824 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1825 | /// By default, performs semantic analysis to build the new expression. |
| 1826 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1827 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1828 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1829 | SourceLocation RParenLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1830 | Expr *ExecConfig = nullptr) { |
| 1831 | return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1832 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1836 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1837 | /// By default, performs semantic analysis to build the new expression. |
| 1838 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1839 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1840 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1841 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1842 | SourceLocation TemplateKWLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1843 | const DeclarationNameInfo &MemberNameInfo, |
| 1844 | ValueDecl *Member, |
| 1845 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1846 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1847 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1848 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1849 | isArrow); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1850 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1851 | // We have a reference to an unnamed field. This is always the |
| 1852 | // base of an anonymous struct/union member access, i.e. the |
| 1853 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1854 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1855 | assert(Member->getType()->isRecordType() && |
| 1856 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1857 | |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1858 | BaseResult = |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1859 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1860 | QualifierLoc.getNestedNameSpecifier(), |
| 1861 | FoundDecl, Member); |
| 1862 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1863 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1864 | Base = BaseResult.get(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1865 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1866 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1867 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1868 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1869 | cast<FieldDecl>(Member)->getType(), |
| 1870 | VK, OK_Ordinary); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1871 | return ME; |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1872 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1873 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1874 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1875 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1876 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1877 | Base = BaseResult.get(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1878 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1879 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1880 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1881 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1882 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1883 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1884 | R.resolveKind(); |
| 1885 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1886 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1887 | SS, TemplateKWLoc, |
| 1888 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1889 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1890 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1891 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1892 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1893 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1894 | /// By default, performs semantic analysis to build the new expression. |
| 1895 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1896 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1897 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1898 | Expr *LHS, Expr *RHS) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1899 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1903 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1904 | /// By default, performs semantic analysis to build the new expression. |
| 1905 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1906 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1907 | SourceLocation QuestionLoc, |
| 1908 | Expr *LHS, |
| 1909 | SourceLocation ColonLoc, |
| 1910 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1911 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1912 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1913 | } |
| 1914 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1915 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1917 | /// By default, performs semantic analysis to build the new expression. |
| 1918 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1919 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1920 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1921 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1922 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1923 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1924 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1925 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1926 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1927 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1928 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1929 | /// By default, performs semantic analysis to build the new expression. |
| 1930 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1931 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1932 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1933 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1934 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1935 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1936 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1937 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1938 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1939 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1940 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1941 | /// By default, performs semantic analysis to build the new expression. |
| 1942 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1943 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1944 | SourceLocation OpLoc, |
| 1945 | SourceLocation AccessorLoc, |
| 1946 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1947 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1948 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1949 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1950 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1951 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1952 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1953 | /*FirstQualifierInScope*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1954 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1955 | /* TemplateArgs */ nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1956 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1957 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1958 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1959 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1960 | /// By default, performs semantic analysis to build the new expression. |
| 1961 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1962 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1963 | MultiExprArg Inits, |
| 1964 | SourceLocation RBraceLoc, |
| 1965 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1966 | ExprResult Result |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1967 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1968 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1969 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1970 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1971 | // Patch in the result type we were given, which may have been computed |
| 1972 | // when the initial InitListExpr was built. |
| 1973 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1974 | ILE->setType(ResultTy); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1975 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1976 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1977 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1978 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1980 | /// By default, performs semantic analysis to build the new expression. |
| 1981 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1982 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1983 | MultiExprArg ArrayExprs, |
| 1984 | SourceLocation EqualOrColonLoc, |
| 1985 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1986 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1987 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1988 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1989 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1990 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1991 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1993 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1994 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1995 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1996 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1998 | /// By default, builds the implicit value initialization without performing |
| 1999 | /// any semantic analysis. Subclasses may override this routine to provide |
| 2000 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2001 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2002 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2003 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2004 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2005 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2006 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2007 | /// By default, performs semantic analysis to build the new expression. |
| 2008 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2009 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2010 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2011 | SourceLocation RParenLoc) { |
| 2012 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2013 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2014 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2019 | /// By default, performs semantic analysis to build the new expression. |
| 2020 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2021 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 2022 | MultiExprArg SubExprs, |
| 2023 | SourceLocation RParenLoc) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2024 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2025 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2026 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2027 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2028 | /// |
| 2029 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2030 | /// rather than attempting to map the label statement itself. |
| 2031 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2032 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 2033 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2034 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2037 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2038 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2039 | /// By default, performs semantic analysis to build the new expression. |
| 2040 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2041 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2042 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2043 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2044 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2045 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2047 | /// \brief Build a new __builtin_choose_expr expression. |
| 2048 | /// |
| 2049 | /// By default, performs semantic analysis to build the new expression. |
| 2050 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2051 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2052 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2053 | SourceLocation RParenLoc) { |
| 2054 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2055 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2056 | RParenLoc); |
| 2057 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2058 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2059 | /// \brief Build a new generic selection expression. |
| 2060 | /// |
| 2061 | /// By default, performs semantic analysis to build the new expression. |
| 2062 | /// Subclasses may override this routine to provide different behavior. |
| 2063 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2064 | SourceLocation DefaultLoc, |
| 2065 | SourceLocation RParenLoc, |
| 2066 | Expr *ControllingExpr, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2067 | ArrayRef<TypeSourceInfo *> Types, |
| 2068 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2069 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2070 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2073 | /// \brief Build a new overloaded operator call expression. |
| 2074 | /// |
| 2075 | /// By default, performs semantic analysis to build the new expression. |
| 2076 | /// The semantic analysis provides the behavior of template instantiation, |
| 2077 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2078 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2079 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2080 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2081 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2082 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2083 | Expr *Callee, |
| 2084 | Expr *First, |
| 2085 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2086 | |
| 2087 | /// \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] | 2088 | /// reinterpret_cast. |
| 2089 | /// |
| 2090 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2091 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2092 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2093 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2094 | Stmt::StmtClass Class, |
| 2095 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2096 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2097 | SourceLocation RAngleLoc, |
| 2098 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2099 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2100 | SourceLocation RParenLoc) { |
| 2101 | switch (Class) { |
| 2102 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2103 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2104 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2105 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2106 | |
| 2107 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2108 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2109 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2110 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2112 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2113 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2114 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2115 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2116 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2117 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2118 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2119 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2120 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2121 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2122 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2123 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2124 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2125 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2126 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2127 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2128 | /// \brief Build a new C++ static_cast expression. |
| 2129 | /// |
| 2130 | /// By default, performs semantic analysis to build the new expression. |
| 2131 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2132 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2133 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2134 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2135 | SourceLocation RAngleLoc, |
| 2136 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2137 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2138 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2139 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2140 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2141 | SourceRange(LAngleLoc, RAngleLoc), |
| 2142 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | /// \brief Build a new C++ dynamic_cast expression. |
| 2146 | /// |
| 2147 | /// By default, performs semantic analysis to build the new expression. |
| 2148 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2149 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2150 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2151 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2152 | SourceLocation RAngleLoc, |
| 2153 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2154 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2155 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2156 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2157 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2158 | SourceRange(LAngleLoc, RAngleLoc), |
| 2159 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | /// \brief Build a new C++ reinterpret_cast expression. |
| 2163 | /// |
| 2164 | /// By default, performs semantic analysis to build the new expression. |
| 2165 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2166 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2167 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2168 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2169 | SourceLocation RAngleLoc, |
| 2170 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2171 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2172 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2173 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2174 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2175 | SourceRange(LAngleLoc, RAngleLoc), |
| 2176 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | /// \brief Build a new C++ const_cast expression. |
| 2180 | /// |
| 2181 | /// By default, performs semantic analysis to build the new expression. |
| 2182 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2183 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2184 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2185 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2186 | SourceLocation RAngleLoc, |
| 2187 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2188 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2189 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2190 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2191 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2192 | SourceRange(LAngleLoc, RAngleLoc), |
| 2193 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2194 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2195 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2196 | /// \brief Build a new C++ functional-style cast expression. |
| 2197 | /// |
| 2198 | /// By default, performs semantic analysis to build the new expression. |
| 2199 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2200 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2201 | SourceLocation LParenLoc, |
| 2202 | Expr *Sub, |
| 2203 | SourceLocation RParenLoc) { |
| 2204 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2205 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2206 | RParenLoc); |
| 2207 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2208 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2209 | /// \brief Build a new C++ typeid(type) expression. |
| 2210 | /// |
| 2211 | /// By default, performs semantic analysis to build the new expression. |
| 2212 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2213 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2214 | SourceLocation TypeidLoc, |
| 2215 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2216 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2217 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2218 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2219 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2220 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2222 | /// \brief Build a new C++ typeid(expr) expression. |
| 2223 | /// |
| 2224 | /// By default, performs semantic analysis to build the new expression. |
| 2225 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2226 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2227 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2228 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2229 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2230 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2231 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2234 | /// \brief Build a new C++ __uuidof(type) expression. |
| 2235 | /// |
| 2236 | /// By default, performs semantic analysis to build the new expression. |
| 2237 | /// Subclasses may override this routine to provide different behavior. |
| 2238 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2239 | SourceLocation TypeidLoc, |
| 2240 | TypeSourceInfo *Operand, |
| 2241 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2242 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2243 | RParenLoc); |
| 2244 | } |
| 2245 | |
| 2246 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2247 | /// |
| 2248 | /// By default, performs semantic analysis to build the new expression. |
| 2249 | /// Subclasses may override this routine to provide different behavior. |
| 2250 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2251 | SourceLocation TypeidLoc, |
| 2252 | Expr *Operand, |
| 2253 | SourceLocation RParenLoc) { |
| 2254 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2255 | RParenLoc); |
| 2256 | } |
| 2257 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2258 | /// \brief Build a new C++ "this" expression. |
| 2259 | /// |
| 2260 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2261 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2262 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2263 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2264 | QualType ThisType, |
| 2265 | bool isImplicit) { |
Eli Friedman | 20139d3 | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2266 | getSema().CheckCXXThisCapture(ThisLoc); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2267 | return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | /// \brief Build a new C++ throw expression. |
| 2271 | /// |
| 2272 | /// By default, performs semantic analysis to build the new expression. |
| 2273 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2274 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2275 | bool IsThrownVariableInScope) { |
| 2276 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | /// \brief Build a new C++ default-argument expression. |
| 2280 | /// |
| 2281 | /// By default, builds a new default-argument expression, which does not |
| 2282 | /// require any semantic analysis. Subclasses may override this routine to |
| 2283 | /// provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2284 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2285 | ParmVarDecl *Param) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2286 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2289 | /// \brief Build a new C++11 default-initialization expression. |
| 2290 | /// |
| 2291 | /// By default, builds a new default field initialization expression, which |
| 2292 | /// does not require any semantic analysis. Subclasses may override this |
| 2293 | /// routine to provide different behavior. |
| 2294 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2295 | FieldDecl *Field) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2296 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field); |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2297 | } |
| 2298 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2299 | /// \brief Build a new C++ zero-initialization expression. |
| 2300 | /// |
| 2301 | /// By default, performs semantic analysis to build the new expression. |
| 2302 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2303 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2304 | SourceLocation LParenLoc, |
| 2305 | SourceLocation RParenLoc) { |
| 2306 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2307 | None, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2309 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2310 | /// \brief Build a new C++ "new" expression. |
| 2311 | /// |
| 2312 | /// By default, performs semantic analysis to build the new expression. |
| 2313 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2314 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2315 | bool UseGlobal, |
| 2316 | SourceLocation PlacementLParen, |
| 2317 | MultiExprArg PlacementArgs, |
| 2318 | SourceLocation PlacementRParen, |
| 2319 | SourceRange TypeIdParens, |
| 2320 | QualType AllocatedType, |
| 2321 | TypeSourceInfo *AllocatedTypeInfo, |
| 2322 | Expr *ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2323 | SourceRange DirectInitRange, |
| 2324 | Expr *Initializer) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2325 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2326 | PlacementLParen, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2327 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2328 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2329 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2330 | AllocatedType, |
| 2331 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2332 | ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2333 | DirectInitRange, |
| 2334 | Initializer); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2335 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2336 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2337 | /// \brief Build a new C++ "delete" expression. |
| 2338 | /// |
| 2339 | /// By default, performs semantic analysis to build the new expression. |
| 2340 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2341 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2342 | bool IsGlobalDelete, |
| 2343 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2344 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2345 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2346 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2347 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2348 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2349 | /// \brief Build a new type trait expression. |
| 2350 | /// |
| 2351 | /// By default, performs semantic analysis to build the new expression. |
| 2352 | /// Subclasses may override this routine to provide different behavior. |
| 2353 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2354 | SourceLocation StartLoc, |
| 2355 | ArrayRef<TypeSourceInfo *> Args, |
| 2356 | SourceLocation RParenLoc) { |
| 2357 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2358 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2359 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2360 | /// \brief Build a new array type trait expression. |
| 2361 | /// |
| 2362 | /// By default, performs semantic analysis to build the new expression. |
| 2363 | /// Subclasses may override this routine to provide different behavior. |
| 2364 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2365 | SourceLocation StartLoc, |
| 2366 | TypeSourceInfo *TSInfo, |
| 2367 | Expr *DimExpr, |
| 2368 | SourceLocation RParenLoc) { |
| 2369 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2370 | } |
| 2371 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2372 | /// \brief Build a new expression trait expression. |
| 2373 | /// |
| 2374 | /// By default, performs semantic analysis to build the new expression. |
| 2375 | /// Subclasses may override this routine to provide different behavior. |
| 2376 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2377 | SourceLocation StartLoc, |
| 2378 | Expr *Queried, |
| 2379 | SourceLocation RParenLoc) { |
| 2380 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2381 | } |
| 2382 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2383 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2384 | /// expression. |
| 2385 | /// |
| 2386 | /// By default, performs semantic analysis to build the new expression. |
| 2387 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2388 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2389 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2390 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2391 | const DeclarationNameInfo &NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2392 | const TemplateArgumentListInfo *TemplateArgs, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2393 | bool IsAddressOfOperand, |
| 2394 | TypeSourceInfo **RecoveryTSI) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2395 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2396 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2397 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2398 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2399 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2400 | TemplateArgs); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2401 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2402 | return getSema().BuildQualifiedDeclarationNameExpr( |
| 2403 | SS, NameInfo, IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | /// \brief Build a new template-id expression. |
| 2407 | /// |
| 2408 | /// By default, performs semantic analysis to build the new expression. |
| 2409 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2410 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2411 | SourceLocation TemplateKWLoc, |
| 2412 | LookupResult &R, |
| 2413 | bool RequiresADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2414 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2415 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2416 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | /// \brief Build a new object-construction expression. |
| 2420 | /// |
| 2421 | /// By default, performs semantic analysis to build the new expression. |
| 2422 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2423 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2424 | SourceLocation Loc, |
| 2425 | CXXConstructorDecl *Constructor, |
| 2426 | bool IsElidable, |
| 2427 | MultiExprArg Args, |
| 2428 | bool HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2429 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2430 | bool StdInitListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2431 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2432 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2433 | SourceRange ParenRange) { |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2434 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2435 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2436 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2437 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2438 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2439 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2440 | ConvertedArgs, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2441 | HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2442 | ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2443 | StdInitListInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2444 | RequiresZeroInit, ConstructKind, |
| 2445 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | /// \brief Build a new object-construction expression. |
| 2449 | /// |
| 2450 | /// By default, performs semantic analysis to build the new expression. |
| 2451 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2452 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2453 | SourceLocation LParenLoc, |
| 2454 | MultiExprArg Args, |
| 2455 | SourceLocation RParenLoc) { |
| 2456 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2457 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2458 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2459 | RParenLoc); |
| 2460 | } |
| 2461 | |
| 2462 | /// \brief Build a new object-construction expression. |
| 2463 | /// |
| 2464 | /// By default, performs semantic analysis to build the new expression. |
| 2465 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2466 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2467 | SourceLocation LParenLoc, |
| 2468 | MultiExprArg Args, |
| 2469 | SourceLocation RParenLoc) { |
| 2470 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2471 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2472 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2473 | RParenLoc); |
| 2474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2475 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2476 | /// \brief Build a new member reference expression. |
| 2477 | /// |
| 2478 | /// By default, performs semantic analysis to build the new expression. |
| 2479 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2480 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2481 | QualType BaseType, |
| 2482 | bool IsArrow, |
| 2483 | SourceLocation OperatorLoc, |
| 2484 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2485 | SourceLocation TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2486 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2487 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2488 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2489 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2490 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2491 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2492 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2493 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2494 | SS, TemplateKWLoc, |
| 2495 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2496 | MemberNameInfo, |
| 2497 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2500 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2501 | /// |
| 2502 | /// By default, performs semantic analysis to build the new expression. |
| 2503 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2504 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2505 | SourceLocation OperatorLoc, |
| 2506 | bool IsArrow, |
| 2507 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2508 | SourceLocation TemplateKWLoc, |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2509 | NamedDecl *FirstQualifierInScope, |
| 2510 | LookupResult &R, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2511 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2512 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2513 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2514 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2515 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2516 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2517 | SS, TemplateKWLoc, |
| 2518 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2519 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2520 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2521 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2522 | /// \brief Build a new noexcept expression. |
| 2523 | /// |
| 2524 | /// By default, performs semantic analysis to build the new expression. |
| 2525 | /// Subclasses may override this routine to provide different behavior. |
| 2526 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2527 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2528 | } |
| 2529 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2530 | /// \brief Build a new expression to compute the length of a parameter pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2531 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2532 | SourceLocation PackLoc, |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2533 | SourceLocation RParenLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2534 | Optional<unsigned> Length) { |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2535 | if (Length) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2536 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2537 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2538 | RParenLoc, *Length); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2539 | |
| 2540 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2541 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2542 | RParenLoc); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2543 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2544 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2545 | /// \brief Build a new Objective-C boxed expression. |
| 2546 | /// |
| 2547 | /// By default, performs semantic analysis to build the new expression. |
| 2548 | /// Subclasses may override this routine to provide different behavior. |
| 2549 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2550 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2551 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2552 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2553 | /// \brief Build a new Objective-C array literal. |
| 2554 | /// |
| 2555 | /// By default, performs semantic analysis to build the new expression. |
| 2556 | /// Subclasses may override this routine to provide different behavior. |
| 2557 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2558 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2559 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2560 | MultiExprArg(Elements, NumElements)); |
| 2561 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2562 | |
| 2563 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2564 | Expr *Base, Expr *Key, |
| 2565 | ObjCMethodDecl *getterMethod, |
| 2566 | ObjCMethodDecl *setterMethod) { |
| 2567 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2568 | getterMethod, setterMethod); |
| 2569 | } |
| 2570 | |
| 2571 | /// \brief Build a new Objective-C dictionary literal. |
| 2572 | /// |
| 2573 | /// By default, performs semantic analysis to build the new expression. |
| 2574 | /// Subclasses may override this routine to provide different behavior. |
| 2575 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2576 | ObjCDictionaryElement *Elements, |
| 2577 | unsigned NumElements) { |
| 2578 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2579 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2580 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2581 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2582 | /// |
| 2583 | /// By default, performs semantic analysis to build the new expression. |
| 2584 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2585 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2586 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2587 | SourceLocation RParenLoc) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2588 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2589 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2590 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2591 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2592 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2593 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2594 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2595 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2596 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2597 | MultiExprArg Args, |
| 2598 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2599 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2600 | ReceiverTypeInfo->getType(), |
| 2601 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2602 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2603 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2607 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2608 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2609 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2610 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2611 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2612 | MultiExprArg Args, |
| 2613 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2614 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2615 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2616 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2617 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2618 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2621 | /// \brief Build a new Objective-C ivar reference expression. |
| 2622 | /// |
| 2623 | /// By default, performs semantic analysis to build the new expression. |
| 2624 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2625 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2626 | SourceLocation IvarLoc, |
| 2627 | bool IsArrow, bool IsFreeIvar) { |
| 2628 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2629 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2630 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| 2631 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2632 | /*FIXME:*/IvarLoc, IsArrow, |
| 2633 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2634 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2635 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2636 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2637 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2638 | |
| 2639 | /// \brief Build a new Objective-C property reference expression. |
| 2640 | /// |
| 2641 | /// By default, performs semantic analysis to build the new expression. |
| 2642 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2643 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2644 | ObjCPropertyDecl *Property, |
| 2645 | SourceLocation PropertyLoc) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2646 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2647 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 2648 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 2649 | /*FIXME:*/PropertyLoc, |
| 2650 | /*IsArrow=*/false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2651 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2652 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2653 | NameInfo, |
| 2654 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2655 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2656 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2657 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2658 | /// |
| 2659 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2660 | /// Subclasses may override this routine to provide different behavior. |
| 2661 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2662 | ObjCMethodDecl *Getter, |
| 2663 | ObjCMethodDecl *Setter, |
| 2664 | SourceLocation PropertyLoc) { |
| 2665 | // Since these expressions can only be value-dependent, we do not |
| 2666 | // need to perform semantic analysis again. |
| 2667 | return Owned( |
| 2668 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2669 | VK_LValue, OK_ObjCProperty, |
| 2670 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2673 | /// \brief Build a new Objective-C "isa" expression. |
| 2674 | /// |
| 2675 | /// By default, performs semantic analysis to build the new expression. |
| 2676 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2677 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2678 | SourceLocation OpLoc, bool IsArrow) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2679 | CXXScopeSpec SS; |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2680 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 2681 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2682 | OpLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2683 | SS, SourceLocation(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2684 | /*FirstQualifierInScope=*/nullptr, |
Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 2685 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2686 | /*TemplateArgs=*/nullptr); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2687 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2688 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2689 | /// \brief Build a new shuffle vector expression. |
| 2690 | /// |
| 2691 | /// By default, performs semantic analysis to build the new expression. |
| 2692 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2693 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2694 | MultiExprArg SubExprs, |
| 2695 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2696 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2697 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2698 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2699 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2700 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2701 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2702 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2703 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2704 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2705 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2706 | SemaRef.Context.BuiltinFnTy, |
| 2707 | VK_RValue, BuiltinLoc); |
| 2708 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2709 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2710 | CK_BuiltinFnToFnPtr).get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2711 | |
| 2712 | // Build the CallExpr |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2713 | ExprResult TheCall = new (SemaRef.Context) CallExpr( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2714 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2715 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2716 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2717 | // Type-check the __builtin_shufflevector expression. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2718 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2719 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2720 | |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 2721 | /// \brief Build a new convert vector expression. |
| 2722 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 2723 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 2724 | SourceLocation RParenLoc) { |
| 2725 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 2726 | BuiltinLoc, RParenLoc); |
| 2727 | } |
| 2728 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2729 | /// \brief Build a new template argument pack expansion. |
| 2730 | /// |
| 2731 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2732 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2733 | /// different behavior. |
| 2734 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2735 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2736 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2737 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2738 | case TemplateArgument::Expression: { |
| 2739 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2740 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2741 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2742 | if (Result.isInvalid()) |
| 2743 | return TemplateArgumentLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2744 | |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2745 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2746 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2747 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2748 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2749 | return TemplateArgumentLoc(TemplateArgument( |
| 2750 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2751 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2752 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2753 | Pattern.getTemplateNameLoc(), |
| 2754 | EllipsisLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2755 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2756 | case TemplateArgument::Null: |
| 2757 | case TemplateArgument::Integral: |
| 2758 | case TemplateArgument::Declaration: |
| 2759 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2760 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2761 | case TemplateArgument::NullPtr: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2762 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2763 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2764 | case TemplateArgument::Type: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2765 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2766 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2767 | EllipsisLoc, |
| 2768 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2769 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2770 | Expansion); |
| 2771 | break; |
| 2772 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2773 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2774 | return TemplateArgumentLoc(); |
| 2775 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2776 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2777 | /// \brief Build a new expression pack expansion. |
| 2778 | /// |
| 2779 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2780 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2781 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2782 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2783 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2784 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2785 | } |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2786 | |
| 2787 | /// \brief Build a new atomic operation expression. |
| 2788 | /// |
| 2789 | /// By default, performs semantic analysis to build the new expression. |
| 2790 | /// Subclasses may override this routine to provide different behavior. |
| 2791 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2792 | MultiExprArg SubExprs, |
| 2793 | QualType RetTy, |
| 2794 | AtomicExpr::AtomicOp Op, |
| 2795 | SourceLocation RParenLoc) { |
| 2796 | // Just create the expression; there is not any interesting semantic |
| 2797 | // analysis here because we can't actually build an AtomicExpr until |
| 2798 | // we are sure it is semantically sound. |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2799 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2800 | RParenLoc); |
| 2801 | } |
| 2802 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2803 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2804 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2805 | QualType ObjectType, |
| 2806 | NamedDecl *FirstQualifierInScope, |
| 2807 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2808 | |
| 2809 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2810 | QualType ObjectType, |
| 2811 | NamedDecl *FirstQualifierInScope, |
| 2812 | CXXScopeSpec &SS); |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 2813 | |
| 2814 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 2815 | NamedDecl *FirstQualifierInScope, |
| 2816 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2817 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2818 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2819 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2820 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2821 | if (!S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2822 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2823 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2824 | switch (S->getStmtClass()) { |
| 2825 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2826 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2827 | // Transform individual statement nodes |
| 2828 | #define STMT(Node, Parent) \ |
| 2829 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2830 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2831 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2832 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2833 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2834 | // Transform expressions by calling TransformExpr. |
| 2835 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2836 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2837 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2838 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2839 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2840 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2841 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2842 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2843 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2844 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2845 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2846 | } |
| 2847 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2848 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2849 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2850 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2851 | template<typename Derived> |
| 2852 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2853 | if (!S) |
| 2854 | return S; |
| 2855 | |
| 2856 | switch (S->getClauseKind()) { |
| 2857 | default: break; |
| 2858 | // Transform individual clause nodes |
| 2859 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2860 | case OMPC_ ## Name : \ |
| 2861 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2862 | #include "clang/Basic/OpenMPKinds.def" |
| 2863 | } |
| 2864 | |
| 2865 | return S; |
| 2866 | } |
| 2867 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2868 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2869 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2870 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2871 | if (!E) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2872 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2873 | |
| 2874 | switch (E->getStmtClass()) { |
| 2875 | case Stmt::NoStmtClass: break; |
| 2876 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2877 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2878 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2879 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2880 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | } |
| 2882 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2883 | return E; |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | template<typename Derived> |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2887 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 2888 | bool NotCopyInit) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2889 | // Initializers are instantiated like expressions, except that various outer |
| 2890 | // layers are stripped. |
| 2891 | if (!Init) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2892 | return Init; |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2893 | |
| 2894 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2895 | Init = ExprTemp->getSubExpr(); |
| 2896 | |
Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 2897 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 2898 | Init = MTE->GetTemporaryExpr(); |
| 2899 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2900 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 2901 | Init = Binder->getSubExpr(); |
| 2902 | |
| 2903 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 2904 | Init = ICE->getSubExprAsWritten(); |
| 2905 | |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 2906 | if (CXXStdInitializerListExpr *ILE = |
| 2907 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 2908 | return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 2909 | |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 2910 | // If this is copy-initialization, we only need to reconstruct |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2911 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 2912 | // the initializer is already the right type. |
| 2913 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 2914 | if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2915 | return getDerived().TransformExpr(Init); |
| 2916 | |
| 2917 | // Revert value-initialization back to empty parens. |
| 2918 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 2919 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2920 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2921 | Parens.getEnd()); |
| 2922 | } |
| 2923 | |
| 2924 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 2925 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2926 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2927 | SourceLocation()); |
| 2928 | |
| 2929 | // Revert initialization by constructor back to a parenthesized or braced list |
| 2930 | // of expressions. Any other form of initializer can just be reused directly. |
| 2931 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2932 | return getDerived().TransformExpr(Init); |
| 2933 | |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2934 | // If the initialization implicitly converted an initializer list to a |
| 2935 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 2936 | if (Construct && Construct->isStdInitListInitialization()) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 2937 | return TransformInitializer(Construct->getArg(0), NotCopyInit); |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2938 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2939 | SmallVector<Expr*, 8> NewArgs; |
| 2940 | bool ArgChanged = false; |
| 2941 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 2942 | /*IsCall*/true, NewArgs, &ArgChanged)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2943 | return ExprError(); |
| 2944 | |
| 2945 | // If this was list initialization, revert to list form. |
| 2946 | if (Construct->isListInitialization()) |
| 2947 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 2948 | Construct->getLocEnd(), |
| 2949 | Construct->getType()); |
| 2950 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2951 | // Build a ParenListExpr to represent anything else. |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 2952 | SourceRange Parens = Construct->getParenOrBraceRange(); |
Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 2953 | if (Parens.isInvalid()) { |
| 2954 | // This was a variable declaration's initialization for which no initializer |
| 2955 | // was specified. |
| 2956 | assert(NewArgs.empty() && |
| 2957 | "no parens or braces but have direct init with arguments?"); |
| 2958 | return ExprEmpty(); |
| 2959 | } |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2960 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 2961 | Parens.getEnd()); |
| 2962 | } |
| 2963 | |
| 2964 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2965 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2966 | unsigned NumInputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2967 | bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2968 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2969 | bool *ArgChanged) { |
| 2970 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2971 | // If requested, drop call arguments that need to be dropped. |
| 2972 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2973 | if (ArgChanged) |
| 2974 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2975 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2976 | break; |
| 2977 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2978 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2979 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2980 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2981 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2982 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2983 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2984 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2985 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2986 | // Determine whether the set of unexpanded parameter packs can and should |
| 2987 | // be expanded. |
| 2988 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2989 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2990 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 2991 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2992 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2993 | Pattern->getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2994 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2995 | Expand, RetainExpansion, |
| 2996 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2997 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2998 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2999 | if (!Expand) { |
| 3000 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3001 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3002 | // expansion. |
| 3003 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3004 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 3005 | if (OutPattern.isInvalid()) |
| 3006 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3007 | |
| 3008 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3009 | Expansion->getEllipsisLoc(), |
| 3010 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3011 | if (Out.isInvalid()) |
| 3012 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3013 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3014 | if (ArgChanged) |
| 3015 | *ArgChanged = true; |
| 3016 | Outputs.push_back(Out.get()); |
| 3017 | continue; |
| 3018 | } |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 3019 | |
| 3020 | // Record right away that the argument was changed. This needs |
| 3021 | // to happen even if the array expands to nothing. |
| 3022 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3023 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3024 | // The transform has determined that we should perform an elementwise |
| 3025 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3026 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3027 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3028 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3029 | if (Out.isInvalid()) |
| 3030 | return true; |
| 3031 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3032 | // FIXME: Can this happen? We should not try to expand the pack |
| 3033 | // in this case. |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3034 | if (Out.get()->containsUnexpandedParameterPack()) { |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3035 | Out = getDerived().RebuildPackExpansion( |
| 3036 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3037 | if (Out.isInvalid()) |
| 3038 | return true; |
| 3039 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3040 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3041 | Outputs.push_back(Out.get()); |
| 3042 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3043 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3044 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3045 | // forgetting the partially-substituted parameter pack. |
| 3046 | if (RetainExpansion) { |
| 3047 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3048 | |
| 3049 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3050 | if (Out.isInvalid()) |
| 3051 | return true; |
| 3052 | |
| 3053 | Out = getDerived().RebuildPackExpansion( |
| 3054 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3055 | if (Out.isInvalid()) |
| 3056 | return true; |
| 3057 | |
| 3058 | Outputs.push_back(Out.get()); |
| 3059 | } |
| 3060 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3061 | continue; |
| 3062 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3063 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3064 | ExprResult Result = |
| 3065 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3066 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3067 | if (Result.isInvalid()) |
| 3068 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3069 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3070 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3071 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3072 | |
| 3073 | Outputs.push_back(Result.get()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3074 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3075 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3076 | return false; |
| 3077 | } |
| 3078 | |
| 3079 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3080 | NestedNameSpecifierLoc |
| 3081 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3082 | NestedNameSpecifierLoc NNS, |
| 3083 | QualType ObjectType, |
| 3084 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3085 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3086 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3087 | Qualifier = Qualifier.getPrefix()) |
| 3088 | Qualifiers.push_back(Qualifier); |
| 3089 | |
| 3090 | CXXScopeSpec SS; |
| 3091 | while (!Qualifiers.empty()) { |
| 3092 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3093 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3094 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3095 | switch (QNNS->getKind()) { |
| 3096 | case NestedNameSpecifier::Identifier: |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3097 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3098 | *QNNS->getAsIdentifier(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3099 | Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3100 | Q.getLocalEndLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3101 | ObjectType, false, SS, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3102 | FirstQualifierInScope, false)) |
| 3103 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3104 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3105 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3106 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3107 | case NestedNameSpecifier::Namespace: { |
| 3108 | NamespaceDecl *NS |
| 3109 | = cast_or_null<NamespaceDecl>( |
| 3110 | getDerived().TransformDecl( |
| 3111 | Q.getLocalBeginLoc(), |
| 3112 | QNNS->getAsNamespace())); |
| 3113 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3114 | break; |
| 3115 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3116 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3117 | case NestedNameSpecifier::NamespaceAlias: { |
| 3118 | NamespaceAliasDecl *Alias |
| 3119 | = cast_or_null<NamespaceAliasDecl>( |
| 3120 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3121 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3122 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3123 | Q.getLocalEndLoc()); |
| 3124 | break; |
| 3125 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3126 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3127 | case NestedNameSpecifier::Global: |
| 3128 | // There is no meaningful transformation that one could perform on the |
| 3129 | // global scope. |
| 3130 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3131 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3132 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 3133 | case NestedNameSpecifier::Super: { |
| 3134 | CXXRecordDecl *RD = |
| 3135 | cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 3136 | SourceLocation(), QNNS->getAsRecordDecl())); |
| 3137 | SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); |
| 3138 | break; |
| 3139 | } |
| 3140 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3141 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3142 | case NestedNameSpecifier::TypeSpec: { |
| 3143 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3144 | FirstQualifierInScope, SS); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3145 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3146 | if (!TL) |
| 3147 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3148 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3149 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3150 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3151 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3152 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3153 | "Can't get cv-qualifiers here"); |
Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3154 | if (TL.getType()->isEnumeralType()) |
| 3155 | SemaRef.Diag(TL.getBeginLoc(), |
| 3156 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3157 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3158 | Q.getLocalEndLoc()); |
| 3159 | break; |
| 3160 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3161 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3162 | // error because a previous error should have already been emitted. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3163 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3164 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3165 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3166 | << TL.getType() << SS.getRange(); |
| 3167 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3168 | return NestedNameSpecifierLoc(); |
| 3169 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3170 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3171 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3172 | // 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] | 3173 | FirstQualifierInScope = nullptr; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3174 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3175 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3176 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3177 | // 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] | 3178 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3179 | !getDerived().AlwaysRebuild()) |
| 3180 | return NNS; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3181 | |
| 3182 | // If we can re-use the source-location data from the original |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3183 | // nested-name-specifier, do so. |
| 3184 | if (SS.location_size() == NNS.getDataLength() && |
| 3185 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3186 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3187 | |
| 3188 | // Allocate new nested-name-specifier location information. |
| 3189 | return SS.getWithLocInContext(SemaRef.Context); |
| 3190 | } |
| 3191 | |
| 3192 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3193 | DeclarationNameInfo |
| 3194 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3195 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3196 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3197 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3198 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3199 | |
| 3200 | switch (Name.getNameKind()) { |
| 3201 | case DeclarationName::Identifier: |
| 3202 | case DeclarationName::ObjCZeroArgSelector: |
| 3203 | case DeclarationName::ObjCOneArgSelector: |
| 3204 | case DeclarationName::ObjCMultiArgSelector: |
| 3205 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3206 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3207 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3208 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3209 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3210 | case DeclarationName::CXXConstructorName: |
| 3211 | case DeclarationName::CXXDestructorName: |
| 3212 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3213 | TypeSourceInfo *NewTInfo; |
| 3214 | CanQualType NewCanTy; |
| 3215 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3216 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3217 | if (!NewTInfo) |
| 3218 | return DeclarationNameInfo(); |
| 3219 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3220 | } |
| 3221 | else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3222 | NewTInfo = nullptr; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3223 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3224 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3225 | if (NewT.isNull()) |
| 3226 | return DeclarationNameInfo(); |
| 3227 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3228 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3229 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3230 | DeclarationName NewName |
| 3231 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3232 | NewCanTy); |
| 3233 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3234 | NewNameInfo.setName(NewName); |
| 3235 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3236 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3237 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3238 | } |
| 3239 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3240 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3241 | } |
| 3242 | |
| 3243 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3245 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3246 | TemplateName Name, |
| 3247 | SourceLocation NameLoc, |
| 3248 | QualType ObjectType, |
| 3249 | NamedDecl *FirstQualifierInScope) { |
| 3250 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3251 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3252 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3253 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3254 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3255 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3256 | Template)); |
| 3257 | if (!TransTemplate) |
| 3258 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3259 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3260 | if (!getDerived().AlwaysRebuild() && |
| 3261 | SS.getScopeRep() == QTN->getQualifier() && |
| 3262 | TransTemplate == Template) |
| 3263 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3264 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3265 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3266 | TransTemplate); |
| 3267 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3268 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3269 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3270 | if (SS.getScopeRep()) { |
| 3271 | // These apply to the scope specifier, not the template. |
| 3272 | ObjectType = QualType(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3273 | FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3276 | if (!getDerived().AlwaysRebuild() && |
| 3277 | SS.getScopeRep() == DTN->getQualifier() && |
| 3278 | ObjectType.isNull()) |
| 3279 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3280 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3281 | if (DTN->isIdentifier()) { |
| 3282 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3283 | *DTN->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3284 | NameLoc, |
| 3285 | ObjectType, |
| 3286 | FirstQualifierInScope); |
| 3287 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3288 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3289 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3290 | ObjectType); |
| 3291 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3292 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3293 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3294 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3295 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3296 | Template)); |
| 3297 | if (!TransTemplate) |
| 3298 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3299 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3300 | if (!getDerived().AlwaysRebuild() && |
| 3301 | TransTemplate == Template) |
| 3302 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3303 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3304 | return TemplateName(TransTemplate); |
| 3305 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3306 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3307 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3308 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3309 | TemplateTemplateParmDecl *TransParam |
| 3310 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3311 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3312 | if (!TransParam) |
| 3313 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3314 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3315 | if (!getDerived().AlwaysRebuild() && |
| 3316 | TransParam == SubstPack->getParameterPack()) |
| 3317 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3318 | |
| 3319 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3320 | SubstPack->getArgumentPack()); |
| 3321 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3322 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3323 | // These should be getting filtered out before they reach the AST. |
| 3324 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3328 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3329 | const TemplateArgument &Arg, |
| 3330 | TemplateArgumentLoc &Output) { |
| 3331 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3332 | switch (Arg.getKind()) { |
| 3333 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3334 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3335 | break; |
| 3336 | |
| 3337 | case TemplateArgument::Type: |
| 3338 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3339 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3340 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3341 | break; |
| 3342 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3343 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3344 | case TemplateArgument::TemplateExpansion: { |
| 3345 | NestedNameSpecifierLocBuilder Builder; |
| 3346 | TemplateName Template = Arg.getAsTemplate(); |
| 3347 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3348 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3349 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3350 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3351 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3352 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3353 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3354 | Builder.getWithLocInContext(SemaRef.Context), |
| 3355 | Loc); |
| 3356 | else |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3357 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3358 | Builder.getWithLocInContext(SemaRef.Context), |
| 3359 | Loc, Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3360 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3361 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3362 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3363 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3364 | case TemplateArgument::Expression: |
| 3365 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3366 | break; |
| 3367 | |
| 3368 | case TemplateArgument::Declaration: |
| 3369 | case TemplateArgument::Integral: |
| 3370 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3371 | case TemplateArgument::NullPtr: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3372 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3373 | break; |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | template<typename Derived> |
| 3378 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3379 | const TemplateArgumentLoc &Input, |
| 3380 | TemplateArgumentLoc &Output) { |
| 3381 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3382 | switch (Arg.getKind()) { |
| 3383 | case TemplateArgument::Null: |
| 3384 | case TemplateArgument::Integral: |
Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3385 | case TemplateArgument::Pack: |
| 3386 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3387 | case TemplateArgument::NullPtr: |
| 3388 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3389 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3390 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3391 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3392 | if (!DI) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3393 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3394 | |
| 3395 | DI = getDerived().TransformType(DI); |
| 3396 | if (!DI) return true; |
| 3397 | |
| 3398 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3399 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3400 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3401 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3402 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3403 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3404 | if (QualifierLoc) { |
| 3405 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3406 | if (!QualifierLoc) |
| 3407 | return true; |
| 3408 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3410 | CXXScopeSpec SS; |
| 3411 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3412 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3413 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3414 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3415 | if (Template.isNull()) |
| 3416 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3417 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3418 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3419 | Input.getTemplateNameLoc()); |
| 3420 | return false; |
| 3421 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3422 | |
| 3423 | case TemplateArgument::TemplateExpansion: |
| 3424 | llvm_unreachable("Caller should expand pack expansions"); |
| 3425 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3426 | case TemplateArgument::Expression: { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3427 | // Template argument expressions are constant expressions. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3429 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3430 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3431 | Expr *InputExpr = Input.getSourceExpression(); |
| 3432 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3433 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3434 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3435 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3436 | if (E.isInvalid()) return true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3437 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3438 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3439 | } |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3440 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3442 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3443 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3446 | /// \brief Iterator adaptor that invents template argument location information |
| 3447 | /// for each of the template arguments in its underlying iterator. |
| 3448 | template<typename Derived, typename InputIterator> |
| 3449 | class TemplateArgumentLocInventIterator { |
| 3450 | TreeTransform<Derived> &Self; |
| 3451 | InputIterator Iter; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3452 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3453 | public: |
| 3454 | typedef TemplateArgumentLoc value_type; |
| 3455 | typedef TemplateArgumentLoc reference; |
| 3456 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3457 | difference_type; |
| 3458 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3459 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3460 | class pointer { |
| 3461 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3462 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3463 | public: |
| 3464 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3465 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3466 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3467 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3468 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3469 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3470 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3471 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3472 | InputIterator Iter) |
| 3473 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3474 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3475 | TemplateArgumentLocInventIterator &operator++() { |
| 3476 | ++Iter; |
| 3477 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3478 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3479 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3480 | TemplateArgumentLocInventIterator operator++(int) { |
| 3481 | TemplateArgumentLocInventIterator Old(*this); |
| 3482 | ++(*this); |
| 3483 | return Old; |
| 3484 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3485 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3486 | reference operator*() const { |
| 3487 | TemplateArgumentLoc Result; |
| 3488 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3489 | return Result; |
| 3490 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3491 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3492 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3493 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3494 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3495 | const TemplateArgumentLocInventIterator &Y) { |
| 3496 | return X.Iter == Y.Iter; |
| 3497 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3498 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3499 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3500 | const TemplateArgumentLocInventIterator &Y) { |
| 3501 | return X.Iter != Y.Iter; |
| 3502 | } |
| 3503 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3504 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3505 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3506 | template<typename InputIterator> |
| 3507 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3508 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3509 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3510 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3511 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3512 | TemplateArgumentLoc In = *First; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3513 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3514 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3515 | // Unpack argument packs, which we translate them into separate |
| 3516 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3517 | // FIXME: We could do much better if we could guarantee that the |
| 3518 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3519 | // all of the template arguments in the argument pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3520 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3521 | TemplateArgument::pack_iterator> |
| 3522 | PackLocIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3523 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3524 | In.getArgument().pack_begin()), |
| 3525 | PackLocIterator(*this, |
| 3526 | In.getArgument().pack_end()), |
| 3527 | Outputs)) |
| 3528 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3529 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3530 | continue; |
| 3531 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3532 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3533 | if (In.getArgument().isPackExpansion()) { |
| 3534 | // We have a pack expansion, for which we will be substituting into |
| 3535 | // the pattern. |
| 3536 | SourceLocation Ellipsis; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3537 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3538 | TemplateArgumentLoc Pattern |
Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3539 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3540 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3541 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3542 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3543 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3544 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3545 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3546 | // Determine whether the set of unexpanded parameter packs can and should |
| 3547 | // be expanded. |
| 3548 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3549 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3550 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3551 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3552 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3553 | Unexpanded, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3554 | Expand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3555 | RetainExpansion, |
| 3556 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3557 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3558 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3559 | if (!Expand) { |
| 3560 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3561 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3562 | // expansion. |
| 3563 | TemplateArgumentLoc OutPattern; |
| 3564 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3565 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3566 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3567 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3568 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3569 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3570 | if (Out.getArgument().isNull()) |
| 3571 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3572 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3573 | Outputs.addArgument(Out); |
| 3574 | continue; |
| 3575 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3576 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3577 | // The transform has determined that we should perform an elementwise |
| 3578 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3579 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3580 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3581 | |
| 3582 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3583 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3584 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3585 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3586 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3587 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3588 | if (Out.getArgument().isNull()) |
| 3589 | return true; |
| 3590 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3591 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3592 | Outputs.addArgument(Out); |
| 3593 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3594 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3595 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3596 | // forgetting the partially-substituted parameter pack. |
| 3597 | if (RetainExpansion) { |
| 3598 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3599 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3600 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3601 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3602 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3603 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3604 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3605 | if (Out.getArgument().isNull()) |
| 3606 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3607 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3608 | Outputs.addArgument(Out); |
| 3609 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3610 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3611 | continue; |
| 3612 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3613 | |
| 3614 | // The simple case: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3615 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3616 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3617 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3618 | Outputs.addArgument(Out); |
| 3619 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3620 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3621 | return false; |
| 3622 | |
| 3623 | } |
| 3624 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3625 | //===----------------------------------------------------------------------===// |
| 3626 | // Type transformation |
| 3627 | //===----------------------------------------------------------------------===// |
| 3628 | |
| 3629 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3630 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3631 | if (getDerived().AlreadyTransformed(T)) |
| 3632 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3633 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3634 | // Temporary workaround. All of these transformations should |
| 3635 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3636 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3637 | getDerived().getBaseLocation()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3638 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3639 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3640 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3641 | if (!NewDI) |
| 3642 | return QualType(); |
| 3643 | |
| 3644 | return NewDI->getType(); |
| 3645 | } |
| 3646 | |
| 3647 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3648 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3649 | // Refine the base location to the type's location. |
| 3650 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3651 | getDerived().getBaseEntity()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3652 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3653 | return DI; |
| 3654 | |
| 3655 | TypeLocBuilder TLB; |
| 3656 | |
| 3657 | TypeLoc TL = DI->getTypeLoc(); |
| 3658 | TLB.reserve(TL.getFullDataSize()); |
| 3659 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3660 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3661 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3662 | return nullptr; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3663 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3664 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | template<typename Derived> |
| 3668 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3669 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3670 | switch (T.getTypeLocClass()) { |
| 3671 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3672 | #define TYPELOC(CLASS, PARENT) \ |
| 3673 | case TypeLoc::CLASS: \ |
| 3674 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3675 | T.castAs<CLASS##TypeLoc>()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3676 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3677 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3678 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3679 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3683 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3684 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3685 | /// types). This is the right thing for template instantiation, but |
| 3686 | /// probably not for other clients. |
| 3687 | template<typename Derived> |
| 3688 | QualType |
| 3689 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3690 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3691 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3692 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3693 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3694 | if (Result.isNull()) |
| 3695 | return QualType(); |
| 3696 | |
| 3697 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3698 | // FIXME: this is the right thing for template instantiation, but |
| 3699 | // probably not for other clients. |
| 3700 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3701 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3703 | // 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] | 3704 | // resulting type. |
| 3705 | if (Quals.hasObjCLifetime()) { |
| 3706 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3707 | Quals.removeObjCLifetime(); |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3708 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3709 | // Objective-C ARC: |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3710 | // A lifetime qualifier applied to a substituted template parameter |
| 3711 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3712 | const AutoType *AutoTy; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3713 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3714 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3715 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3716 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3717 | Qs.removeObjCLifetime(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3718 | Replacement |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3719 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3720 | Qs); |
| 3721 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3722 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3723 | Replacement); |
| 3724 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3725 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3726 | // 'auto' types behave the same way as template parameters. |
| 3727 | QualType Deduced = AutoTy->getDeducedType(); |
| 3728 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3729 | Qs.removeObjCLifetime(); |
| 3730 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3731 | Qs); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 3732 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(), |
| 3733 | AutoTy->isDependentType()); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3734 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3735 | } else { |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3736 | // Otherwise, complain about the addition of a qualifier to an |
| 3737 | // already-qualified type. |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3738 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3739 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3740 | << Result << R; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3741 | |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3742 | Quals.removeObjCLifetime(); |
| 3743 | } |
| 3744 | } |
| 3745 | } |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3746 | if (!Quals.empty()) { |
| 3747 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3748 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3749 | if (Result.hasLocalQualifiers()) |
| 3750 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3751 | // No location information to preserve. |
| 3752 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3753 | |
| 3754 | return Result; |
| 3755 | } |
| 3756 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3757 | template<typename Derived> |
| 3758 | TypeLoc |
| 3759 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3760 | QualType ObjectType, |
| 3761 | NamedDecl *UnqualLookup, |
| 3762 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3763 | if (getDerived().AlreadyTransformed(TL.getType())) |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3764 | return TL; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3765 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3766 | TypeSourceInfo *TSI = |
| 3767 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 3768 | if (TSI) |
| 3769 | return TSI->getTypeLoc(); |
| 3770 | return TypeLoc(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3773 | template<typename Derived> |
| 3774 | TypeSourceInfo * |
| 3775 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3776 | QualType ObjectType, |
| 3777 | NamedDecl *UnqualLookup, |
| 3778 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3779 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3780 | return TSInfo; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3781 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3782 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 3783 | UnqualLookup, SS); |
| 3784 | } |
| 3785 | |
| 3786 | template <typename Derived> |
| 3787 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 3788 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 3789 | CXXScopeSpec &SS) { |
| 3790 | QualType T = TL.getType(); |
| 3791 | assert(!getDerived().AlreadyTransformed(T)); |
| 3792 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3793 | TypeLocBuilder TLB; |
| 3794 | QualType Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3795 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3796 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3797 | TemplateSpecializationTypeLoc SpecTL = |
| 3798 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3799 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3800 | TemplateName Template |
| 3801 | = getDerived().TransformTemplateName(SS, |
| 3802 | SpecTL.getTypePtr()->getTemplateName(), |
| 3803 | SpecTL.getTemplateNameLoc(), |
| 3804 | ObjectType, UnqualLookup); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3805 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3806 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3807 | |
| 3808 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3809 | Template); |
| 3810 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3811 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3812 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3813 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3814 | TemplateName Template |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3815 | = getDerived().RebuildTemplateName(SS, |
| 3816 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3817 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3818 | ObjectType, UnqualLookup); |
| 3819 | if (Template.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3820 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3821 | |
| 3822 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3823 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3824 | Template, |
| 3825 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3826 | } else { |
| 3827 | // Nothing special needs to be done for these. |
| 3828 | Result = getDerived().TransformType(TLB, TL); |
| 3829 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3830 | |
| 3831 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3832 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3833 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3834 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3835 | } |
| 3836 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3837 | template <class TyLoc> static inline |
| 3838 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3839 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3840 | NewT.setNameLoc(T.getNameLoc()); |
| 3841 | return T.getType(); |
| 3842 | } |
| 3843 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3844 | template<typename Derived> |
| 3845 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3846 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3847 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3848 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3849 | if (T.needsExtraLocalData()) |
| 3850 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3851 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3852 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3853 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3854 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3855 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3856 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3857 | // FIXME: recurse? |
| 3858 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3859 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3860 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3861 | template <typename Derived> |
| 3862 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 3863 | AdjustedTypeLoc TL) { |
| 3864 | // Adjustments applied during transformation are handled elsewhere. |
| 3865 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3866 | } |
| 3867 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3868 | template<typename Derived> |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 3869 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 3870 | DecayedTypeLoc TL) { |
| 3871 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3872 | if (OriginalType.isNull()) |
| 3873 | return QualType(); |
| 3874 | |
| 3875 | QualType Result = TL.getType(); |
| 3876 | if (getDerived().AlwaysRebuild() || |
| 3877 | OriginalType != TL.getOriginalLoc().getType()) |
| 3878 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 3879 | TLB.push<DecayedTypeLoc>(Result); |
| 3880 | // Nothing to set for DecayedTypeLoc. |
| 3881 | return Result; |
| 3882 | } |
| 3883 | |
| 3884 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3885 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3886 | PointerTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3887 | QualType PointeeType |
| 3888 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3889 | if (PointeeType.isNull()) |
| 3890 | return QualType(); |
| 3891 | |
| 3892 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3893 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3894 | // A dependent pointer type 'T *' has is being transformed such |
| 3895 | // that an Objective-C class type is being replaced for 'T'. The |
| 3896 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3897 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3898 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3899 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3900 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3901 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3902 | return Result; |
| 3903 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3904 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3905 | if (getDerived().AlwaysRebuild() || |
| 3906 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3907 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3908 | if (Result.isNull()) |
| 3909 | return QualType(); |
| 3910 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3911 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3912 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3913 | // pointing to. |
| 3914 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3915 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3916 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3917 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3918 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3919 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3920 | |
| 3921 | template<typename Derived> |
| 3922 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3923 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3924 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3925 | QualType PointeeType |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3926 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3927 | if (PointeeType.isNull()) |
| 3928 | return QualType(); |
| 3929 | |
| 3930 | QualType Result = TL.getType(); |
| 3931 | if (getDerived().AlwaysRebuild() || |
| 3932 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3933 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3934 | TL.getSigilLoc()); |
| 3935 | if (Result.isNull()) |
| 3936 | return QualType(); |
| 3937 | } |
| 3938 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3939 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3940 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3941 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3942 | } |
| 3943 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3944 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3945 | /// don't care whether the type itself is an l-value type or an r-value |
| 3946 | /// type; we only care if the type was *written* as an l-value type |
| 3947 | /// or an r-value type. |
| 3948 | template<typename Derived> |
| 3949 | QualType |
| 3950 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3951 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3952 | const ReferenceType *T = TL.getTypePtr(); |
| 3953 | |
| 3954 | // Note that this works with the pointee-as-written. |
| 3955 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3956 | if (PointeeType.isNull()) |
| 3957 | return QualType(); |
| 3958 | |
| 3959 | QualType Result = TL.getType(); |
| 3960 | if (getDerived().AlwaysRebuild() || |
| 3961 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3962 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3963 | T->isSpelledAsLValue(), |
| 3964 | TL.getSigilLoc()); |
| 3965 | if (Result.isNull()) |
| 3966 | return QualType(); |
| 3967 | } |
| 3968 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3969 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3970 | // referring to. |
| 3971 | TLB.TypeWasModifiedSafely( |
| 3972 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3973 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3974 | // r-value references can be rebuilt as l-value references. |
| 3975 | ReferenceTypeLoc NewTL; |
| 3976 | if (isa<LValueReferenceType>(Result)) |
| 3977 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3978 | else |
| 3979 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3980 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3981 | |
| 3982 | return Result; |
| 3983 | } |
| 3984 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3985 | template<typename Derived> |
| 3986 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3987 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3988 | LValueReferenceTypeLoc TL) { |
| 3989 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | template<typename Derived> |
| 3993 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3994 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3995 | RValueReferenceTypeLoc TL) { |
| 3996 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3998 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3999 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4000 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4001 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4002 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4003 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4004 | if (PointeeType.isNull()) |
| 4005 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4006 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4007 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4008 | TypeSourceInfo *NewClsTInfo = nullptr; |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4009 | if (OldClsTInfo) { |
| 4010 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 4011 | if (!NewClsTInfo) |
| 4012 | return QualType(); |
| 4013 | } |
| 4014 | |
| 4015 | const MemberPointerType *T = TL.getTypePtr(); |
| 4016 | QualType OldClsType = QualType(T->getClass(), 0); |
| 4017 | QualType NewClsType; |
| 4018 | if (NewClsTInfo) |
| 4019 | NewClsType = NewClsTInfo->getType(); |
| 4020 | else { |
| 4021 | NewClsType = getDerived().TransformType(OldClsType); |
| 4022 | if (NewClsType.isNull()) |
| 4023 | return QualType(); |
| 4024 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4025 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4026 | QualType Result = TL.getType(); |
| 4027 | if (getDerived().AlwaysRebuild() || |
| 4028 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4029 | NewClsType != OldClsType) { |
| 4030 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4031 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4032 | if (Result.isNull()) |
| 4033 | return QualType(); |
| 4034 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4035 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4036 | // If we had to adjust the pointee type when building a member pointer, make |
| 4037 | // sure to push TypeLoc info for it. |
| 4038 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 4039 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 4040 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 4041 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 4042 | } |
| 4043 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4044 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 4045 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4046 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4047 | |
| 4048 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4049 | } |
| 4050 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4051 | template<typename Derived> |
| 4052 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4053 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4054 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4055 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4056 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4057 | if (ElementType.isNull()) |
| 4058 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4059 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4060 | QualType Result = TL.getType(); |
| 4061 | if (getDerived().AlwaysRebuild() || |
| 4062 | ElementType != T->getElementType()) { |
| 4063 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4064 | T->getSizeModifier(), |
| 4065 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4066 | T->getIndexTypeCVRQualifiers(), |
| 4067 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4068 | if (Result.isNull()) |
| 4069 | return QualType(); |
| 4070 | } |
Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4071 | |
| 4072 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4073 | // a ConstantArrayType is allowed to have an element type which is a |
| 4074 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4075 | // types have the same location layout. |
| 4076 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4077 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4078 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4079 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4080 | Expr *Size = TL.getSizeExpr(); |
| 4081 | if (Size) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4082 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4083 | Sema::ConstantEvaluated); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4084 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4085 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4086 | } |
| 4087 | NewTL.setSizeExpr(Size); |
| 4088 | |
| 4089 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4090 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4091 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4092 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4093 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4094 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4095 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4096 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4097 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4098 | if (ElementType.isNull()) |
| 4099 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4100 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4101 | QualType Result = TL.getType(); |
| 4102 | if (getDerived().AlwaysRebuild() || |
| 4103 | ElementType != T->getElementType()) { |
| 4104 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4105 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4106 | T->getIndexTypeCVRQualifiers(), |
| 4107 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4108 | if (Result.isNull()) |
| 4109 | return QualType(); |
| 4110 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4111 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4112 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4113 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4114 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4115 | NewTL.setSizeExpr(nullptr); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4116 | |
| 4117 | return Result; |
| 4118 | } |
| 4119 | |
| 4120 | template<typename Derived> |
| 4121 | QualType |
| 4122 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4123 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4124 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4125 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4126 | if (ElementType.isNull()) |
| 4127 | return QualType(); |
| 4128 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4129 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4130 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 4131 | if (SizeResult.isInvalid()) |
| 4132 | return QualType(); |
| 4133 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4134 | Expr *Size = SizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4135 | |
| 4136 | QualType Result = TL.getType(); |
| 4137 | if (getDerived().AlwaysRebuild() || |
| 4138 | ElementType != T->getElementType() || |
| 4139 | Size != T->getSizeExpr()) { |
| 4140 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4141 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4142 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4143 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4144 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4145 | if (Result.isNull()) |
| 4146 | return QualType(); |
| 4147 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4148 | |
Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4149 | // We might have constant size array now, but fortunately it has the same |
| 4150 | // location layout. |
| 4151 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4152 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4153 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4154 | NewTL.setSizeExpr(Size); |
| 4155 | |
| 4156 | return Result; |
| 4157 | } |
| 4158 | |
| 4159 | template<typename Derived> |
| 4160 | QualType |
| 4161 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4162 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4163 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4164 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4165 | if (ElementType.isNull()) |
| 4166 | return QualType(); |
| 4167 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4168 | // Array bounds are constant expressions. |
| 4169 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4170 | Sema::ConstantEvaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4171 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4172 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4173 | Expr *origSize = TL.getSizeExpr(); |
| 4174 | if (!origSize) origSize = T->getSizeExpr(); |
| 4175 | |
| 4176 | ExprResult sizeResult |
| 4177 | = getDerived().TransformExpr(origSize); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4178 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4179 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4180 | return QualType(); |
| 4181 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4182 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4183 | |
| 4184 | QualType Result = TL.getType(); |
| 4185 | if (getDerived().AlwaysRebuild() || |
| 4186 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4187 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4188 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4189 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4190 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4191 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4192 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4193 | if (Result.isNull()) |
| 4194 | return QualType(); |
| 4195 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4196 | |
| 4197 | // We might have any sort of array type now, but fortunately they |
| 4198 | // all have the same location layout. |
| 4199 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4200 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4201 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4202 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4203 | |
| 4204 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4205 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4206 | |
| 4207 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4208 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4209 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4210 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4211 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4212 | |
| 4213 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4214 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4215 | if (ElementType.isNull()) |
| 4216 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4217 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4218 | // Vector sizes are constant expressions. |
| 4219 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4220 | Sema::ConstantEvaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4221 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4222 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4223 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4224 | if (Size.isInvalid()) |
| 4225 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4226 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4227 | QualType Result = TL.getType(); |
| 4228 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4229 | ElementType != T->getElementType() || |
| 4230 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4231 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4232 | Size.get(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4233 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4234 | if (Result.isNull()) |
| 4235 | return QualType(); |
| 4236 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4237 | |
| 4238 | // Result might be dependent or not. |
| 4239 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4240 | DependentSizedExtVectorTypeLoc NewTL |
| 4241 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4242 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4243 | } else { |
| 4244 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4245 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4246 | } |
| 4247 | |
| 4248 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4249 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | |
| 4251 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4252 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4253 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4254 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4255 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4256 | if (ElementType.isNull()) |
| 4257 | return QualType(); |
| 4258 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4259 | QualType Result = TL.getType(); |
| 4260 | if (getDerived().AlwaysRebuild() || |
| 4261 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4262 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4263 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4264 | if (Result.isNull()) |
| 4265 | return QualType(); |
| 4266 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4267 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4268 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4269 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4270 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4271 | return Result; |
| 4272 | } |
| 4273 | |
| 4274 | template<typename Derived> |
| 4275 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4276 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4277 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4278 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4279 | if (ElementType.isNull()) |
| 4280 | return QualType(); |
| 4281 | |
| 4282 | QualType Result = TL.getType(); |
| 4283 | if (getDerived().AlwaysRebuild() || |
| 4284 | ElementType != T->getElementType()) { |
| 4285 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4286 | T->getNumElements(), |
| 4287 | /*FIXME*/ SourceLocation()); |
| 4288 | if (Result.isNull()) |
| 4289 | return QualType(); |
| 4290 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4291 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4292 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4293 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4294 | |
| 4295 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4297 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4298 | template <typename Derived> |
| 4299 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4300 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4301 | bool ExpectParameterPack) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4302 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4303 | TypeSourceInfo *NewDI = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4304 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4305 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4306 | // 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] | 4307 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4308 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4309 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4310 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4311 | TypeLocBuilder TLB; |
| 4312 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4313 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4314 | |
| 4315 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4316 | OldExpansionTL.getPatternLoc()); |
| 4317 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4318 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4319 | |
| 4320 | Result = RebuildPackExpansionType(Result, |
| 4321 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4322 | OldExpansionTL.getEllipsisLoc(), |
| 4323 | NumExpansions); |
| 4324 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4325 | return nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4326 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4327 | PackExpansionTypeLoc NewExpansionTL |
| 4328 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4329 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4330 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4331 | } else |
| 4332 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4333 | if (!NewDI) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4334 | return nullptr; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4335 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4336 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4337 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4338 | |
| 4339 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4340 | OldParm->getDeclContext(), |
| 4341 | OldParm->getInnerLocStart(), |
| 4342 | OldParm->getLocation(), |
| 4343 | OldParm->getIdentifier(), |
| 4344 | NewDI->getType(), |
| 4345 | NewDI, |
| 4346 | OldParm->getStorageClass(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4347 | /* DefArg */ nullptr); |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4348 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4349 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4350 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | template<typename Derived> |
| 4354 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4355 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4356 | ParmVarDecl **Params, unsigned NumParams, |
| 4357 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4358 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4359 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4360 | int indexAdjustment = 0; |
| 4361 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4362 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4363 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4364 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4365 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4366 | Optional<unsigned> NumExpansions; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4367 | ParmVarDecl *NewParm = nullptr; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4368 | if (OldParm->isParameterPack()) { |
| 4369 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4370 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4371 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4372 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4373 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4374 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4375 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4376 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4377 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4378 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4379 | // Determine whether we should expand the parameter packs. |
| 4380 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4381 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4382 | Optional<unsigned> OrigNumExpansions = |
| 4383 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4384 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4385 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4386 | Pattern.getSourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4387 | Unexpanded, |
| 4388 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4389 | RetainExpansion, |
| 4390 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4391 | return true; |
| 4392 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4393 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4394 | if (ShouldExpand) { |
| 4395 | // Expand the function parameter pack into multiple, separate |
| 4396 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4397 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4398 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4399 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4400 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4401 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4402 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4403 | OrigNumExpansions, |
| 4404 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4405 | if (!NewParm) |
| 4406 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4407 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4408 | OutParamTypes.push_back(NewParm->getType()); |
| 4409 | if (PVars) |
| 4410 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4411 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4412 | |
| 4413 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4414 | // forgetting the partially-substituted parameter pack. |
| 4415 | if (RetainExpansion) { |
| 4416 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4417 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4418 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4419 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4420 | OrigNumExpansions, |
| 4421 | /*ExpectParameterPack=*/false); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4422 | if (!NewParm) |
| 4423 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4424 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4425 | OutParamTypes.push_back(NewParm->getType()); |
| 4426 | if (PVars) |
| 4427 | PVars->push_back(NewParm); |
| 4428 | } |
| 4429 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4430 | // The next parameter should have the same adjustment as the |
| 4431 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4432 | // on every push. Also, if we push nothing, the adjustment should |
| 4433 | // go down by one. |
| 4434 | indexAdjustment--; |
| 4435 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4436 | // We're done with the pack expansion. |
| 4437 | continue; |
| 4438 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4439 | |
| 4440 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4441 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4442 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4443 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4444 | indexAdjustment, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4445 | NumExpansions, |
| 4446 | /*ExpectParameterPack=*/true); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4447 | } else { |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4448 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4449 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4450 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4451 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4452 | if (!NewParm) |
| 4453 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4454 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4455 | OutParamTypes.push_back(NewParm->getType()); |
| 4456 | if (PVars) |
| 4457 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4458 | continue; |
| 4459 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4460 | |
| 4461 | // Deal with the possibility that we don't have a parameter |
| 4462 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4463 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4464 | bool IsPackExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4465 | Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4466 | QualType NewType; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4467 | if (const PackExpansionType *Expansion |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4468 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4469 | // We have a function parameter pack that may need to be expanded. |
| 4470 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4471 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4472 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4473 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4474 | // Determine whether we should expand the parameter packs. |
| 4475 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4476 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4477 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4478 | Unexpanded, |
| 4479 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4480 | RetainExpansion, |
| 4481 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4482 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4483 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4484 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4485 | if (ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4486 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4487 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4488 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4489 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4490 | QualType NewType = getDerived().TransformType(Pattern); |
| 4491 | if (NewType.isNull()) |
| 4492 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4493 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4494 | OutParamTypes.push_back(NewType); |
| 4495 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4496 | PVars->push_back(nullptr); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4497 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4498 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4499 | // We're done with the pack expansion. |
| 4500 | continue; |
| 4501 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4502 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4503 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4504 | // forgetting the partially-substituted parameter pack. |
| 4505 | if (RetainExpansion) { |
| 4506 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4507 | QualType NewType = getDerived().TransformType(Pattern); |
| 4508 | if (NewType.isNull()) |
| 4509 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4510 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4511 | OutParamTypes.push_back(NewType); |
| 4512 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4513 | PVars->push_back(nullptr); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4514 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4515 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4516 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4517 | // expansion. |
| 4518 | OldType = Expansion->getPattern(); |
| 4519 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4520 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4521 | NewType = getDerived().TransformType(OldType); |
| 4522 | } else { |
| 4523 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4524 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4525 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4526 | if (NewType.isNull()) |
| 4527 | return true; |
| 4528 | |
| 4529 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4530 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4531 | NumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4532 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4533 | OutParamTypes.push_back(NewType); |
| 4534 | if (PVars) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4535 | PVars->push_back(nullptr); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4536 | } |
| 4537 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4538 | #ifndef NDEBUG |
| 4539 | if (PVars) { |
| 4540 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4541 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4542 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4543 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4544 | #endif |
| 4545 | |
| 4546 | return false; |
| 4547 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4548 | |
| 4549 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4550 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4551 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4552 | FunctionProtoTypeLoc TL) { |
NAKAMURA Takumi | 2322415 | 2014-10-17 12:48:37 +0000 | [diff] [blame] | 4553 | return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
NAKAMURA Takumi | 2322415 | 2014-10-17 12:48:37 +0000 | [diff] [blame] | 4556 | template<typename Derived> |
| 4557 | QualType |
| 4558 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4559 | FunctionProtoTypeLoc TL, |
| 4560 | CXXRecordDecl *ThisContext, |
| 4561 | unsigned ThisTypeQuals) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4562 | // Transform the parameters and return type. |
| 4563 | // |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4564 | // 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] | 4565 | // When the function has a trailing return type, we instantiate the |
| 4566 | // parameters before the return type, since the return type can then refer |
| 4567 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4568 | // |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4569 | SmallVector<QualType, 4> ParamTypes; |
| 4570 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4571 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4572 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4573 | QualType ResultType; |
| 4574 | |
Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4575 | if (T->hasTrailingReturn()) { |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4576 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4577 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4578 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4579 | return QualType(); |
| 4580 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4581 | { |
| 4582 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4583 | // If a declaration declares a member function or member function |
| 4584 | // 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] | 4585 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4586 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4587 | // declarator. |
| 4588 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4589 | |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4590 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4591 | if (ResultType.isNull()) |
| 4592 | return QualType(); |
| 4593 | } |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4594 | } |
| 4595 | else { |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4596 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4597 | if (ResultType.isNull()) |
| 4598 | return QualType(); |
| 4599 | |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4600 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4601 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4602 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4603 | return QualType(); |
| 4604 | } |
| 4605 | |
NAKAMURA Takumi | 2322415 | 2014-10-17 12:48:37 +0000 | [diff] [blame] | 4606 | // FIXME: Need to transform the exception-specification too. |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4607 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4608 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4609 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4610 | T->getNumParams() != ParamTypes.size() || |
| 4611 | !std::equal(T->param_type_begin(), T->param_type_end(), |
NAKAMURA Takumi | 2322415 | 2014-10-17 12:48:37 +0000 | [diff] [blame] | 4612 | ParamTypes.begin())) { |
| 4613 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, |
| 4614 | T->getExtProtoInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4615 | if (Result.isNull()) |
| 4616 | return QualType(); |
| 4617 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4618 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4619 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4620 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4621 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4622 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4623 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4624 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 4625 | NewTL.setParam(i, ParamDecls[i]); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4626 | |
| 4627 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4628 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4629 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4630 | template<typename Derived> |
| 4631 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4632 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4633 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4634 | const FunctionNoProtoType *T = TL.getTypePtr(); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4635 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4636 | if (ResultType.isNull()) |
| 4637 | return QualType(); |
| 4638 | |
| 4639 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4640 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4641 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4642 | |
| 4643 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4644 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4645 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4646 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4647 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4648 | |
| 4649 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4651 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4652 | template<typename Derived> QualType |
| 4653 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4654 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4655 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4656 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4657 | if (!D) |
| 4658 | return QualType(); |
| 4659 | |
| 4660 | QualType Result = TL.getType(); |
| 4661 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4662 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4663 | if (Result.isNull()) |
| 4664 | return QualType(); |
| 4665 | } |
| 4666 | |
| 4667 | // We might get an arbitrary type spec type back. We should at |
| 4668 | // least always get a type spec type, though. |
| 4669 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4670 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4671 | |
| 4672 | return Result; |
| 4673 | } |
| 4674 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4675 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4676 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4677 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4678 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4679 | TypedefNameDecl *Typedef |
| 4680 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4681 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4682 | if (!Typedef) |
| 4683 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4684 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4685 | QualType Result = TL.getType(); |
| 4686 | if (getDerived().AlwaysRebuild() || |
| 4687 | Typedef != T->getDecl()) { |
| 4688 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4689 | if (Result.isNull()) |
| 4690 | return QualType(); |
| 4691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4692 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4693 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4694 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4695 | |
| 4696 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4697 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4699 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4700 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4701 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4702 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4703 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4704 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4705 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4706 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4707 | if (E.isInvalid()) |
| 4708 | return QualType(); |
| 4709 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4710 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4711 | if (E.isInvalid()) |
| 4712 | return QualType(); |
| 4713 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4714 | QualType Result = TL.getType(); |
| 4715 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4716 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4717 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4718 | if (Result.isNull()) |
| 4719 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4720 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4721 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4722 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4723 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4724 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4725 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4726 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4727 | |
| 4728 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4729 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4730 | |
| 4731 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4732 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4733 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4734 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4735 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4736 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4737 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4738 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4739 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4740 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4741 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4742 | if (Result.isNull()) |
| 4743 | return QualType(); |
| 4744 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4745 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4746 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4747 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4748 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4749 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4750 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4751 | |
| 4752 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4754 | |
| 4755 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4756 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4757 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4758 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4759 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4760 | // decltype expressions are not potentially evaluated contexts |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4761 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4762 | nullptr, /*IsDecltype=*/ true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4763 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4764 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4765 | if (E.isInvalid()) |
| 4766 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4767 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4768 | E = getSema().ActOnDecltypeExpression(E.get()); |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4769 | if (E.isInvalid()) |
| 4770 | return QualType(); |
| 4771 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4772 | QualType Result = TL.getType(); |
| 4773 | if (getDerived().AlwaysRebuild() || |
| 4774 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4775 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4776 | if (Result.isNull()) |
| 4777 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4778 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4779 | else E.get(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4780 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4781 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4782 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4783 | |
| 4784 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4788 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4789 | TypeLocBuilder &TLB, |
| 4790 | UnaryTransformTypeLoc TL) { |
| 4791 | QualType Result = TL.getType(); |
| 4792 | if (Result->isDependentType()) { |
| 4793 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4794 | QualType NewBase = |
| 4795 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4796 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4797 | T->getUTTKind(), |
| 4798 | TL.getKWLoc()); |
| 4799 | if (Result.isNull()) |
| 4800 | return QualType(); |
| 4801 | } |
| 4802 | |
| 4803 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4804 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4805 | NewTL.setParensRange(TL.getParensRange()); |
| 4806 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4807 | return Result; |
| 4808 | } |
| 4809 | |
| 4810 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4811 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4812 | AutoTypeLoc TL) { |
| 4813 | const AutoType *T = TL.getTypePtr(); |
| 4814 | QualType OldDeduced = T->getDeducedType(); |
| 4815 | QualType NewDeduced; |
| 4816 | if (!OldDeduced.isNull()) { |
| 4817 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4818 | if (NewDeduced.isNull()) |
| 4819 | return QualType(); |
| 4820 | } |
| 4821 | |
| 4822 | QualType Result = TL.getType(); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 4823 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 4824 | T->isDependentType()) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 4825 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4826 | if (Result.isNull()) |
| 4827 | return QualType(); |
| 4828 | } |
| 4829 | |
| 4830 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4831 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4832 | |
| 4833 | return Result; |
| 4834 | } |
| 4835 | |
| 4836 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4837 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4838 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4839 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4840 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4841 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4842 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4843 | if (!Record) |
| 4844 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4845 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4846 | QualType Result = TL.getType(); |
| 4847 | if (getDerived().AlwaysRebuild() || |
| 4848 | Record != T->getDecl()) { |
| 4849 | Result = getDerived().RebuildRecordType(Record); |
| 4850 | if (Result.isNull()) |
| 4851 | return QualType(); |
| 4852 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4853 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4854 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4855 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4856 | |
| 4857 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4858 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4859 | |
| 4860 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4861 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4862 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4863 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4864 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4865 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4866 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4867 | if (!Enum) |
| 4868 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4869 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4870 | QualType Result = TL.getType(); |
| 4871 | if (getDerived().AlwaysRebuild() || |
| 4872 | Enum != T->getDecl()) { |
| 4873 | Result = getDerived().RebuildEnumType(Enum); |
| 4874 | if (Result.isNull()) |
| 4875 | return QualType(); |
| 4876 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4877 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4878 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4879 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4880 | |
| 4881 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4882 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4883 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4884 | template<typename Derived> |
| 4885 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4886 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4887 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4888 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4889 | TL.getTypePtr()->getDecl()); |
| 4890 | if (!D) return QualType(); |
| 4891 | |
| 4892 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4893 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4894 | return T; |
| 4895 | } |
| 4896 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4897 | template<typename Derived> |
| 4898 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4899 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4900 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4901 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4902 | } |
| 4903 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4905 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4906 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4907 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4908 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4909 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4910 | // Substitute into the replacement type, which itself might involve something |
| 4911 | // that needs to be transformed. This only tends to occur with default |
| 4912 | // template arguments of template template parameters. |
| 4913 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4914 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4915 | if (Replacement.isNull()) |
| 4916 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4917 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4918 | // Always canonicalize the replacement type. |
| 4919 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4920 | QualType Result |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4921 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4922 | Replacement); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4923 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4924 | // Propagate type-source information. |
| 4925 | SubstTemplateTypeParmTypeLoc NewTL |
| 4926 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4927 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4928 | return Result; |
| 4929 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4933 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4934 | TypeLocBuilder &TLB, |
| 4935 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4936 | return TransformTypeSpecType(TLB, TL); |
| 4937 | } |
| 4938 | |
| 4939 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4940 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4941 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4942 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4943 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4944 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4945 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4946 | // because we can't have a dependent nested-name-specifier anyway. |
| 4947 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4948 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4949 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4950 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4951 | if (Template.isNull()) |
| 4952 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4953 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4954 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4955 | } |
| 4956 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4957 | template<typename Derived> |
| 4958 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4959 | AtomicTypeLoc TL) { |
| 4960 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4961 | if (ValueType.isNull()) |
| 4962 | return QualType(); |
| 4963 | |
| 4964 | QualType Result = TL.getType(); |
| 4965 | if (getDerived().AlwaysRebuild() || |
| 4966 | ValueType != TL.getValueLoc().getType()) { |
| 4967 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4968 | if (Result.isNull()) |
| 4969 | return QualType(); |
| 4970 | } |
| 4971 | |
| 4972 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4973 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4974 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4975 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4976 | |
| 4977 | return Result; |
| 4978 | } |
| 4979 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4980 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4981 | /// container that provides a \c getArgLoc() member function. |
| 4982 | /// |
| 4983 | /// This iterator is intended to be used with the iterator form of |
| 4984 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4985 | template<typename ArgLocContainer> |
| 4986 | class TemplateArgumentLocContainerIterator { |
| 4987 | ArgLocContainer *Container; |
| 4988 | unsigned Index; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4989 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4990 | public: |
| 4991 | typedef TemplateArgumentLoc value_type; |
| 4992 | typedef TemplateArgumentLoc reference; |
| 4993 | typedef int difference_type; |
| 4994 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4995 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4996 | class pointer { |
| 4997 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4998 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4999 | public: |
| 5000 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5001 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5002 | const TemplateArgumentLoc *operator->() const { |
| 5003 | return &Arg; |
| 5004 | } |
| 5005 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5006 | |
| 5007 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5008 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5009 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5010 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 5011 | unsigned Index) |
| 5012 | : Container(&Container), Index(Index) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5013 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5014 | TemplateArgumentLocContainerIterator &operator++() { |
| 5015 | ++Index; |
| 5016 | return *this; |
| 5017 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5018 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5019 | TemplateArgumentLocContainerIterator operator++(int) { |
| 5020 | TemplateArgumentLocContainerIterator Old(*this); |
| 5021 | ++(*this); |
| 5022 | return Old; |
| 5023 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5024 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5025 | TemplateArgumentLoc operator*() const { |
| 5026 | return Container->getArgLoc(Index); |
| 5027 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5028 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5029 | pointer operator->() const { |
| 5030 | return pointer(Container->getArgLoc(Index)); |
| 5031 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5032 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5033 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5034 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5035 | return X.Container == Y.Container && X.Index == Y.Index; |
| 5036 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5037 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5038 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5039 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5040 | return !(X == Y); |
| 5041 | } |
| 5042 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5043 | |
| 5044 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5045 | template <typename Derived> |
| 5046 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 5047 | TypeLocBuilder &TLB, |
| 5048 | TemplateSpecializationTypeLoc TL, |
| 5049 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5050 | TemplateArgumentListInfo NewTemplateArgs; |
| 5051 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5052 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5053 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 5054 | ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5055 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5056 | ArgIterator(TL, TL.getNumArgs()), |
| 5057 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 5058 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5059 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5060 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 5061 | |
| 5062 | QualType Result = |
| 5063 | getDerived().RebuildTemplateSpecializationType(Template, |
| 5064 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5065 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5066 | |
| 5067 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5068 | // Specializations of template template parameters are represented as |
| 5069 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 5070 | // within a dependent context can transform them into |
| 5071 | // DependentTemplateSpecializationTypes. |
| 5072 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5073 | DependentTemplateSpecializationTypeLoc NewTL |
| 5074 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5075 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5076 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5077 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5078 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5079 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5080 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5081 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5082 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5083 | return Result; |
| 5084 | } |
| 5085 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5086 | TemplateSpecializationTypeLoc NewTL |
| 5087 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5088 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5089 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5090 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5091 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5092 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5093 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5094 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5095 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5096 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5098 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5099 | template <typename Derived> |
| 5100 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 5101 | TypeLocBuilder &TLB, |
| 5102 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 5103 | TemplateName Template, |
| 5104 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5105 | TemplateArgumentListInfo NewTemplateArgs; |
| 5106 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5107 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 5108 | typedef TemplateArgumentLocContainerIterator< |
| 5109 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5110 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5111 | ArgIterator(TL, TL.getNumArgs()), |
| 5112 | NewTemplateArgs)) |
| 5113 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5115 | // 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] | 5116 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5117 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 5118 | QualType Result |
| 5119 | = getSema().Context.getDependentTemplateSpecializationType( |
| 5120 | TL.getTypePtr()->getKeyword(), |
| 5121 | DTN->getQualifier(), |
| 5122 | DTN->getIdentifier(), |
| 5123 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5124 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5125 | DependentTemplateSpecializationTypeLoc NewTL |
| 5126 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5127 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5128 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5129 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5130 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5131 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5132 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5133 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5134 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5135 | return Result; |
| 5136 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5137 | |
| 5138 | QualType Result |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5139 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5140 | TL.getTemplateNameLoc(), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5141 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5142 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5143 | if (!Result.isNull()) { |
| 5144 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 5145 | TemplateSpecializationTypeLoc NewTL |
| 5146 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5147 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5148 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5149 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5150 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5151 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5152 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5153 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5154 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5155 | return Result; |
| 5156 | } |
| 5157 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5159 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5160 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5161 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5162 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5163 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5164 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5165 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5166 | if (TL.getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5167 | QualifierLoc |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5168 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5169 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5170 | return QualType(); |
| 5171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5173 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 5174 | if (NamedT.isNull()) |
| 5175 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 5176 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5177 | // C++0x [dcl.type.elab]p2: |
| 5178 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 5179 | // resolves to an alias template specialization, the |
| 5180 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5181 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 5182 | if (const TemplateSpecializationType *TST = |
| 5183 | NamedT->getAs<TemplateSpecializationType>()) { |
| 5184 | TemplateName Template = TST->getTemplateName(); |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 5185 | if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( |
| 5186 | Template.getAsTemplateDecl())) { |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5187 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 5188 | diag::err_tag_reference_non_tag) << 4; |
| 5189 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 5190 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5191 | } |
| 5192 | } |
| 5193 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5194 | QualType Result = TL.getType(); |
| 5195 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5196 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5197 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5198 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5199 | T->getKeyword(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5200 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5201 | if (Result.isNull()) |
| 5202 | return QualType(); |
| 5203 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5204 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5205 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5206 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5207 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5208 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5209 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5210 | |
| 5211 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5212 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5213 | TypeLocBuilder &TLB, |
| 5214 | AttributedTypeLoc TL) { |
| 5215 | const AttributedType *oldType = TL.getTypePtr(); |
| 5216 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5217 | if (modifiedType.isNull()) |
| 5218 | return QualType(); |
| 5219 | |
| 5220 | QualType result = TL.getType(); |
| 5221 | |
| 5222 | // FIXME: dependent operand expressions? |
| 5223 | if (getDerived().AlwaysRebuild() || |
| 5224 | modifiedType != oldType->getModifiedType()) { |
| 5225 | // TODO: this is really lame; we should really be rebuilding the |
| 5226 | // equivalent type from first principles. |
| 5227 | QualType equivalentType |
| 5228 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5229 | if (equivalentType.isNull()) |
| 5230 | return QualType(); |
| 5231 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5232 | modifiedType, |
| 5233 | equivalentType); |
| 5234 | } |
| 5235 | |
| 5236 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5237 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5238 | if (TL.hasAttrOperand()) |
| 5239 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5240 | if (TL.hasAttrExprOperand()) |
| 5241 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5242 | else if (TL.hasAttrEnumOperand()) |
| 5243 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5244 | |
| 5245 | return result; |
| 5246 | } |
| 5247 | |
| 5248 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5249 | QualType |
| 5250 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5251 | ParenTypeLoc TL) { |
| 5252 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5253 | if (Inner.isNull()) |
| 5254 | return QualType(); |
| 5255 | |
| 5256 | QualType Result = TL.getType(); |
| 5257 | if (getDerived().AlwaysRebuild() || |
| 5258 | Inner != TL.getInnerLoc().getType()) { |
| 5259 | Result = getDerived().RebuildParenType(Inner); |
| 5260 | if (Result.isNull()) |
| 5261 | return QualType(); |
| 5262 | } |
| 5263 | |
| 5264 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5265 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5266 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5267 | return Result; |
| 5268 | } |
| 5269 | |
| 5270 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5271 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5272 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5273 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5274 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5275 | NestedNameSpecifierLoc QualifierLoc |
| 5276 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5277 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5278 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5279 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5280 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5281 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5282 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5283 | QualifierLoc, |
| 5284 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5285 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5286 | if (Result.isNull()) |
| 5287 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5288 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5289 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5290 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5291 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5292 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5293 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5294 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5295 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5296 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5297 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5298 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5299 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5300 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5301 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5302 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5303 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5304 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5305 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5306 | QualType TreeTransform<Derived>:: |
| 5307 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5308 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5309 | NestedNameSpecifierLoc QualifierLoc; |
| 5310 | if (TL.getQualifierLoc()) { |
| 5311 | QualifierLoc |
| 5312 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5313 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5314 | return QualType(); |
| 5315 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5316 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5317 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5318 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | template<typename Derived> |
| 5322 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5323 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5324 | DependentTemplateSpecializationTypeLoc TL, |
| 5325 | NestedNameSpecifierLoc QualifierLoc) { |
| 5326 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5327 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5328 | TemplateArgumentListInfo NewTemplateArgs; |
| 5329 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5330 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5331 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5332 | typedef TemplateArgumentLocContainerIterator< |
| 5333 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5334 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5335 | ArgIterator(TL, TL.getNumArgs()), |
| 5336 | NewTemplateArgs)) |
| 5337 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5338 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5339 | QualType Result |
| 5340 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5341 | QualifierLoc, |
| 5342 | T->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5343 | TL.getTemplateNameLoc(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5344 | NewTemplateArgs); |
| 5345 | if (Result.isNull()) |
| 5346 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5347 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5348 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5349 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5350 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5351 | // Copy information relevant to the template specialization. |
| 5352 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5353 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5354 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5355 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5356 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5357 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5358 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5359 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5360 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5361 | // Copy information relevant to the elaborated type. |
| 5362 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5363 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5364 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5365 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5366 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5367 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5368 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5369 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5370 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5371 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5372 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5373 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5374 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5375 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5376 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5377 | TemplateSpecializationTypeLoc SpecTL |
| 5378 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5379 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5380 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5381 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5382 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5383 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5384 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5385 | } |
| 5386 | return Result; |
| 5387 | } |
| 5388 | |
| 5389 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5390 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5391 | PackExpansionTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5392 | QualType Pattern |
| 5393 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5394 | if (Pattern.isNull()) |
| 5395 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5396 | |
| 5397 | QualType Result = TL.getType(); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5398 | if (getDerived().AlwaysRebuild() || |
| 5399 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5400 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5401 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5402 | TL.getEllipsisLoc(), |
| 5403 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5404 | if (Result.isNull()) |
| 5405 | return QualType(); |
| 5406 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5407 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5408 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5409 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5410 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5414 | QualType |
| 5415 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5416 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5417 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5418 | TLB.pushFullCopy(TL); |
| 5419 | return TL.getType(); |
| 5420 | } |
| 5421 | |
| 5422 | template<typename Derived> |
| 5423 | QualType |
| 5424 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5425 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5426 | // ObjCObjectType is never dependent. |
| 5427 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5428 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5430 | |
| 5431 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5432 | QualType |
| 5433 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5434 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5435 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5436 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5437 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5438 | } |
| 5439 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5440 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5441 | // Statement transformation |
| 5442 | //===----------------------------------------------------------------------===// |
| 5443 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5444 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5445 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5446 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5450 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5451 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5452 | return getDerived().TransformCompoundStmt(S, false); |
| 5453 | } |
| 5454 | |
| 5455 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5456 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5457 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5458 | bool IsStmtExpr) { |
Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5459 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5460 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5461 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5462 | bool SubStmtChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5463 | SmallVector<Stmt*, 8> Statements; |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5464 | for (auto *B : S->body()) { |
| 5465 | StmtResult Result = getDerived().TransformStmt(B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5466 | if (Result.isInvalid()) { |
| 5467 | // Immediately fail if this was a DeclStmt, since it's very |
| 5468 | // likely that this will cause problems for future statements. |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5469 | if (isa<DeclStmt>(B)) |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5470 | return StmtError(); |
| 5471 | |
| 5472 | // Otherwise, just keep processing substatements and fail later. |
| 5473 | SubStmtInvalid = true; |
| 5474 | continue; |
| 5475 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | |
Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 5477 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5478 | Statements.push_back(Result.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5480 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5481 | if (SubStmtInvalid) |
| 5482 | return StmtError(); |
| 5483 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5484 | if (!getDerived().AlwaysRebuild() && |
| 5485 | !SubStmtChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5486 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5487 | |
| 5488 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5489 | Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5490 | S->getRBracLoc(), |
| 5491 | IsStmtExpr); |
| 5492 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5494 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5495 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5496 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5497 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5498 | { |
Eli Friedman | 1f4f9dd | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5499 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5500 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5501 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5502 | // Transform the left-hand case value. |
| 5503 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5504 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5505 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5506 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5507 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5508 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5509 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5510 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5511 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5512 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5513 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5514 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5515 | // Build the case statement. |
| 5516 | // Case statements are always rebuilt so that they will attached to their |
| 5517 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5518 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5519 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5520 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5521 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5522 | S->getColonLoc()); |
| 5523 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5524 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5525 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5526 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5527 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5528 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5529 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5531 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5532 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5536 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5537 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5538 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5539 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5540 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5541 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5542 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5543 | // Default statements are always rebuilt |
| 5544 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5545 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5546 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5547 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5548 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5549 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5550 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5551 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5552 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5553 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5554 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5555 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5556 | S->getDecl()); |
| 5557 | if (!LD) |
| 5558 | return StmtError(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5559 | |
| 5560 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5561 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5562 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5563 | cast<LabelDecl>(LD), SourceLocation(), |
| 5564 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5565 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5566 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5567 | template <typename Derived> |
| 5568 | const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 5569 | if (!R) |
| 5570 | return R; |
| 5571 | |
| 5572 | switch (R->getKind()) { |
| 5573 | // Transform attributes with a pragma spelling by calling TransformXXXAttr. |
| 5574 | #define ATTR(X) |
| 5575 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 5576 | case attr::X: \ |
| 5577 | return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 5578 | #include "clang/Basic/AttrList.inc" |
| 5579 | default: |
| 5580 | return R; |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | template <typename Derived> |
| 5585 | StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5586 | bool AttrsChanged = false; |
| 5587 | SmallVector<const Attr *, 1> Attrs; |
| 5588 | |
| 5589 | // Visit attributes and keep track if any are transformed. |
| 5590 | for (const auto *I : S->getAttrs()) { |
| 5591 | const Attr *R = getDerived().TransformAttr(I); |
| 5592 | AttrsChanged |= (I != R); |
| 5593 | Attrs.push_back(R); |
| 5594 | } |
| 5595 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5596 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5597 | if (SubStmt.isInvalid()) |
| 5598 | return StmtError(); |
| 5599 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5600 | if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5601 | return S; |
| 5602 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 5603 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5604 | SubStmt.get()); |
| 5605 | } |
| 5606 | |
| 5607 | template<typename Derived> |
| 5608 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5609 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5610 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5611 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5612 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5613 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5614 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5615 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5616 | getDerived().TransformDefinition( |
| 5617 | S->getConditionVariable()->getLocation(), |
| 5618 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5619 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5620 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5621 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5622 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5623 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5624 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5625 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5626 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5627 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5628 | if (S->getCond()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5629 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5630 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5631 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5632 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5633 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5634 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5635 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5636 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5637 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5638 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5639 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5640 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5641 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5642 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5643 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5644 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5645 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5646 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5647 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5648 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5649 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5650 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5651 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5652 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5653 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5654 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5655 | Then.get() == S->getThen() && |
| 5656 | Else.get() == S->getElse()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5657 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5659 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5660 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5661 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5665 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5666 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5667 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5668 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5669 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5670 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5671 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5672 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5673 | getDerived().TransformDefinition( |
| 5674 | S->getConditionVariable()->getLocation(), |
| 5675 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5676 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5677 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5678 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5679 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5680 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5681 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5682 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5683 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5684 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5685 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5686 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5687 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5688 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5689 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5690 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5691 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5692 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5693 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5694 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5695 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5696 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5697 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5698 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5699 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5701 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5702 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5703 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5704 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5705 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5706 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5707 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5708 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5709 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5710 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5711 | getDerived().TransformDefinition( |
| 5712 | S->getConditionVariable()->getLocation(), |
| 5713 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5714 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5715 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5716 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5717 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5718 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5719 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5720 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5721 | |
| 5722 | if (S->getCond()) { |
| 5723 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5724 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 5725 | S->getWhileLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5726 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5727 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5728 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5729 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5730 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5732 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5733 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5734 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5735 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5736 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5737 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5738 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5739 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5740 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5741 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5742 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5743 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5744 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5745 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5746 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5747 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5748 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5749 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5750 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5751 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5752 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5753 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5754 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5755 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5756 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5757 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5758 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5759 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5760 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5761 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5762 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5763 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5764 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5765 | if (!getDerived().AlwaysRebuild() && |
| 5766 | Cond.get() == S->getCond() && |
| 5767 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5768 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5769 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5770 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5771 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5772 | S->getRParenLoc()); |
| 5773 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5774 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5775 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5776 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5777 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5778 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5779 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5780 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5781 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5782 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5783 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5784 | ExprResult Cond; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5785 | VarDecl *ConditionVar = nullptr; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5786 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5787 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5788 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5789 | getDerived().TransformDefinition( |
| 5790 | S->getConditionVariable()->getLocation(), |
| 5791 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5792 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5793 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5794 | } else { |
| 5795 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5796 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5797 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5798 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5799 | |
| 5800 | if (S->getCond()) { |
| 5801 | // Convert the condition to a boolean value. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5802 | ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, |
| 5803 | S->getForLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5804 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5805 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5806 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5807 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5808 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5809 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5811 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5812 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5813 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5814 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5815 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5816 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5817 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5818 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5819 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5820 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 5821 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5822 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5823 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5824 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5825 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5826 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5827 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5828 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5829 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5830 | if (!getDerived().AlwaysRebuild() && |
| 5831 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5832 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5833 | Inc.get() == S->getInc() && |
| 5834 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5835 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5836 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5837 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5838 | Init.get(), FullCond, ConditionVar, |
| 5839 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5843 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5844 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5845 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5846 | S->getLabel()); |
| 5847 | if (!LD) |
| 5848 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5849 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5850 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5851 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5852 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5856 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5857 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5858 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5859 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5860 | return StmtError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5861 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5862 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5863 | if (!getDerived().AlwaysRebuild() && |
| 5864 | Target.get() == S->getTarget()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5865 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5866 | |
| 5867 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5868 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5872 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5873 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5874 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5876 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5877 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5878 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5879 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5880 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5881 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5882 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5883 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5884 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5885 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Richard Smith | 3b71752 | 2014-08-21 20:51:13 +0000 | [diff] [blame] | 5886 | ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 5887 | /*NotCopyInit*/false); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5888 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5889 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5890 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5891 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5892 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5893 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5894 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5895 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5896 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5897 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5898 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5899 | bool DeclChanged = false; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5900 | SmallVector<Decl *, 4> Decls; |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 5901 | for (auto *D : S->decls()) { |
| 5902 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5903 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5904 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5905 | |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 5906 | if (Transformed != D) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5907 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5908 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5909 | Decls.push_back(Transformed); |
| 5910 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5911 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5912 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5913 | return S; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5914 | |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 5915 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5916 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5917 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5918 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5919 | StmtResult |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5920 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5921 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5922 | SmallVector<Expr*, 8> Constraints; |
| 5923 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5924 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5925 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5926 | ExprResult AsmString; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5927 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5928 | |
| 5929 | bool ExprsChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5930 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5931 | // Go through the outputs. |
| 5932 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5933 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5934 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5935 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5936 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5937 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5938 | // Transform the output expr. |
| 5939 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5940 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5941 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5942 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5943 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5944 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5945 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5946 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5947 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5948 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5949 | // Go through the inputs. |
| 5950 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5951 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5952 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5953 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5954 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5955 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5956 | // Transform the input expr. |
| 5957 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5958 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5959 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5960 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5961 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5962 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5963 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5964 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5965 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5966 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5967 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5968 | return S; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5969 | |
| 5970 | // Go through the clobbers. |
| 5971 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5972 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5973 | |
| 5974 | // No need to transform the asm string literal. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5975 | AsmString = S->getAsmString(); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5976 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5977 | S->isVolatile(), S->getNumOutputs(), |
| 5978 | S->getNumInputs(), Names.data(), |
| 5979 | Constraints, Exprs, AsmString.get(), |
| 5980 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5981 | } |
| 5982 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5983 | template<typename Derived> |
| 5984 | StmtResult |
| 5985 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5986 | ArrayRef<Token> AsmToks = |
| 5987 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5988 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5989 | bool HadError = false, HadChange = false; |
| 5990 | |
| 5991 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 5992 | SmallVector<Expr*, 8> TransformedExprs; |
| 5993 | TransformedExprs.reserve(SrcExprs.size()); |
| 5994 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 5995 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 5996 | if (!Result.isUsable()) { |
| 5997 | HadError = true; |
| 5998 | } else { |
| 5999 | HadChange |= (Result.get() != SrcExprs[i]); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6000 | TransformedExprs.push_back(Result.get()); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6001 | } |
| 6002 | } |
| 6003 | |
| 6004 | if (HadError) return StmtError(); |
| 6005 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 6006 | return Owned(S); |
| 6007 | |
Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 6008 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6009 | AsmToks, S->getAsmString(), |
| 6010 | S->getNumOutputs(), S->getNumInputs(), |
| 6011 | S->getAllConstraints(), S->getClobbers(), |
| 6012 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6013 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6014 | |
| 6015 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6016 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6017 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6018 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6019 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6020 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6021 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6022 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6023 | // Transform the @catch statements (if present). |
| 6024 | bool AnyCatchChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6025 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6026 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6027 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6028 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6029 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6030 | if (Catch.get() != S->getCatchStmt(I)) |
| 6031 | AnyCatchChanged = true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6032 | CatchStmts.push_back(Catch.get()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6033 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6034 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6035 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6036 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6037 | if (S->getFinallyStmt()) { |
| 6038 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 6039 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6040 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | // If nothing changed, just retain this statement. |
| 6044 | if (!getDerived().AlwaysRebuild() && |
| 6045 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 6046 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6047 | Finally.get() == S->getFinallyStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6048 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6049 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6050 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6051 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6052 | CatchStmts, Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6053 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6054 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6055 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6056 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6057 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6058 | // Transform the @catch parameter, if there is one. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6059 | VarDecl *Var = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6060 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6061 | TypeSourceInfo *TSInfo = nullptr; |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6062 | if (FromVar->getTypeSourceInfo()) { |
| 6063 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 6064 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6065 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6066 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6067 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6068 | QualType T; |
| 6069 | if (TSInfo) |
| 6070 | T = TSInfo->getType(); |
| 6071 | else { |
| 6072 | T = getDerived().TransformType(FromVar->getType()); |
| 6073 | if (T.isNull()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6074 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6075 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6076 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6077 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 6078 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6079 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6080 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6081 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6082 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6083 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6084 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6085 | |
| 6086 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 6087 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6088 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6090 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6091 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6092 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6093 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6094 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6095 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6096 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6097 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6098 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6099 | // If nothing changed, just retain this statement. |
| 6100 | if (!getDerived().AlwaysRebuild() && |
| 6101 | Body.get() == S->getFinallyBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6102 | return S; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 6103 | |
| 6104 | // Build a new statement. |
| 6105 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6106 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6107 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6108 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6109 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6110 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6111 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6112 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6113 | if (S->getThrowExpr()) { |
| 6114 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 6115 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6116 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6117 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6118 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 6119 | if (!getDerived().AlwaysRebuild() && |
| 6120 | Operand.get() == S->getThrowExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6121 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6122 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6123 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6125 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6126 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6127 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6128 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6129 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6130 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6131 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6132 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6133 | return StmtError(); |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 6134 | Object = |
| 6135 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 6136 | Object.get()); |
| 6137 | if (Object.isInvalid()) |
| 6138 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6139 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6140 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6141 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6142 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6143 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6144 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6145 | // If nothing change, just retain the current statement. |
| 6146 | if (!getDerived().AlwaysRebuild() && |
| 6147 | Object.get() == S->getSynchExpr() && |
| 6148 | Body.get() == S->getSynchBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6149 | return S; |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 6150 | |
| 6151 | // Build a new statement. |
| 6152 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6153 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6154 | } |
| 6155 | |
| 6156 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6157 | StmtResult |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6158 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 6159 | ObjCAutoreleasePoolStmt *S) { |
| 6160 | // Transform the body. |
| 6161 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 6162 | if (Body.isInvalid()) |
| 6163 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6164 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6165 | // If nothing changed, just retain this statement. |
| 6166 | if (!getDerived().AlwaysRebuild() && |
| 6167 | Body.get() == S->getSubStmt()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6168 | return S; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 6169 | |
| 6170 | // Build a new statement. |
| 6171 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 6172 | S->getAtLoc(), Body.get()); |
| 6173 | } |
| 6174 | |
| 6175 | template<typename Derived> |
| 6176 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6177 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6178 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6179 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6180 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6181 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6182 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6183 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6184 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6185 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6186 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6187 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6188 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6189 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6190 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6191 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6192 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6193 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6194 | // If nothing changed, just retain this statement. |
| 6195 | if (!getDerived().AlwaysRebuild() && |
| 6196 | Element.get() == S->getElement() && |
| 6197 | Collection.get() == S->getCollection() && |
| 6198 | Body.get() == S->getBody()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6199 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6200 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6201 | // Build a new statement. |
| 6202 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6203 | Element.get(), |
| 6204 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6205 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6206 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6207 | } |
| 6208 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6209 | template <typename Derived> |
| 6210 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6211 | // Transform the exception declaration, if any. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6212 | VarDecl *Var = nullptr; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6213 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 6214 | TypeSourceInfo *T = |
| 6215 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 6216 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6217 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6218 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6219 | Var = getDerived().RebuildExceptionDecl( |
| 6220 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 6221 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6222 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6223 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6224 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6225 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6226 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6227 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6228 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6229 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6230 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6231 | if (!getDerived().AlwaysRebuild() && !Var && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6232 | Handler.get() == S->getHandlerBlock()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6233 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6234 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6235 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6236 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6237 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6238 | template <typename Derived> |
| 6239 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6240 | // Transform the try block itself. |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6241 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6242 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6243 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6244 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6245 | // Transform the handlers. |
| 6246 | bool HandlerChanged = false; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6247 | SmallVector<Stmt *, 8> Handlers; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6248 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6249 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6250 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6251 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6252 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6253 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6254 | Handlers.push_back(Handler.getAs<Stmt>()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6255 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6256 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6257 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6258 | !HandlerChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6259 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6260 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6261 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6262 | Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6264 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6265 | template<typename Derived> |
| 6266 | StmtResult |
| 6267 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6268 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6269 | if (Range.isInvalid()) |
| 6270 | return StmtError(); |
| 6271 | |
| 6272 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6273 | if (BeginEnd.isInvalid()) |
| 6274 | return StmtError(); |
| 6275 | |
| 6276 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6277 | if (Cond.isInvalid()) |
| 6278 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6279 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6280 | Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc()); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6281 | if (Cond.isInvalid()) |
| 6282 | return StmtError(); |
| 6283 | if (Cond.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6284 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6285 | |
| 6286 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6287 | if (Inc.isInvalid()) |
| 6288 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6289 | if (Inc.get()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6290 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6291 | |
| 6292 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6293 | if (LoopVar.isInvalid()) |
| 6294 | return StmtError(); |
| 6295 | |
| 6296 | StmtResult NewStmt = S; |
| 6297 | if (getDerived().AlwaysRebuild() || |
| 6298 | Range.get() != S->getRangeStmt() || |
| 6299 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6300 | Cond.get() != S->getCond() || |
| 6301 | Inc.get() != S->getInc() || |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6302 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6303 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6304 | S->getColonLoc(), Range.get(), |
| 6305 | BeginEnd.get(), Cond.get(), |
| 6306 | Inc.get(), LoopVar.get(), |
| 6307 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6308 | if (NewStmt.isInvalid()) |
| 6309 | return StmtError(); |
| 6310 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6311 | |
| 6312 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6313 | if (Body.isInvalid()) |
| 6314 | return StmtError(); |
| 6315 | |
| 6316 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6317 | // 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] | 6318 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6319 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6320 | S->getColonLoc(), Range.get(), |
| 6321 | BeginEnd.get(), Cond.get(), |
| 6322 | Inc.get(), LoopVar.get(), |
| 6323 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6324 | if (NewStmt.isInvalid()) |
| 6325 | return StmtError(); |
| 6326 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6327 | |
| 6328 | if (NewStmt.get() == S) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6329 | return S; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6330 | |
| 6331 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6332 | } |
| 6333 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6334 | template<typename Derived> |
| 6335 | StmtResult |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6336 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6337 | MSDependentExistsStmt *S) { |
| 6338 | // Transform the nested-name-specifier, if any. |
| 6339 | NestedNameSpecifierLoc QualifierLoc; |
| 6340 | if (S->getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6341 | QualifierLoc |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6342 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6343 | if (!QualifierLoc) |
| 6344 | return StmtError(); |
| 6345 | } |
| 6346 | |
| 6347 | // Transform the declaration name. |
| 6348 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6349 | if (NameInfo.getName()) { |
| 6350 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6351 | if (!NameInfo.getName()) |
| 6352 | return StmtError(); |
| 6353 | } |
| 6354 | |
| 6355 | // Check whether anything changed. |
| 6356 | if (!getDerived().AlwaysRebuild() && |
| 6357 | QualifierLoc == S->getQualifierLoc() && |
| 6358 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6359 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6360 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6361 | // Determine whether this name exists, if we can. |
| 6362 | CXXScopeSpec SS; |
| 6363 | SS.Adopt(QualifierLoc); |
| 6364 | bool Dependent = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6365 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6366 | case Sema::IER_Exists: |
| 6367 | if (S->isIfExists()) |
| 6368 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6369 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6370 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6371 | |
| 6372 | case Sema::IER_DoesNotExist: |
| 6373 | if (S->isIfNotExists()) |
| 6374 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6375 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6376 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6377 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6378 | case Sema::IER_Dependent: |
| 6379 | Dependent = true; |
| 6380 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6381 | |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6382 | case Sema::IER_Error: |
| 6383 | return StmtError(); |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6384 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6385 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6386 | // We need to continue with the instantiation, so do so now. |
| 6387 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6388 | if (SubStmt.isInvalid()) |
| 6389 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6390 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6391 | // If we have resolved the name, just transform to the substatement. |
| 6392 | if (!Dependent) |
| 6393 | return SubStmt; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6394 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6395 | // The name is still dependent, so build a dependent expression again. |
| 6396 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6397 | S->isIfExists(), |
| 6398 | QualifierLoc, |
| 6399 | NameInfo, |
| 6400 | SubStmt.get()); |
| 6401 | } |
| 6402 | |
| 6403 | template<typename Derived> |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6404 | ExprResult |
| 6405 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6406 | NestedNameSpecifierLoc QualifierLoc; |
| 6407 | if (E->getQualifierLoc()) { |
| 6408 | QualifierLoc |
| 6409 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6410 | if (!QualifierLoc) |
| 6411 | return ExprError(); |
| 6412 | } |
| 6413 | |
| 6414 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6415 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6416 | if (!PD) |
| 6417 | return ExprError(); |
| 6418 | |
| 6419 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6420 | if (Base.isInvalid()) |
| 6421 | return ExprError(); |
| 6422 | |
| 6423 | return new (SemaRef.getASTContext()) |
| 6424 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6425 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6426 | QualifierLoc, E->getMemberLoc()); |
| 6427 | } |
| 6428 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6429 | template <typename Derived> |
| 6430 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6431 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6432 | if (TryBlock.isInvalid()) |
| 6433 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6434 | |
| 6435 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6436 | if (Handler.isInvalid()) |
| 6437 | return StmtError(); |
| 6438 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6439 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 6440 | Handler.get() == S->getHandler()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6441 | return S; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6442 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 6443 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 6444 | TryBlock.get(), Handler.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6447 | template <typename Derived> |
| 6448 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6449 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6450 | if (Block.isInvalid()) |
| 6451 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6452 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6453 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6454 | } |
| 6455 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6456 | template <typename Derived> |
| 6457 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6458 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6459 | if (FilterExpr.isInvalid()) |
| 6460 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6461 | |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6462 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6463 | if (Block.isInvalid()) |
| 6464 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6465 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6466 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 6467 | Block.get()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6468 | } |
| 6469 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6470 | template <typename Derived> |
| 6471 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6472 | if (isa<SEHFinallyStmt>(Handler)) |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6473 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6474 | else |
| 6475 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6476 | } |
| 6477 | |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 6478 | template<typename Derived> |
| 6479 | StmtResult |
| 6480 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 6481 | return S; |
| 6482 | } |
| 6483 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6484 | //===----------------------------------------------------------------------===// |
| 6485 | // OpenMP directive transformation |
| 6486 | //===----------------------------------------------------------------------===// |
| 6487 | template <typename Derived> |
| 6488 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 6489 | OMPExecutableDirective *D) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6490 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6491 | // Transform the clauses |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6492 | llvm::SmallVector<OMPClause *, 16> TClauses; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6493 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6494 | TClauses.reserve(Clauses.size()); |
| 6495 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6496 | I != E; ++I) { |
| 6497 | if (*I) { |
| 6498 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6499 | if (Clause) |
| 6500 | TClauses.push_back(Clause); |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6501 | } else { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 6502 | TClauses.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6503 | } |
| 6504 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6505 | StmtResult AssociatedStmt; |
| 6506 | if (D->hasAssociatedStmt()) { |
| 6507 | if (!D->getAssociatedStmt()) { |
| 6508 | return StmtError(); |
| 6509 | } |
| 6510 | AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt()); |
| 6511 | if (AssociatedStmt.isInvalid()) { |
| 6512 | return StmtError(); |
| 6513 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6514 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6515 | if (TClauses.size() != Clauses.size()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6516 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6517 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6518 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6519 | // Transform directive name for 'omp critical' directive. |
| 6520 | DeclarationNameInfo DirName; |
| 6521 | if (D->getDirectiveKind() == OMPD_critical) { |
| 6522 | DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 6523 | DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 6524 | } |
| 6525 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6526 | return getDerived().RebuildOMPExecutableDirective( |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6527 | D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(), |
| 6528 | D->getLocStart(), D->getLocEnd()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6529 | } |
| 6530 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6531 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6532 | StmtResult |
| 6533 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 6534 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6535 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| 6536 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6537 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6538 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6539 | return Res; |
| 6540 | } |
| 6541 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6542 | template <typename Derived> |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6543 | StmtResult |
| 6544 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 6545 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6546 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| 6547 | D->getLocStart()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 6548 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6549 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6550 | return Res; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6551 | } |
| 6552 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6553 | template <typename Derived> |
| 6554 | StmtResult |
| 6555 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 6556 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6557 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| 6558 | D->getLocStart()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6559 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6560 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6561 | return Res; |
| 6562 | } |
| 6563 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6564 | template <typename Derived> |
| 6565 | StmtResult |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 6566 | TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 6567 | DeclarationNameInfo DirName; |
| 6568 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, |
| 6569 | D->getLocStart()); |
| 6570 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6571 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6572 | return Res; |
| 6573 | } |
| 6574 | |
| 6575 | template <typename Derived> |
| 6576 | StmtResult |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6577 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 6578 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6579 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| 6580 | D->getLocStart()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6581 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6582 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6583 | return Res; |
| 6584 | } |
| 6585 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6586 | template <typename Derived> |
| 6587 | StmtResult |
| 6588 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 6589 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6590 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| 6591 | D->getLocStart()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6592 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6593 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6594 | return Res; |
| 6595 | } |
| 6596 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6597 | template <typename Derived> |
| 6598 | StmtResult |
| 6599 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 6600 | DeclarationNameInfo DirName; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6601 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| 6602 | D->getLocStart()); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6603 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6604 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6605 | return Res; |
| 6606 | } |
| 6607 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6608 | template <typename Derived> |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 6609 | StmtResult |
| 6610 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 6611 | DeclarationNameInfo DirName; |
| 6612 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| 6613 | D->getLocStart()); |
| 6614 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6615 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6616 | return Res; |
| 6617 | } |
| 6618 | |
| 6619 | template <typename Derived> |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6620 | StmtResult |
| 6621 | TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 6622 | getDerived().getSema().StartOpenMPDSABlock( |
| 6623 | OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart()); |
| 6624 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6625 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6626 | return Res; |
| 6627 | } |
| 6628 | |
| 6629 | template <typename Derived> |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6630 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 6631 | OMPParallelForDirective *D) { |
| 6632 | DeclarationNameInfo DirName; |
| 6633 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| 6634 | nullptr, D->getLocStart()); |
| 6635 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6636 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6637 | return Res; |
| 6638 | } |
| 6639 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6640 | template <typename Derived> |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 6641 | StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 6642 | OMPParallelForSimdDirective *D) { |
| 6643 | DeclarationNameInfo DirName; |
| 6644 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, |
| 6645 | nullptr, D->getLocStart()); |
| 6646 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6647 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6648 | return Res; |
| 6649 | } |
| 6650 | |
| 6651 | template <typename Derived> |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6652 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 6653 | OMPParallelSectionsDirective *D) { |
| 6654 | DeclarationNameInfo DirName; |
| 6655 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| 6656 | nullptr, D->getLocStart()); |
| 6657 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6658 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6659 | return Res; |
| 6660 | } |
| 6661 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6662 | template <typename Derived> |
| 6663 | StmtResult |
| 6664 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 6665 | DeclarationNameInfo DirName; |
| 6666 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| 6667 | D->getLocStart()); |
| 6668 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6669 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6670 | return Res; |
| 6671 | } |
| 6672 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6673 | template <typename Derived> |
| 6674 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 6675 | OMPTaskyieldDirective *D) { |
| 6676 | DeclarationNameInfo DirName; |
| 6677 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| 6678 | D->getLocStart()); |
| 6679 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6680 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6681 | return Res; |
| 6682 | } |
| 6683 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 6684 | template <typename Derived> |
| 6685 | StmtResult |
| 6686 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 6687 | DeclarationNameInfo DirName; |
| 6688 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| 6689 | D->getLocStart()); |
| 6690 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6691 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6692 | return Res; |
| 6693 | } |
| 6694 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 6695 | template <typename Derived> |
| 6696 | StmtResult |
| 6697 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 6698 | DeclarationNameInfo DirName; |
| 6699 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| 6700 | D->getLocStart()); |
| 6701 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6702 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6703 | return Res; |
| 6704 | } |
| 6705 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6706 | template <typename Derived> |
| 6707 | StmtResult |
| 6708 | TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 6709 | DeclarationNameInfo DirName; |
| 6710 | getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, |
| 6711 | D->getLocStart()); |
| 6712 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6713 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6714 | return Res; |
| 6715 | } |
| 6716 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 6717 | template <typename Derived> |
| 6718 | StmtResult |
| 6719 | TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 6720 | DeclarationNameInfo DirName; |
| 6721 | getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, |
| 6722 | D->getLocStart()); |
| 6723 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6724 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6725 | return Res; |
| 6726 | } |
| 6727 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6728 | template <typename Derived> |
| 6729 | StmtResult |
| 6730 | TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 6731 | DeclarationNameInfo DirName; |
| 6732 | getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, |
| 6733 | D->getLocStart()); |
| 6734 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6735 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6736 | return Res; |
| 6737 | } |
| 6738 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6739 | template <typename Derived> |
| 6740 | StmtResult |
| 6741 | TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 6742 | DeclarationNameInfo DirName; |
| 6743 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, |
| 6744 | D->getLocStart()); |
| 6745 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6746 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6747 | return Res; |
| 6748 | } |
| 6749 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6750 | template <typename Derived> |
| 6751 | StmtResult |
| 6752 | TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 6753 | DeclarationNameInfo DirName; |
| 6754 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, |
| 6755 | D->getLocStart()); |
| 6756 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 6757 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 6758 | return Res; |
| 6759 | } |
| 6760 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6761 | //===----------------------------------------------------------------------===// |
| 6762 | // OpenMP clause transformation |
| 6763 | //===----------------------------------------------------------------------===// |
| 6764 | template <typename Derived> |
| 6765 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 6766 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 6767 | if (Cond.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6768 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6769 | return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(), |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6770 | C->getLParenLoc(), C->getLocEnd()); |
| 6771 | } |
| 6772 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6773 | template <typename Derived> |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6774 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 6775 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 6776 | if (Cond.isInvalid()) |
| 6777 | return nullptr; |
| 6778 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(), |
| 6779 | C->getLParenLoc(), C->getLocEnd()); |
| 6780 | } |
| 6781 | |
| 6782 | template <typename Derived> |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6783 | OMPClause * |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6784 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 6785 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 6786 | if (NumThreads.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6787 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6788 | return getDerived().RebuildOMPNumThreadsClause( |
| 6789 | NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6790 | } |
| 6791 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6792 | template <typename Derived> |
| 6793 | OMPClause * |
| 6794 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 6795 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 6796 | if (E.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6797 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6798 | return getDerived().RebuildOMPSafelenClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6799 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6800 | } |
| 6801 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6802 | template <typename Derived> |
| 6803 | OMPClause * |
| 6804 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 6805 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 6806 | if (E.isInvalid()) |
| 6807 | return 0; |
| 6808 | return getDerived().RebuildOMPCollapseClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6809 | E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6810 | } |
| 6811 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6812 | template <typename Derived> |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6813 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6814 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6815 | return getDerived().RebuildOMPDefaultClause( |
| 6816 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(), |
| 6817 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6818 | } |
| 6819 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6820 | template <typename Derived> |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6821 | OMPClause * |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6822 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6823 | return getDerived().RebuildOMPProcBindClause( |
| 6824 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(), |
| 6825 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6826 | } |
| 6827 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6828 | template <typename Derived> |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6829 | OMPClause * |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6830 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 6831 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 6832 | if (E.isInvalid()) |
| 6833 | return nullptr; |
| 6834 | return getDerived().RebuildOMPScheduleClause( |
| 6835 | C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(), |
| 6836 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd()); |
| 6837 | } |
| 6838 | |
| 6839 | template <typename Derived> |
| 6840 | OMPClause * |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6841 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
| 6842 | // No need to rebuild this clause, no template-dependent parameters. |
| 6843 | return C; |
| 6844 | } |
| 6845 | |
| 6846 | template <typename Derived> |
| 6847 | OMPClause * |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6848 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 6849 | // No need to rebuild this clause, no template-dependent parameters. |
| 6850 | return C; |
| 6851 | } |
| 6852 | |
| 6853 | template <typename Derived> |
| 6854 | OMPClause * |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6855 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 6856 | // No need to rebuild this clause, no template-dependent parameters. |
| 6857 | return C; |
| 6858 | } |
| 6859 | |
| 6860 | template <typename Derived> |
| 6861 | OMPClause * |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6862 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 6863 | // No need to rebuild this clause, no template-dependent parameters. |
| 6864 | return C; |
| 6865 | } |
| 6866 | |
| 6867 | template <typename Derived> |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6868 | OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 6869 | // No need to rebuild this clause, no template-dependent parameters. |
| 6870 | return C; |
| 6871 | } |
| 6872 | |
| 6873 | template <typename Derived> |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6874 | OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 6875 | // No need to rebuild this clause, no template-dependent parameters. |
| 6876 | return C; |
| 6877 | } |
| 6878 | |
| 6879 | template <typename Derived> |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6880 | OMPClause * |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6881 | TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 6882 | // No need to rebuild this clause, no template-dependent parameters. |
| 6883 | return C; |
| 6884 | } |
| 6885 | |
| 6886 | template <typename Derived> |
| 6887 | OMPClause * |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6888 | TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 6889 | // No need to rebuild this clause, no template-dependent parameters. |
| 6890 | return C; |
| 6891 | } |
| 6892 | |
| 6893 | template <typename Derived> |
| 6894 | OMPClause * |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6895 | TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 6896 | // No need to rebuild this clause, no template-dependent parameters. |
| 6897 | return C; |
| 6898 | } |
| 6899 | |
| 6900 | template <typename Derived> |
| 6901 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6902 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6903 | llvm::SmallVector<Expr *, 16> Vars; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6904 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6905 | for (auto *VE : C->varlists()) { |
| 6906 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6907 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6908 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6909 | Vars.push_back(EVar.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6910 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6911 | return getDerived().RebuildOMPPrivateClause( |
| 6912 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6913 | } |
| 6914 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6915 | template <typename Derived> |
| 6916 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 6917 | OMPFirstprivateClause *C) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6918 | llvm::SmallVector<Expr *, 16> Vars; |
| 6919 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6920 | for (auto *VE : C->varlists()) { |
| 6921 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6922 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6923 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6924 | Vars.push_back(EVar.get()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6925 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6926 | return getDerived().RebuildOMPFirstprivateClause( |
| 6927 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6928 | } |
| 6929 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6930 | template <typename Derived> |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6931 | OMPClause * |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6932 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 6933 | llvm::SmallVector<Expr *, 16> Vars; |
| 6934 | Vars.reserve(C->varlist_size()); |
| 6935 | for (auto *VE : C->varlists()) { |
| 6936 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6937 | if (EVar.isInvalid()) |
| 6938 | return nullptr; |
| 6939 | Vars.push_back(EVar.get()); |
| 6940 | } |
| 6941 | return getDerived().RebuildOMPLastprivateClause( |
| 6942 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 6943 | } |
| 6944 | |
| 6945 | template <typename Derived> |
| 6946 | OMPClause * |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6947 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 6948 | llvm::SmallVector<Expr *, 16> Vars; |
| 6949 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 6950 | for (auto *VE : C->varlists()) { |
| 6951 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6952 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6953 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6954 | Vars.push_back(EVar.get()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6955 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6956 | return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(), |
| 6957 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6958 | } |
| 6959 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6960 | template <typename Derived> |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6961 | OMPClause * |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6962 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 6963 | llvm::SmallVector<Expr *, 16> Vars; |
| 6964 | Vars.reserve(C->varlist_size()); |
| 6965 | for (auto *VE : C->varlists()) { |
| 6966 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6967 | if (EVar.isInvalid()) |
| 6968 | return nullptr; |
| 6969 | Vars.push_back(EVar.get()); |
| 6970 | } |
| 6971 | CXXScopeSpec ReductionIdScopeSpec; |
| 6972 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 6973 | |
| 6974 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 6975 | if (NameInfo.getName()) { |
| 6976 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6977 | if (!NameInfo.getName()) |
| 6978 | return nullptr; |
| 6979 | } |
| 6980 | return getDerived().RebuildOMPReductionClause( |
| 6981 | Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(), |
| 6982 | C->getLocEnd(), ReductionIdScopeSpec, NameInfo); |
| 6983 | } |
| 6984 | |
| 6985 | template <typename Derived> |
| 6986 | OMPClause * |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6987 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 6988 | llvm::SmallVector<Expr *, 16> Vars; |
| 6989 | Vars.reserve(C->varlist_size()); |
| 6990 | for (auto *VE : C->varlists()) { |
| 6991 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 6992 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6993 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6994 | Vars.push_back(EVar.get()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6995 | } |
| 6996 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 6997 | if (Step.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 6998 | return nullptr; |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6999 | return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(), |
| 7000 | C->getLParenLoc(), |
| 7001 | C->getColonLoc(), C->getLocEnd()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7002 | } |
| 7003 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7004 | template <typename Derived> |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7005 | OMPClause * |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7006 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 7007 | llvm::SmallVector<Expr *, 16> Vars; |
| 7008 | Vars.reserve(C->varlist_size()); |
| 7009 | for (auto *VE : C->varlists()) { |
| 7010 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7011 | if (EVar.isInvalid()) |
| 7012 | return nullptr; |
| 7013 | Vars.push_back(EVar.get()); |
| 7014 | } |
| 7015 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 7016 | if (Alignment.isInvalid()) |
| 7017 | return nullptr; |
| 7018 | return getDerived().RebuildOMPAlignedClause( |
| 7019 | Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(), |
| 7020 | C->getColonLoc(), C->getLocEnd()); |
| 7021 | } |
| 7022 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7023 | template <typename Derived> |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7024 | OMPClause * |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7025 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 7026 | llvm::SmallVector<Expr *, 16> Vars; |
| 7027 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 7028 | for (auto *VE : C->varlists()) { |
| 7029 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7030 | if (EVar.isInvalid()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7031 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7032 | Vars.push_back(EVar.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7033 | } |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7034 | return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(), |
| 7035 | C->getLParenLoc(), C->getLocEnd()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7036 | } |
| 7037 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7038 | template <typename Derived> |
| 7039 | OMPClause * |
| 7040 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 7041 | llvm::SmallVector<Expr *, 16> Vars; |
| 7042 | Vars.reserve(C->varlist_size()); |
| 7043 | for (auto *VE : C->varlists()) { |
| 7044 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7045 | if (EVar.isInvalid()) |
| 7046 | return nullptr; |
| 7047 | Vars.push_back(EVar.get()); |
| 7048 | } |
| 7049 | return getDerived().RebuildOMPCopyprivateClause( |
| 7050 | Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); |
| 7051 | } |
| 7052 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7053 | template <typename Derived> |
| 7054 | OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 7055 | llvm::SmallVector<Expr *, 16> Vars; |
| 7056 | Vars.reserve(C->varlist_size()); |
| 7057 | for (auto *VE : C->varlists()) { |
| 7058 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 7059 | if (EVar.isInvalid()) |
| 7060 | return nullptr; |
| 7061 | Vars.push_back(EVar.get()); |
| 7062 | } |
| 7063 | return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(), |
| 7064 | C->getLParenLoc(), C->getLocEnd()); |
| 7065 | } |
| 7066 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7067 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7068 | // Expression transformation |
| 7069 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7070 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7071 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7072 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 7073 | if (!E->isTypeDependent()) |
| 7074 | return E; |
| 7075 | |
| 7076 | return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| 7077 | E->getIdentType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7078 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7079 | |
| 7080 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7081 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7082 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7083 | NestedNameSpecifierLoc QualifierLoc; |
| 7084 | if (E->getQualifierLoc()) { |
| 7085 | QualifierLoc |
| 7086 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7087 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7088 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7089 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7090 | |
| 7091 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7092 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7093 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7094 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7095 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7096 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 7097 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 7098 | if (NameInfo.getName()) { |
| 7099 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7100 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7101 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 7102 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7103 | |
| 7104 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7105 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7106 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7107 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7108 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7109 | |
| 7110 | // Mark it referenced in the new context regardless. |
| 7111 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7112 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7113 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7114 | return E; |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 7115 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7116 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7117 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7118 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7119 | TemplateArgs = &TransArgs; |
| 7120 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 7121 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7122 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7123 | E->getNumTemplateArgs(), |
| 7124 | TransArgs)) |
| 7125 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 7126 | } |
| 7127 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7128 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7129 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7131 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7132 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7133 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7134 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7135 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7136 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7137 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7138 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7139 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7140 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7141 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7142 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7143 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7144 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7145 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7146 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7147 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7148 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7150 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7151 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7152 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7153 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7154 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7155 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7156 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7157 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7158 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7159 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7163 | ExprResult |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 7164 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 7165 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 7166 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 7167 | return SemaRef.MaybeBindToTemporary(E); |
| 7168 | } |
| 7169 | |
| 7170 | template<typename Derived> |
| 7171 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7172 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 7173 | ExprResult ControllingExpr = |
| 7174 | getDerived().TransformExpr(E->getControllingExpr()); |
| 7175 | if (ControllingExpr.isInvalid()) |
| 7176 | return ExprError(); |
| 7177 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7178 | SmallVector<Expr *, 4> AssocExprs; |
| 7179 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7180 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 7181 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 7182 | if (TS) { |
| 7183 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 7184 | if (!AssocType) |
| 7185 | return ExprError(); |
| 7186 | AssocTypes.push_back(AssocType); |
| 7187 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7188 | AssocTypes.push_back(nullptr); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7189 | } |
| 7190 | |
| 7191 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 7192 | if (AssocExpr.isInvalid()) |
| 7193 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7194 | AssocExprs.push_back(AssocExpr.get()); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7195 | } |
| 7196 | |
| 7197 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 7198 | E->getDefaultLoc(), |
| 7199 | E->getRParenLoc(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7200 | ControllingExpr.get(), |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 7201 | AssocTypes, |
| 7202 | AssocExprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 7203 | } |
| 7204 | |
| 7205 | template<typename Derived> |
| 7206 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7207 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7208 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7209 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7210 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7211 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7212 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7213 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7214 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7215 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7216 | E->getRParen()); |
| 7217 | } |
| 7218 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7219 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 7220 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 7221 | /// object available. |
| 7222 | template<typename Derived> |
| 7223 | ExprResult |
| 7224 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 7225 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7226 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7227 | else |
| 7228 | return getDerived().TransformExpr(E); |
| 7229 | } |
| 7230 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7231 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7232 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7233 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 7234 | ExprResult SubExpr; |
| 7235 | if (E->getOpcode() == UO_AddrOf) |
| 7236 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 7237 | else |
| 7238 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7239 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7240 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7241 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7242 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7243 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7244 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7245 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 7246 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7247 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7249 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7250 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7251 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7252 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 7253 | // Transform the type. |
| 7254 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7255 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7256 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7257 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7258 | // Transform all of the components into components similar to what the |
| 7259 | // parser uses. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7260 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 7261 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 7262 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7263 | // template code that we don't care. |
| 7264 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7265 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7266 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7267 | SmallVector<Component, 4> Components; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7268 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 7269 | const Node &ON = E->getComponent(I); |
| 7270 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 7271 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 7272 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 7273 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7274 | switch (ON.getKind()) { |
| 7275 | case Node::Array: { |
| 7276 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7277 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7278 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7279 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7280 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7281 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 7282 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7283 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7284 | break; |
| 7285 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7286 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7287 | case Node::Field: |
| 7288 | case Node::Identifier: |
| 7289 | Comp.isBrackets = false; |
| 7290 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 7291 | if (!Comp.U.IdentInfo) |
| 7292 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7293 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7294 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7295 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 7296 | case Node::Base: |
| 7297 | // Will be recomputed during the rebuild. |
| 7298 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7299 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7300 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7301 | Components.push_back(Comp); |
| 7302 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7303 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7304 | // If nothing changed, retain the existing expression. |
| 7305 | if (!getDerived().AlwaysRebuild() && |
| 7306 | Type == E->getTypeSourceInfo() && |
| 7307 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7308 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7309 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 7310 | // Build a new offsetof expression. |
| 7311 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 7312 | Components.data(), Components.size(), |
| 7313 | E->getRParenLoc()); |
| 7314 | } |
| 7315 | |
| 7316 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7317 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7318 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 7319 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 7320 | "opaque value expression requires transformation"); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7321 | return E; |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 7322 | } |
| 7323 | |
| 7324 | template<typename Derived> |
| 7325 | ExprResult |
Kaelyn Takata | e1f49d5 | 2014-10-27 18:07:20 +0000 | [diff] [blame^] | 7326 | TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { |
| 7327 | return E; |
| 7328 | } |
| 7329 | |
| 7330 | template<typename Derived> |
| 7331 | ExprResult |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7332 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 7333 | // Rebuild the syntactic form. The original syntactic form has |
| 7334 | // opaque-value expressions in it, so strip those away and rebuild |
| 7335 | // the result. This is a really awful way of doing this, but the |
| 7336 | // better solution (rebuilding the semantic expressions and |
| 7337 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 7338 | // TreeTransform to not strip away implicit conversions. |
| 7339 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 7340 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7341 | if (result.isInvalid()) return ExprError(); |
| 7342 | |
| 7343 | // If that gives us a pseudo-object result back, the pseudo-object |
| 7344 | // expression must have been an lvalue-to-rvalue conversion which we |
| 7345 | // should reapply. |
| 7346 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7347 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 7348 | |
| 7349 | return result; |
| 7350 | } |
| 7351 | |
| 7352 | template<typename Derived> |
| 7353 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7354 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 7355 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7356 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7357 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7358 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 7359 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7360 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7361 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7362 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 7363 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7364 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7365 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7366 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 7367 | E->getKind(), |
| 7368 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7369 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7370 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7371 | // C++0x [expr.sizeof]p1: |
| 7372 | // The operand is either an expression, which is an unevaluated operand |
| 7373 | // [...] |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7374 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7375 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7376 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 7377 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 7378 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 7379 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 7380 | ExprResult SubExpr; |
| 7381 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 7382 | if (auto *DRE = |
| 7383 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 7384 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 7385 | PE, DRE, false, &RecoveryTSI); |
| 7386 | else |
| 7387 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 7388 | |
| 7389 | if (RecoveryTSI) { |
| 7390 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 7391 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 7392 | } else if (SubExpr.isInvalid()) |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7393 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7394 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 7395 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7396 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7397 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 7398 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 7399 | E->getOperatorLoc(), |
| 7400 | E->getKind(), |
| 7401 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7402 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7403 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7404 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7405 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7406 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7407 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7408 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7409 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7410 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7411 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7412 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7413 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7414 | |
| 7415 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7416 | if (!getDerived().AlwaysRebuild() && |
| 7417 | LHS.get() == E->getLHS() && |
| 7418 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7419 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7420 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7421 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7422 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7423 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7424 | E->getRBracketLoc()); |
| 7425 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7426 | |
| 7427 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7428 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7429 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7430 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7431 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7432 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7433 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7434 | |
| 7435 | // Transform arguments. |
| 7436 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7437 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7438 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7439 | &ArgChanged)) |
| 7440 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7441 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7442 | if (!getDerived().AlwaysRebuild() && |
| 7443 | Callee.get() == E->getCallee() && |
| 7444 | !ArgChanged) |
Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 7445 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7446 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7447 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7448 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7449 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7450 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7451 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7452 | E->getRParenLoc()); |
| 7453 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7454 | |
| 7455 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7456 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7457 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7458 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7459 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7460 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7461 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7462 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7463 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7464 | QualifierLoc |
| 7465 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7466 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7467 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7468 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 7469 | } |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7470 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7471 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 7472 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7473 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 7474 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7475 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7476 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7477 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7478 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 7479 | if (FoundDecl == E->getMemberDecl()) { |
| 7480 | FoundDecl = Member; |
| 7481 | } else { |
| 7482 | FoundDecl = cast_or_null<NamedDecl>( |
| 7483 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 7484 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7485 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7486 | } |
| 7487 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7488 | if (!getDerived().AlwaysRebuild() && |
| 7489 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7490 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7491 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7492 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7493 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7494 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 7495 | // Mark it referenced in the new context regardless. |
| 7496 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7497 | SemaRef.MarkMemberReferenced(E); |
| 7498 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7499 | return E; |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 7500 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7501 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7502 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7503 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7504 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 7505 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7506 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7507 | E->getNumTemplateArgs(), |
| 7508 | TransArgs)) |
| 7509 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7510 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7511 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7512 | // FIXME: Bogus source location for the operator |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7513 | SourceLocation FakeOperatorLoc = |
| 7514 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7515 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7516 | // FIXME: to do this check properly, we will need to preserve the |
| 7517 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7518 | // base (and therefore couldn't do the check) and a |
| 7519 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7520 | NamedDecl *FirstQualifierInScope = nullptr; |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7521 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7522 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7523 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7524 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7525 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7526 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 7527 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 7528 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 7529 | (E->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7530 | ? &TransArgs : nullptr), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7531 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7532 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7533 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7534 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7535 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7536 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7537 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7538 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7539 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7540 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7541 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7542 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7543 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7544 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7545 | if (!getDerived().AlwaysRebuild() && |
| 7546 | LHS.get() == E->getLHS() && |
| 7547 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7548 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7549 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7550 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7551 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7552 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7553 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7554 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7555 | } |
| 7556 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7557 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7558 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7559 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7560 | CompoundAssignOperator *E) { |
| 7561 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7562 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7563 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7564 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7565 | ExprResult TreeTransform<Derived>:: |
| 7566 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 7567 | // Just rebuild the common and RHS expressions and see whether we |
| 7568 | // get any changes. |
| 7569 | |
| 7570 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 7571 | if (commonExpr.isInvalid()) |
| 7572 | return ExprError(); |
| 7573 | |
| 7574 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 7575 | if (rhs.isInvalid()) |
| 7576 | return ExprError(); |
| 7577 | |
| 7578 | if (!getDerived().AlwaysRebuild() && |
| 7579 | commonExpr.get() == e->getCommon() && |
| 7580 | rhs.get() == e->getFalseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7581 | return e; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7582 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7583 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7584 | e->getQuestionLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7585 | nullptr, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7586 | e->getColonLoc(), |
| 7587 | rhs.get()); |
| 7588 | } |
| 7589 | |
| 7590 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7591 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7592 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7593 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7594 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7595 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7596 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7597 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7598 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7599 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7600 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7601 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7602 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7603 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7604 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7605 | if (!getDerived().AlwaysRebuild() && |
| 7606 | Cond.get() == E->getCond() && |
| 7607 | LHS.get() == E->getLHS() && |
| 7608 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7609 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7610 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7611 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 7612 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7613 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 7614 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7615 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7616 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7617 | |
| 7618 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7619 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7620 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 7621 | // Implicit casts are eliminated during transformation, since they |
| 7622 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7623 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7624 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7625 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7626 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7627 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7628 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7629 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7630 | if (!Type) |
| 7631 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7632 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7633 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7634 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7635 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7636 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7638 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7639 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7640 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7641 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7642 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 7643 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7644 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7645 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7646 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7648 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7649 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7650 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7651 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7652 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 7653 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 7654 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7655 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7656 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7657 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7658 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7659 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7660 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7661 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7662 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7663 | Init.get() == E->getInitializer()) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7664 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7665 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 7666 | // Note: the expression type doesn't necessarily match the |
| 7667 | // type-as-written, but that's okay, because it should always be |
| 7668 | // derivable from the initializer. |
| 7669 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 7670 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7671 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7672 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7673 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7674 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7675 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7676 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7677 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7678 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7679 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7680 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7681 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7682 | if (!getDerived().AlwaysRebuild() && |
| 7683 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7684 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7685 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7686 | // FIXME: Bad source location |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7687 | SourceLocation FakeOperatorLoc = |
| 7688 | SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7689 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7690 | E->getAccessorLoc(), |
| 7691 | E->getAccessor()); |
| 7692 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7693 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7694 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7695 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7696 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7697 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7698 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7699 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7700 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7701 | Inits, &InitChanged)) |
| 7702 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7703 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7704 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7705 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7706 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7707 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 7708 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7710 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7711 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7712 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7713 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7714 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7715 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7716 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7717 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7718 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7719 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7720 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7721 | // transform the designators. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7722 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7723 | bool ExprChanged = false; |
| 7724 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 7725 | DEnd = E->designators_end(); |
| 7726 | D != DEnd; ++D) { |
| 7727 | if (D->isFieldDesignator()) { |
| 7728 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 7729 | D->getDotLoc(), |
| 7730 | D->getFieldLoc())); |
| 7731 | continue; |
| 7732 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7733 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7734 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7735 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7736 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7737 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7738 | |
| 7739 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7740 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7741 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7742 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7743 | ArrayExprs.push_back(Index.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7744 | continue; |
| 7745 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7746 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7747 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7748 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7749 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 7750 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7751 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7752 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7753 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7754 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7755 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7756 | |
| 7757 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7758 | End.get(), |
| 7759 | D->getLBracketLoc(), |
| 7760 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7761 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7762 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 7763 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7764 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7765 | ArrayExprs.push_back(Start.get()); |
| 7766 | ArrayExprs.push_back(End.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7768 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7769 | if (!getDerived().AlwaysRebuild() && |
| 7770 | Init.get() == E->getInit() && |
| 7771 | !ExprChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7772 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7773 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7774 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7775 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7776 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7778 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7779 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7780 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7781 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7782 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7783 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7784 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7785 | // FIXME: Will we ever have proper type location here? Will we actually |
| 7786 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7787 | QualType T = getDerived().TransformType(E->getType()); |
| 7788 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7789 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7790 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7791 | if (!getDerived().AlwaysRebuild() && |
| 7792 | T == E->getType()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7793 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7794 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7795 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 7796 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7797 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7798 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7799 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7800 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 7801 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 7802 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7803 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7804 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7805 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7806 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7807 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7808 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7809 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7810 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7811 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7812 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7813 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7814 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7815 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7816 | } |
| 7817 | |
| 7818 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7819 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7820 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7821 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7822 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7823 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 7824 | &ArgumentChanged)) |
| 7825 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7826 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7827 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7828 | Inits, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7829 | E->getRParenLoc()); |
| 7830 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7831 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7832 | /// \brief Transform an address-of-label expression. |
| 7833 | /// |
| 7834 | /// By default, the transformation of an address-of-label expression always |
| 7835 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 7836 | /// the corresponding label statement by semantic analysis. |
| 7837 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7838 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7839 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7840 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 7841 | E->getLabel()); |
| 7842 | if (!LD) |
| 7843 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7844 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7845 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7846 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7847 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7848 | |
| 7849 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7850 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7851 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7852 | SemaRef.ActOnStartStmtExpr(); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7853 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7854 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7855 | if (SubStmt.isInvalid()) { |
| 7856 | SemaRef.ActOnStmtExprError(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7857 | return ExprError(); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7858 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7859 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7860 | if (!getDerived().AlwaysRebuild() && |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7861 | SubStmt.get() == E->getSubStmt()) { |
| 7862 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 7863 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7864 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7865 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7866 | |
| 7867 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7868 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7869 | E->getRParenLoc()); |
| 7870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7871 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7872 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7873 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7874 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7875 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7876 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7877 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7878 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7879 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7880 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7881 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7882 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7883 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7884 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7885 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7886 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7887 | if (!getDerived().AlwaysRebuild() && |
| 7888 | Cond.get() == E->getCond() && |
| 7889 | LHS.get() == E->getLHS() && |
| 7890 | RHS.get() == E->getRHS()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7891 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7892 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7893 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7894 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7895 | E->getRParenLoc()); |
| 7896 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7898 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7899 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7900 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7901 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7902 | } |
| 7903 | |
| 7904 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7905 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7906 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7907 | switch (E->getOperator()) { |
| 7908 | case OO_New: |
| 7909 | case OO_Delete: |
| 7910 | case OO_Array_New: |
| 7911 | case OO_Array_Delete: |
| 7912 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7913 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7914 | case OO_Call: { |
| 7915 | // This is a call to an object's operator(). |
| 7916 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 7917 | |
| 7918 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7919 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7920 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7921 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7922 | |
| 7923 | // FIXME: Poor location information |
Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 7924 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| 7925 | static_cast<Expr *>(Object.get())->getLocEnd()); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7926 | |
| 7927 | // Transform the call arguments. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7928 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7929 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7930 | Args)) |
| 7931 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7932 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7933 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7934 | Args, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7935 | E->getLocEnd()); |
| 7936 | } |
| 7937 | |
| 7938 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 7939 | case OO_##Name: |
| 7940 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 7941 | #include "clang/Basic/OperatorKinds.def" |
| 7942 | case OO_Subscript: |
| 7943 | // Handled below. |
| 7944 | break; |
| 7945 | |
| 7946 | case OO_Conditional: |
| 7947 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7948 | |
| 7949 | case OO_None: |
| 7950 | case NUM_OVERLOADED_OPERATORS: |
| 7951 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7952 | } |
| 7953 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7954 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7955 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7956 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7957 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7958 | ExprResult First; |
| 7959 | if (E->getOperator() == OO_Amp) |
| 7960 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 7961 | else |
| 7962 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7963 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7964 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7965 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7966 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7967 | if (E->getNumArgs() == 2) { |
| 7968 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 7969 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7970 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7973 | if (!getDerived().AlwaysRebuild() && |
| 7974 | Callee.get() == E->getCallee() && |
| 7975 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7976 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7977 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7978 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7979 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7980 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7981 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7982 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 7983 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7984 | Callee.get(), |
| 7985 | First.get(), |
| 7986 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7989 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7990 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7991 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7992 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7993 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7994 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7995 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7996 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7997 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 7998 | // Transform the callee. |
| 7999 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 8000 | if (Callee.isInvalid()) |
| 8001 | return ExprError(); |
| 8002 | |
| 8003 | // Transform exec config. |
| 8004 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 8005 | if (EC.isInvalid()) |
| 8006 | return ExprError(); |
| 8007 | |
| 8008 | // Transform arguments. |
| 8009 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8010 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8011 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8012 | &ArgChanged)) |
| 8013 | return ExprError(); |
| 8014 | |
| 8015 | if (!getDerived().AlwaysRebuild() && |
| 8016 | Callee.get() == E->getCallee() && |
| 8017 | !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8018 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8019 | |
| 8020 | // FIXME: Wrong source location information for the '('. |
| 8021 | SourceLocation FakeLParenLoc |
| 8022 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 8023 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8024 | Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 8025 | E->getRParenLoc(), EC.get()); |
| 8026 | } |
| 8027 | |
| 8028 | template<typename Derived> |
| 8029 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8030 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8031 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8032 | if (!Type) |
| 8033 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8034 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8035 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8036 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8037 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8038 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8039 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8040 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8041 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8042 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8043 | return E; |
Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 8044 | return getDerived().RebuildCXXNamedCastExpr( |
| 8045 | E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 8046 | Type, E->getAngleBrackets().getEnd(), |
| 8047 | // FIXME. this should be '(' location |
| 8048 | E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8051 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8052 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8053 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 8054 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8055 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8056 | |
| 8057 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8058 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8059 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 8060 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8061 | } |
| 8062 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8063 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8064 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8065 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8066 | CXXReinterpretCastExpr *E) { |
| 8067 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8069 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8070 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8071 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8072 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 8073 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8074 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8075 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8076 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8077 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8078 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8079 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8080 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8081 | if (!Type) |
| 8082 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8083 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8084 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 8085 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8086 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8087 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8089 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8090 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8091 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8092 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8093 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 8094 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 8095 | E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8096 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8097 | E->getRParenLoc()); |
| 8098 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8099 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8100 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8101 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8102 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8103 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8104 | TypeSourceInfo *TInfo |
| 8105 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 8106 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8107 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8108 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8109 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8110 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8111 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8112 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8113 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 8114 | E->getLocStart(), |
| 8115 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8116 | E->getLocEnd()); |
| 8117 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8118 | |
Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 8119 | // We don't know whether the subexpression is potentially evaluated until |
| 8120 | // after we perform semantic analysis. We speculatively assume it is |
| 8121 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8122 | // potentially evaluated. |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 8123 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 8124 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8125 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8126 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8127 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8128 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8129 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8130 | if (!getDerived().AlwaysRebuild() && |
| 8131 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8132 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8133 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 8134 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 8135 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8136 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8137 | E->getLocEnd()); |
| 8138 | } |
| 8139 | |
| 8140 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8141 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8142 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 8143 | if (E->isTypeOperand()) { |
| 8144 | TypeSourceInfo *TInfo |
| 8145 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 8146 | if (!TInfo) |
| 8147 | return ExprError(); |
| 8148 | |
| 8149 | if (!getDerived().AlwaysRebuild() && |
| 8150 | TInfo == E->getTypeOperandSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8151 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8152 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 8153 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8154 | E->getLocStart(), |
| 8155 | TInfo, |
| 8156 | E->getLocEnd()); |
| 8157 | } |
| 8158 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8159 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8160 | |
| 8161 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 8162 | if (SubExpr.isInvalid()) |
| 8163 | return ExprError(); |
| 8164 | |
| 8165 | if (!getDerived().AlwaysRebuild() && |
| 8166 | SubExpr.get() == E->getExprOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8167 | return E; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 8168 | |
| 8169 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 8170 | E->getLocStart(), |
| 8171 | SubExpr.get(), |
| 8172 | E->getLocEnd()); |
| 8173 | } |
| 8174 | |
| 8175 | template<typename Derived> |
| 8176 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8177 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8178 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8179 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8180 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8181 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8182 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8183 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8184 | CXXNullPtrLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8185 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8186 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8187 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8188 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8189 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8190 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 8191 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8192 | |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8193 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 8194 | // Make sure that we capture 'this'. |
| 8195 | getSema().CheckCXXThisCapture(E->getLocStart()); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8196 | return E; |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8197 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8198 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 8199 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8200 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8201 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8202 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8203 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8204 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8205 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8206 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8207 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8208 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8209 | if (!getDerived().AlwaysRebuild() && |
| 8210 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8211 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8212 | |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 8213 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 8214 | E->isThrownVariableInScope()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8215 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8216 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8217 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8218 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8219 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8220 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8221 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8222 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8223 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8224 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8225 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 8226 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8227 | Param == E->getParam()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8228 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8229 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 8230 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8231 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8232 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8233 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8234 | ExprResult |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8235 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 8236 | FieldDecl *Field |
| 8237 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 8238 | E->getField())); |
| 8239 | if (!Field) |
| 8240 | return ExprError(); |
| 8241 | |
| 8242 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8243 | return E; |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 8244 | |
| 8245 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 8246 | } |
| 8247 | |
| 8248 | template<typename Derived> |
| 8249 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8250 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 8251 | CXXScalarValueInitExpr *E) { |
| 8252 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8253 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8254 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8255 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8256 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8257 | T == E->getTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8258 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8259 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8260 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8261 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 8262 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8264 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8265 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8266 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8267 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8268 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8269 | TypeSourceInfo *AllocTypeInfo |
| 8270 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 8271 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8272 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8273 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8274 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8275 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8276 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8277 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8278 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8279 | // Transform the placement arguments (if any). |
| 8280 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8281 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8282 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8283 | E->getNumPlacementArgs(), true, |
| 8284 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8285 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8286 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8287 | // Transform the initializer (if any). |
| 8288 | Expr *OldInit = E->getInitializer(); |
| 8289 | ExprResult NewInit; |
| 8290 | if (OldInit) |
Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 8291 | NewInit = getDerived().TransformInitializer(OldInit, true); |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8292 | if (NewInit.isInvalid()) |
| 8293 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8294 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8295 | // Transform new operator and delete operator. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8296 | FunctionDecl *OperatorNew = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8297 | if (E->getOperatorNew()) { |
| 8298 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8299 | getDerived().TransformDecl(E->getLocStart(), |
| 8300 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8301 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8302 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8303 | } |
| 8304 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8305 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8306 | if (E->getOperatorDelete()) { |
| 8307 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8308 | getDerived().TransformDecl(E->getLocStart(), |
| 8309 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8310 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8311 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8312 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8313 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8314 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8315 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8316 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8317 | NewInit.get() == OldInit && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8318 | OperatorNew == E->getOperatorNew() && |
| 8319 | OperatorDelete == E->getOperatorDelete() && |
| 8320 | !ArgumentChanged) { |
| 8321 | // Mark any declarations we need as referenced. |
| 8322 | // FIXME: instantiation-specific. |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8323 | if (OperatorNew) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8324 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8325 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8326 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8327 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8328 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8329 | QualType ElementType |
| 8330 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 8331 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 8332 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 8333 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8334 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 8335 | } |
| 8336 | } |
| 8337 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8338 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8339 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8341 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8342 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8343 | if (!ArraySize.get()) { |
| 8344 | // If no array size was specified, but the new expression was |
| 8345 | // instantiated with an array type (e.g., "new T" where T is |
| 8346 | // instantiated with "int[4]"), extract the outer bound from the |
| 8347 | // array type as our array size. We do this with constant and |
| 8348 | // dependently-sized array types. |
| 8349 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 8350 | if (!ArrayT) { |
| 8351 | // Do nothing |
| 8352 | } else if (const ConstantArrayType *ConsArrayT |
| 8353 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8354 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 8355 | SemaRef.Context.getSizeType(), |
| 8356 | /*FIXME:*/ E->getLocStart()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8357 | AllocType = ConsArrayT->getElementType(); |
| 8358 | } else if (const DependentSizedArrayType *DepArrayT |
| 8359 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 8360 | if (DepArrayT->getSizeExpr()) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8361 | ArraySize = DepArrayT->getSizeExpr(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 8362 | AllocType = DepArrayT->getElementType(); |
| 8363 | } |
| 8364 | } |
| 8365 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8366 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8367 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 8368 | E->isGlobalNew(), |
| 8369 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8370 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8371 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 8372 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8373 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 8374 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8375 | ArraySize.get(), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 8376 | E->getDirectInitRange(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8377 | NewInit.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8378 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8379 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8380 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8381 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8382 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8383 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8384 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8385 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8386 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8387 | // Transform the delete operator, if known. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8388 | FunctionDecl *OperatorDelete = nullptr; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8389 | if (E->getOperatorDelete()) { |
| 8390 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8391 | getDerived().TransformDecl(E->getLocStart(), |
| 8392 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8393 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8394 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8395 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8396 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8397 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8398 | Operand.get() == E->getArgument() && |
| 8399 | OperatorDelete == E->getOperatorDelete()) { |
| 8400 | // Mark any declarations we need as referenced. |
| 8401 | // FIXME: instantiation-specific. |
| 8402 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8403 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8404 | |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8405 | if (!E->getArgument()->isTypeDependent()) { |
| 8406 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 8407 | E->getDestroyedType()); |
| 8408 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 8409 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8410 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8411 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 8412 | } |
| 8413 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8414 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8415 | return E; |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8416 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8417 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8418 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 8419 | E->isGlobalDelete(), |
| 8420 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8421 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8422 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8423 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8424 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8425 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8426 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8427 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8428 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8429 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8430 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8431 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8432 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8433 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8434 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8435 | E->getOperatorLoc(), |
| 8436 | E->isArrow()? tok::arrow : tok::period, |
| 8437 | ObjectTypePtr, |
| 8438 | MayBePseudoDestructor); |
| 8439 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8440 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8441 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8442 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8443 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 8444 | if (QualifierLoc) { |
| 8445 | QualifierLoc |
| 8446 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 8447 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8448 | return ExprError(); |
| 8449 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8450 | CXXScopeSpec SS; |
| 8451 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8452 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8453 | PseudoDestructorTypeStorage Destroyed; |
| 8454 | if (E->getDestroyedTypeInfo()) { |
| 8455 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8456 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8457 | ObjectType, nullptr, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8458 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8459 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8460 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 8461 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8462 | // We aren't likely to be able to resolve the identifier down to a type |
| 8463 | // now anyway, so just retain the identifier. |
| 8464 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 8465 | E->getDestroyedTypeLoc()); |
| 8466 | } else { |
| 8467 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8468 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8469 | *E->getDestroyedTypeIdentifier(), |
| 8470 | E->getDestroyedTypeLoc(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8471 | /*Scope=*/nullptr, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8472 | SS, ObjectTypePtr, |
| 8473 | false); |
| 8474 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8475 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8476 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8477 | Destroyed |
| 8478 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 8479 | E->getDestroyedTypeLoc()); |
| 8480 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8481 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8482 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8483 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 8484 | CXXScopeSpec EmptySS; |
| 8485 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8486 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8487 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8488 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8489 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8490 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8491 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8492 | E->getOperatorLoc(), |
| 8493 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8494 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8495 | ScopeTypeInfo, |
| 8496 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8497 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8498 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8499 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8500 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 8501 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8502 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8503 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8504 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8505 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 8506 | Sema::LookupOrdinaryName); |
| 8507 | |
| 8508 | // Transform all the decls. |
| 8509 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 8510 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8511 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8512 | getDerived().TransformDecl(Old->getNameLoc(), |
| 8513 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8514 | if (!InstD) { |
| 8515 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8516 | // This can happen because of dependent hiding. |
| 8517 | if (isa<UsingShadowDecl>(*I)) |
| 8518 | continue; |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8519 | else { |
| 8520 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8521 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8522 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8523 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8524 | |
| 8525 | // Expand using declarations. |
| 8526 | if (isa<UsingDecl>(InstD)) { |
| 8527 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 8528 | for (auto *I : UD->shadows()) |
| 8529 | R.addDecl(I); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8530 | continue; |
| 8531 | } |
| 8532 | |
| 8533 | R.addDecl(InstD); |
| 8534 | } |
| 8535 | |
| 8536 | // Resolve a kind, but don't do any further analysis. If it's |
| 8537 | // ambiguous, the callee needs to deal with it. |
| 8538 | R.resolveKind(); |
| 8539 | |
| 8540 | // Rebuild the nested-name qualifier, if present. |
| 8541 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8542 | if (Old->getQualifierLoc()) { |
| 8543 | NestedNameSpecifierLoc QualifierLoc |
| 8544 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8545 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8546 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8547 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8548 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8549 | } |
| 8550 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8551 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8552 | CXXRecordDecl *NamingClass |
| 8553 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 8554 | Old->getNameLoc(), |
| 8555 | Old->getNamingClass())); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8556 | if (!NamingClass) { |
| 8557 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8558 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8559 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8560 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8561 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8562 | } |
| 8563 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8564 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8565 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 8566 | // If we have neither explicit template arguments, nor the template keyword, |
| 8567 | // it's a normal declaration name. |
| 8568 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8569 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 8570 | |
| 8571 | // If we have template arguments, rebuild them, then rebuild the |
| 8572 | // templateid expression. |
| 8573 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 8574 | if (Old->hasExplicitTemplateArgs() && |
| 8575 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8576 | Old->getNumTemplateArgs(), |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8577 | TransArgs)) { |
| 8578 | R.clear(); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8579 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 8580 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8581 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8582 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 8583 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8585 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8586 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8587 | ExprResult |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8588 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 8589 | bool ArgChanged = false; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8590 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8591 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 8592 | TypeSourceInfo *From = E->getArg(I); |
| 8593 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 8594 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8595 | TypeLocBuilder TLB; |
| 8596 | TLB.reserve(FromTL.getFullDataSize()); |
| 8597 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 8598 | if (To.isNull()) |
| 8599 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8600 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8601 | if (To == From->getType()) |
| 8602 | Args.push_back(From); |
| 8603 | else { |
| 8604 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8605 | ArgChanged = true; |
| 8606 | } |
| 8607 | continue; |
| 8608 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8609 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8610 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8611 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8612 | // We have a pack expansion. Instantiate it. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 8613 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8614 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 8615 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8616 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8617 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8618 | // Determine whether the set of unexpanded parameter packs can and should |
| 8619 | // be expanded. |
| 8620 | bool Expand = true; |
| 8621 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8622 | Optional<unsigned> OrigNumExpansions = |
| 8623 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 8624 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8625 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 8626 | PatternTL.getSourceRange(), |
| 8627 | Unexpanded, |
| 8628 | Expand, RetainExpansion, |
| 8629 | NumExpansions)) |
| 8630 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8631 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8632 | if (!Expand) { |
| 8633 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8634 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8635 | // expansion. |
| 8636 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8637 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8638 | TypeLocBuilder TLB; |
| 8639 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 8640 | |
| 8641 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8642 | if (To.isNull()) |
| 8643 | return ExprError(); |
| 8644 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8645 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8646 | PatternTL.getSourceRange(), |
| 8647 | ExpansionTL.getEllipsisLoc(), |
| 8648 | NumExpansions); |
| 8649 | if (To.isNull()) |
| 8650 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8651 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8652 | PackExpansionTypeLoc ToExpansionTL |
| 8653 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8654 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8655 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8656 | continue; |
| 8657 | } |
| 8658 | |
| 8659 | // Expand the pack expansion by substituting for each argument in the |
| 8660 | // pack(s). |
| 8661 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8662 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 8663 | TypeLocBuilder TLB; |
| 8664 | TLB.reserve(PatternTL.getFullDataSize()); |
| 8665 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8666 | if (To.isNull()) |
| 8667 | return ExprError(); |
| 8668 | |
Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 8669 | if (To->containsUnexpandedParameterPack()) { |
| 8670 | To = getDerived().RebuildPackExpansionType(To, |
| 8671 | PatternTL.getSourceRange(), |
| 8672 | ExpansionTL.getEllipsisLoc(), |
| 8673 | NumExpansions); |
| 8674 | if (To.isNull()) |
| 8675 | return ExprError(); |
| 8676 | |
| 8677 | PackExpansionTypeLoc ToExpansionTL |
| 8678 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8679 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8680 | } |
| 8681 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8682 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8683 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8684 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8685 | if (!RetainExpansion) |
| 8686 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8687 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8688 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 8689 | // forgetting the partially-substituted parameter pack. |
| 8690 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 8691 | |
| 8692 | TypeLocBuilder TLB; |
| 8693 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8694 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8695 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8696 | if (To.isNull()) |
| 8697 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8698 | |
| 8699 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8700 | PatternTL.getSourceRange(), |
| 8701 | ExpansionTL.getEllipsisLoc(), |
| 8702 | NumExpansions); |
| 8703 | if (To.isNull()) |
| 8704 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8705 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8706 | PackExpansionTypeLoc ToExpansionTL |
| 8707 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8708 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8709 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8710 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8711 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8712 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8713 | return E; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8714 | |
| 8715 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 8716 | E->getLocStart(), |
| 8717 | Args, |
| 8718 | E->getLocEnd()); |
| 8719 | } |
| 8720 | |
| 8721 | template<typename Derived> |
| 8722 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8723 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 8724 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 8725 | if (!T) |
| 8726 | return ExprError(); |
| 8727 | |
| 8728 | if (!getDerived().AlwaysRebuild() && |
| 8729 | T == E->getQueriedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8730 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8731 | |
| 8732 | ExprResult SubExpr; |
| 8733 | { |
| 8734 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8735 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 8736 | if (SubExpr.isInvalid()) |
| 8737 | return ExprError(); |
| 8738 | |
| 8739 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8740 | return E; |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8741 | } |
| 8742 | |
| 8743 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 8744 | E->getLocStart(), |
| 8745 | T, |
| 8746 | SubExpr.get(), |
| 8747 | E->getLocEnd()); |
| 8748 | } |
| 8749 | |
| 8750 | template<typename Derived> |
| 8751 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8752 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 8753 | ExprResult SubExpr; |
| 8754 | { |
| 8755 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8756 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 8757 | if (SubExpr.isInvalid()) |
| 8758 | return ExprError(); |
| 8759 | |
| 8760 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8761 | return E; |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8762 | } |
| 8763 | |
| 8764 | return getDerived().RebuildExpressionTrait( |
| 8765 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 8766 | } |
| 8767 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8768 | template <typename Derived> |
| 8769 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 8770 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 8771 | TypeSourceInfo **RecoveryTSI) { |
| 8772 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 8773 | DRE, AddrTaken, RecoveryTSI); |
| 8774 | |
| 8775 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 8776 | if (!NewDRE.isUsable()) |
| 8777 | return NewDRE; |
| 8778 | |
| 8779 | // We got an expr, wrap it up in parens. |
| 8780 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 8781 | return PE; |
| 8782 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 8783 | PE->getRParen()); |
| 8784 | } |
| 8785 | |
| 8786 | template <typename Derived> |
| 8787 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8788 | DependentScopeDeclRefExpr *E) { |
| 8789 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 8790 | nullptr); |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8791 | } |
| 8792 | |
| 8793 | template<typename Derived> |
| 8794 | ExprResult |
| 8795 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8796 | DependentScopeDeclRefExpr *E, |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8797 | bool IsAddressOfOperand, |
| 8798 | TypeSourceInfo **RecoveryTSI) { |
Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 8799 | assert(E->getQualifierLoc()); |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8800 | NestedNameSpecifierLoc QualifierLoc |
| 8801 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8802 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8803 | return ExprError(); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8804 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8805 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8806 | // TODO: If this is a conversion-function-id, verify that the |
| 8807 | // destination type name (if present) resolves the same way after |
| 8808 | // instantiation as it did in the local scope. |
| 8809 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8810 | DeclarationNameInfo NameInfo |
| 8811 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 8812 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8813 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8814 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8815 | if (!E->hasExplicitTemplateArgs()) { |
| 8816 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8817 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8818 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 8819 | // if name has not changed, DNLoc has not changed either. |
| 8820 | NameInfo.getName() == E->getDeclName()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8821 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8822 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8823 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 8824 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 8825 | IsAddressOfOperand, RecoveryTSI); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 8826 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8827 | |
| 8828 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8829 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8830 | E->getNumTemplateArgs(), |
| 8831 | TransArgs)) |
| 8832 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8833 | |
Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 8834 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 8835 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 8836 | RecoveryTSI); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8837 | } |
| 8838 | |
| 8839 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8840 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8841 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8842 | // CXXConstructExprs other than for list-initialization and |
| 8843 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 8844 | // a 1-argument construction we just transform that argument. |
Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 8845 | if ((E->getNumArgs() == 1 || |
| 8846 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8847 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 8848 | !E->isListInitialization()) |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 8849 | return getDerived().TransformExpr(E->getArg(0)); |
| 8850 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8851 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 8852 | |
| 8853 | QualType T = getDerived().TransformType(E->getType()); |
| 8854 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8855 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8856 | |
| 8857 | CXXConstructorDecl *Constructor |
| 8858 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8859 | getDerived().TransformDecl(E->getLocStart(), |
| 8860 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8861 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8862 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8863 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8864 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8865 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8866 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8867 | &ArgumentChanged)) |
| 8868 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8869 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8870 | if (!getDerived().AlwaysRebuild() && |
| 8871 | T == E->getType() && |
| 8872 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8873 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8874 | // Mark the constructor as referenced. |
| 8875 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8876 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8877 | return E; |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8878 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8879 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 8880 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 8881 | Constructor, E->isElidable(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8882 | Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 8883 | E->hadMultipleCandidates(), |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8884 | E->isListInitialization(), |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 8885 | E->isStdInitListInitialization(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 8886 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 8887 | E->getConstructionKind(), |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 8888 | E->getParenOrBraceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8889 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8891 | /// \brief Transform a C++ temporary-binding expression. |
| 8892 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8893 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 8894 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8895 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8896 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8897 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8898 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8900 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8901 | /// \brief Transform a C++ expression that contains cleanups that should |
| 8902 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8903 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8904 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8905 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8906 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8907 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8908 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8909 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8910 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8911 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8912 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8913 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8914 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8915 | CXXTemporaryObjectExpr *E) { |
| 8916 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8917 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8918 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8920 | CXXConstructorDecl *Constructor |
| 8921 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8922 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8923 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8924 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8925 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8926 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8927 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8928 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8929 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8930 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8931 | &ArgumentChanged)) |
| 8932 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8933 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8934 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8935 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8936 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8937 | !ArgumentChanged) { |
| 8938 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8939 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8940 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8941 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8942 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8943 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8944 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 8945 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8946 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8947 | E->getLocEnd()); |
| 8948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8949 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8950 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8951 | ExprResult |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8952 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8953 | |
| 8954 | // Transform any init-capture expressions before entering the scope of the |
| 8955 | // lambda body, because they are not semantically within that scope. |
| 8956 | SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes; |
| 8957 | InitCaptureExprsAndTypes.resize(E->explicit_capture_end() - |
| 8958 | E->explicit_capture_begin()); |
| 8959 | |
| 8960 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 8961 | CEnd = E->capture_end(); |
| 8962 | C != CEnd; ++C) { |
| 8963 | if (!C->isInitCapture()) |
| 8964 | continue; |
| 8965 | EnterExpressionEvaluationContext EEEC(getSema(), |
| 8966 | Sema::PotentiallyEvaluated); |
| 8967 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 8968 | C->getCapturedVar()->getInit(), |
| 8969 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
| 8970 | |
| 8971 | if (NewExprInitResult.isInvalid()) |
| 8972 | return ExprError(); |
| 8973 | Expr *NewExprInit = NewExprInitResult.get(); |
| 8974 | |
| 8975 | VarDecl *OldVD = C->getCapturedVar(); |
| 8976 | QualType NewInitCaptureType = |
| 8977 | getSema().performLambdaInitCaptureInitialization(C->getLocation(), |
| 8978 | OldVD->getType()->isReferenceType(), OldVD->getIdentifier(), |
| 8979 | NewExprInit); |
| 8980 | NewExprInitResult = NewExprInit; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8981 | InitCaptureExprsAndTypes[C - E->capture_begin()] = |
| 8982 | std::make_pair(NewExprInitResult, NewInitCaptureType); |
| 8983 | |
| 8984 | } |
| 8985 | |
Faisal Vali | 524ca28 | 2013-11-12 01:40:44 +0000 | [diff] [blame] | 8986 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8987 | // Transform the template parameters, and add them to the current |
| 8988 | // instantiation scope. The null case is handled correctly. |
| 8989 | LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList( |
| 8990 | E->getTemplateParameterList()); |
| 8991 | |
| 8992 | // Check to see if the TypeSourceInfo of the call operator needs to |
| 8993 | // be transformed, and if so do the transformation in the |
| 8994 | // CurrentInstantiationScope. |
| 8995 | |
| 8996 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 8997 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 8998 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8999 | TypeSourceInfo *NewCallOpTSI = nullptr; |
| 9000 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9001 | const bool CallOpWasAlreadyTransformed = |
| 9002 | getDerived().AlreadyTransformed(OldCallOpTSI->getType()); |
| 9003 | |
| 9004 | // Use the Old Call Operator's TypeSourceInfo if it is already transformed. |
| 9005 | if (CallOpWasAlreadyTransformed) |
| 9006 | NewCallOpTSI = OldCallOpTSI; |
| 9007 | else { |
| 9008 | // Transform the TypeSourceInfo of the Original Lambda's Call Operator. |
| 9009 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 9010 | // it introduces a mapping of the original to the newly created |
| 9011 | // transformed parameters. |
| 9012 | |
| 9013 | TypeLocBuilder NewCallOpTLBuilder; |
NAKAMURA Takumi | 2322415 | 2014-10-17 12:48:37 +0000 | [diff] [blame] | 9014 | QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder, |
| 9015 | OldCallOpFPTL, |
| 9016 | nullptr, 0); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9017 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 9018 | NewCallOpType); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 9019 | } |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9020 | // Extract the ParmVarDecls from the NewCallOpTSI and add them to |
| 9021 | // the vector below - this will be used to synthesize the |
| 9022 | // NewCallOperator. Additionally, add the parameters of the untransformed |
| 9023 | // lambda call operator to the CurrentInstantiationScope. |
| 9024 | SmallVector<ParmVarDecl *, 4> Params; |
| 9025 | { |
| 9026 | FunctionProtoTypeLoc NewCallOpFPTL = |
| 9027 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>(); |
| 9028 | ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray(); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 9029 | const unsigned NewNumArgs = NewCallOpFPTL.getNumParams(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9030 | |
| 9031 | for (unsigned I = 0; I < NewNumArgs; ++I) { |
| 9032 | // If this call operator's type does not require transformation, |
| 9033 | // the parameters do not get added to the current instantiation scope, |
| 9034 | // - so ADD them! This allows the following to compile when the enclosing |
| 9035 | // template is specialized and the entire lambda expression has to be |
| 9036 | // transformed. |
| 9037 | // template<class T> void foo(T t) { |
| 9038 | // auto L = [](auto a) { |
| 9039 | // auto M = [](char b) { <-- note: non-generic lambda |
| 9040 | // auto N = [](auto c) { |
| 9041 | // int x = sizeof(a); |
| 9042 | // x = sizeof(b); <-- specifically this line |
| 9043 | // x = sizeof(c); |
| 9044 | // }; |
| 9045 | // }; |
| 9046 | // }; |
| 9047 | // } |
| 9048 | // foo('a') |
| 9049 | if (CallOpWasAlreadyTransformed) |
| 9050 | getDerived().transformedLocalDecl(NewParamDeclArray[I], |
| 9051 | NewParamDeclArray[I]); |
| 9052 | // Add to Params array, so these parameters can be used to create |
| 9053 | // the newly transformed call operator. |
| 9054 | Params.push_back(NewParamDeclArray[I]); |
| 9055 | } |
| 9056 | } |
| 9057 | |
| 9058 | if (!NewCallOpTSI) |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9059 | return ExprError(); |
| 9060 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 9061 | // Create the local class that will describe the lambda. |
| 9062 | CXXRecordDecl *Class |
| 9063 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9064 | NewCallOpTSI, |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 9065 | /*KnownDependent=*/false, |
| 9066 | E->getCaptureDefault()); |
| 9067 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 9068 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 9069 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9070 | // Build the call operator. |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9071 | CXXMethodDecl *NewCallOperator |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9072 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9073 | NewCallOpTSI, |
Douglas Gregor | adb376e | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 9074 | E->getCallOperator()->getLocEnd(), |
Richard Smith | 505df23 | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 9075 | Params); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9076 | LSI->CallOperator = NewCallOperator; |
Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 9077 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 9078 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| 9079 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9080 | return getDerived().TransformLambdaScope(E, NewCallOperator, |
| 9081 | InitCaptureExprsAndTypes); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 9082 | } |
| 9083 | |
| 9084 | template<typename Derived> |
| 9085 | ExprResult |
| 9086 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9087 | CXXMethodDecl *CallOperator, |
| 9088 | ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9089 | bool Invalid = false; |
| 9090 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9091 | // Introduce the context of the call operator. |
Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 9092 | Sema::ContextRAII SavedContext(getSema(), CallOperator, |
| 9093 | /*NewThisContext*/false); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9094 | |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 9095 | LambdaScopeInfo *const LSI = getSema().getCurLambda(); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9096 | // Enter the scope of the lambda. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 9097 | getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9098 | E->getCaptureDefault(), |
James Dennett | ddd36ff | 2013-08-09 23:08:25 +0000 | [diff] [blame] | 9099 | E->getCaptureDefaultLoc(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9100 | E->hasExplicitParameters(), |
| 9101 | E->hasExplicitResultType(), |
| 9102 | E->isMutable()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9103 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9104 | // Transform captures. |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9105 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9106 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9107 | CEnd = E->capture_end(); |
| 9108 | C != CEnd; ++C) { |
| 9109 | // When we hit the first implicit capture, tell Sema that we've finished |
| 9110 | // the list of explicit captures. |
| 9111 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 9112 | getSema().finishLambdaExplicitCaptures(LSI); |
| 9113 | FinishedExplicitCaptures = true; |
| 9114 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9115 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9116 | // Capturing 'this' is trivial. |
| 9117 | if (C->capturesThis()) { |
| 9118 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 9119 | continue; |
| 9120 | } |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 9121 | // Captured expression will be recaptured during captured variables |
| 9122 | // rebuilding. |
| 9123 | if (C->capturesVLAType()) |
| 9124 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9125 | |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9126 | // Rebuild init-captures, including the implied field declaration. |
| 9127 | if (C->isInitCapture()) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9128 | |
| 9129 | InitCaptureInfoTy InitExprTypePair = |
| 9130 | InitCaptureExprsAndTypes[C - E->capture_begin()]; |
| 9131 | ExprResult Init = InitExprTypePair.first; |
| 9132 | QualType InitQualType = InitExprTypePair.second; |
| 9133 | if (Init.isInvalid() || InitQualType.isNull()) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9134 | Invalid = true; |
| 9135 | continue; |
| 9136 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9137 | VarDecl *OldVD = C->getCapturedVar(); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9138 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 9139 | OldVD->getLocation(), InitExprTypePair.second, |
| 9140 | OldVD->getIdentifier(), Init.get()); |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9141 | if (!NewVD) |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9142 | Invalid = true; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9143 | else { |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9144 | getDerived().transformedLocalDecl(OldVD, NewVD); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 9145 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 9146 | getSema().buildInitCaptureField(LSI, NewVD); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9147 | continue; |
| 9148 | } |
| 9149 | |
| 9150 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 9151 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9152 | // Determine the capture kind for Sema. |
| 9153 | Sema::TryCaptureKind Kind |
| 9154 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 9155 | : C->getCaptureKind() == LCK_ByCopy |
| 9156 | ? Sema::TryCapture_ExplicitByVal |
| 9157 | : Sema::TryCapture_ExplicitByRef; |
| 9158 | SourceLocation EllipsisLoc; |
| 9159 | if (C->isPackExpansion()) { |
| 9160 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 9161 | bool ShouldExpand = false; |
| 9162 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9163 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9164 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 9165 | C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9166 | Unexpanded, |
| 9167 | ShouldExpand, RetainExpansion, |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 9168 | NumExpansions)) { |
| 9169 | Invalid = true; |
| 9170 | continue; |
| 9171 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9172 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9173 | if (ShouldExpand) { |
| 9174 | // The transform has determined that we should perform an expansion; |
| 9175 | // transform and capture each of the arguments. |
| 9176 | // expansion of the pattern. Do so. |
| 9177 | VarDecl *Pack = C->getCapturedVar(); |
| 9178 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9179 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 9180 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9181 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9182 | Pack)); |
| 9183 | if (!CapturedVar) { |
| 9184 | Invalid = true; |
| 9185 | continue; |
| 9186 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9187 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9188 | // Capture the transformed variable. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9189 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 9190 | } |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9191 | |
| 9192 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 9193 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9194 | continue; |
| 9195 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9196 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 9197 | EllipsisLoc = C->getEllipsisLoc(); |
| 9198 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9199 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9200 | // Transform the captured variable. |
| 9201 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9202 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9203 | C->getCapturedVar())); |
Richard Trieu | b292604 | 2014-09-02 19:32:44 +0000 | [diff] [blame] | 9204 | if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9205 | Invalid = true; |
| 9206 | continue; |
| 9207 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9208 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9209 | // Capture the transformed variable. |
Douglas Gregor | fdf598e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 9210 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9211 | } |
| 9212 | if (!FinishedExplicitCaptures) |
| 9213 | getSema().finishLambdaExplicitCaptures(LSI); |
| 9214 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9215 | |
| 9216 | // Enter a new evaluation context to insulate the lambda from any |
| 9217 | // cleanups from the enclosing full-expression. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9218 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9219 | |
| 9220 | if (Invalid) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9221 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 9222 | /*IsInstantiation=*/true); |
| 9223 | return ExprError(); |
| 9224 | } |
| 9225 | |
| 9226 | // Instantiate the body of the lambda expression. |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9227 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 9228 | if (Body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9229 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr, |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9230 | /*IsInstantiation=*/true); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9231 | return ExprError(); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 9232 | } |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 9233 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9234 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9235 | /*CurScope=*/nullptr, |
| 9236 | /*IsInstantiation=*/true); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 9237 | } |
| 9238 | |
| 9239 | template<typename Derived> |
| 9240 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9241 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9242 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9243 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9244 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9245 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9246 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9247 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9248 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9249 | Args.reserve(E->arg_size()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9250 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9251 | &ArgumentChanged)) |
| 9252 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9253 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9254 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9255 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9256 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9257 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9258 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9259 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 9260 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9261 | E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9262 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9263 | E->getRParenLoc()); |
| 9264 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9265 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9266 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9267 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 9268 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9269 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9270 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9271 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9272 | Expr *OldBase; |
| 9273 | QualType BaseType; |
| 9274 | QualType ObjectType; |
| 9275 | if (!E->isImplicitAccess()) { |
| 9276 | OldBase = E->getBase(); |
| 9277 | Base = getDerived().TransformExpr(OldBase); |
| 9278 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9279 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9280 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9281 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9282 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9283 | bool MayBePseudoDestructor = false; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9284 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9285 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9286 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 9287 | ObjectTy, |
| 9288 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9289 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9290 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9291 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9292 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9293 | BaseType = ((Expr*) Base.get())->getType(); |
| 9294 | } else { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9295 | OldBase = nullptr; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9296 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 9297 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 9298 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9299 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9300 | // Transform the first part of the nested-name-specifier that qualifies |
| 9301 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 9302 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 9303 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9304 | E->getFirstQualifierFoundInScope(), |
| 9305 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9306 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9307 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9308 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9309 | QualifierLoc |
| 9310 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 9311 | ObjectType, |
| 9312 | FirstQualifierInScope); |
| 9313 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9314 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 9315 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9316 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9317 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 9318 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9319 | // TODO: If this is a conversion-function-id, verify that the |
| 9320 | // destination type name (if present) resolves the same way after |
| 9321 | // instantiation as it did in the local scope. |
| 9322 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9323 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9324 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9325 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9326 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9327 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9328 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9329 | // This is a reference to a member without an explicitly-specified |
| 9330 | // template argument list. Optimize for this common case. |
| 9331 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9332 | Base.get() == OldBase && |
| 9333 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9334 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9335 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9336 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9337 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9338 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9339 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9340 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9341 | E->isArrow(), |
| 9342 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9343 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9344 | TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9345 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9346 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9347 | /*TemplateArgs*/nullptr); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9348 | } |
| 9349 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9350 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9351 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9352 | E->getNumTemplateArgs(), |
| 9353 | TransArgs)) |
| 9354 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9355 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9356 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9357 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9358 | E->isArrow(), |
| 9359 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 9360 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9361 | TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 9362 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9363 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9364 | &TransArgs); |
| 9365 | } |
| 9366 | |
| 9367 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9368 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9369 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9370 | // Transform the base of the expression. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9371 | ExprResult Base((Expr*) nullptr); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9372 | QualType BaseType; |
| 9373 | if (!Old->isImplicitAccess()) { |
| 9374 | Base = getDerived().TransformExpr(Old->getBase()); |
| 9375 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9376 | return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9377 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 9378 | Old->isArrow()); |
| 9379 | if (Base.isInvalid()) |
| 9380 | return ExprError(); |
| 9381 | BaseType = Base.get()->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9382 | } else { |
| 9383 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 9384 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9385 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9386 | NestedNameSpecifierLoc QualifierLoc; |
| 9387 | if (Old->getQualifierLoc()) { |
| 9388 | QualifierLoc |
| 9389 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 9390 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9391 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9392 | } |
| 9393 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9394 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 9395 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9396 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9397 | Sema::LookupOrdinaryName); |
| 9398 | |
| 9399 | // Transform all the decls. |
| 9400 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 9401 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9402 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 9403 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 9404 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9405 | if (!InstD) { |
| 9406 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 9407 | // This can happen because of dependent hiding. |
| 9408 | if (isa<UsingShadowDecl>(*I)) |
| 9409 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9410 | else { |
| 9411 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9412 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 9413 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 9414 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9415 | |
| 9416 | // Expand using declarations. |
| 9417 | if (isa<UsingDecl>(InstD)) { |
| 9418 | UsingDecl *UD = cast<UsingDecl>(InstD); |
Aaron Ballman | 91cdc28 | 2014-03-13 18:07:29 +0000 | [diff] [blame] | 9419 | for (auto *I : UD->shadows()) |
| 9420 | R.addDecl(I); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9421 | continue; |
| 9422 | } |
| 9423 | |
| 9424 | R.addDecl(InstD); |
| 9425 | } |
| 9426 | |
| 9427 | R.resolveKind(); |
| 9428 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9429 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 9430 | if (Old->getNamingClass()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9431 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9432 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9433 | Old->getMemberLoc(), |
| 9434 | Old->getNamingClass())); |
| 9435 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9436 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9437 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 9438 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 9439 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9440 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9441 | TemplateArgumentListInfo TransArgs; |
| 9442 | if (Old->hasExplicitTemplateArgs()) { |
| 9443 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 9444 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9445 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 9446 | Old->getNumTemplateArgs(), |
| 9447 | TransArgs)) |
| 9448 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9449 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9450 | |
| 9451 | // FIXME: to do this check properly, we will need to preserve the |
| 9452 | // first-qualifier-in-scope here, just in case we had a dependent |
| 9453 | // base (and therefore couldn't do the check) and a |
| 9454 | // nested-name-qualifier (and therefore could do the lookup). |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9455 | NamedDecl *FirstQualifierInScope = nullptr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9456 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9457 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 9458 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9459 | Old->getOperatorLoc(), |
| 9460 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 9461 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9462 | TemplateKWLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9463 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 9464 | R, |
| 9465 | (Old->hasExplicitTemplateArgs() |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9466 | ? &TransArgs : nullptr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9467 | } |
| 9468 | |
| 9469 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9470 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9471 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Alexis Hunt | 414e3e3 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 9472 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9473 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 9474 | if (SubExpr.isInvalid()) |
| 9475 | return ExprError(); |
| 9476 | |
| 9477 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9478 | return E; |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 9479 | |
| 9480 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 9481 | } |
| 9482 | |
| 9483 | template<typename Derived> |
| 9484 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9485 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9486 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 9487 | if (Pattern.isInvalid()) |
| 9488 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9489 | |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9490 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9491 | return E; |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 9492 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 9493 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 9494 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9495 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9496 | |
| 9497 | template<typename Derived> |
| 9498 | ExprResult |
| 9499 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 9500 | // If E is not value-dependent, then nothing will change when we transform it. |
| 9501 | // Note: This is an instantiation-centric view. |
| 9502 | if (!E->isValueDependent()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9503 | return E; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9504 | |
| 9505 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 9506 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9507 | // so |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9508 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 9509 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 9510 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9511 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9512 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 9513 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 9514 | ShouldExpand, RetainExpansion, |
| 9515 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9516 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9517 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9518 | if (RetainExpansion) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9519 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9520 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9521 | NamedDecl *Pack = E->getPack(); |
| 9522 | if (!ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9523 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9524 | Pack)); |
| 9525 | if (!Pack) |
| 9526 | return ExprError(); |
| 9527 | } |
| 9528 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9529 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9530 | // We now know the length of the parameter pack, so build a new expression |
| 9531 | // that stores that length. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9532 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 9533 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 9534 | NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 9535 | } |
| 9536 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 9537 | template<typename Derived> |
| 9538 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 9539 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 9540 | SubstNonTypeTemplateParmPackExpr *E) { |
| 9541 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9542 | return E; |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 9543 | } |
| 9544 | |
| 9545 | template<typename Derived> |
| 9546 | ExprResult |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 9547 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 9548 | SubstNonTypeTemplateParmExpr *E) { |
| 9549 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9550 | return E; |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 9551 | } |
| 9552 | |
| 9553 | template<typename Derived> |
| 9554 | ExprResult |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 9555 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 9556 | // Default behavior is to do nothing with this transformation. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9557 | return E; |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 9558 | } |
| 9559 | |
| 9560 | template<typename Derived> |
| 9561 | ExprResult |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 9562 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 9563 | MaterializeTemporaryExpr *E) { |
| 9564 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 9565 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9566 | |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 9567 | template<typename Derived> |
| 9568 | ExprResult |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 9569 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 9570 | CXXStdInitializerListExpr *E) { |
| 9571 | return getDerived().TransformExpr(E->getSubExpr()); |
| 9572 | } |
| 9573 | |
| 9574 | template<typename Derived> |
| 9575 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9576 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9577 | return SemaRef.MaybeBindToTemporary(E); |
| 9578 | } |
| 9579 | |
| 9580 | template<typename Derived> |
| 9581 | ExprResult |
| 9582 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9583 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9584 | } |
| 9585 | |
| 9586 | template<typename Derived> |
| 9587 | ExprResult |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 9588 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 9589 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 9590 | if (SubExpr.isInvalid()) |
| 9591 | return ExprError(); |
| 9592 | |
| 9593 | if (!getDerived().AlwaysRebuild() && |
| 9594 | SubExpr.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9595 | return E; |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 9596 | |
| 9597 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9598 | } |
| 9599 | |
| 9600 | template<typename Derived> |
| 9601 | ExprResult |
| 9602 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 9603 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9604 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9605 | bool ArgChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9606 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9607 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 9608 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9609 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9610 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 9611 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9612 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9613 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 9614 | Elements.data(), |
| 9615 | Elements.size()); |
| 9616 | } |
| 9617 | |
| 9618 | template<typename Derived> |
| 9619 | ExprResult |
| 9620 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9621 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9622 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 9623 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9624 | bool ArgChanged = false; |
| 9625 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 9626 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9627 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9628 | if (OrigElement.isPackExpansion()) { |
| 9629 | // This key/value element is a pack expansion. |
| 9630 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 9631 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 9632 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 9633 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 9634 | |
| 9635 | // Determine whether the set of unexpanded parameter packs can |
| 9636 | // and should be expanded. |
| 9637 | bool Expand = true; |
| 9638 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 9639 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 9640 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9641 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 9642 | OrigElement.Value->getLocEnd()); |
| 9643 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 9644 | PatternRange, |
| 9645 | Unexpanded, |
| 9646 | Expand, RetainExpansion, |
| 9647 | NumExpansions)) |
| 9648 | return ExprError(); |
| 9649 | |
| 9650 | if (!Expand) { |
| 9651 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9652 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9653 | // expansion. |
| 9654 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 9655 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9656 | if (Key.isInvalid()) |
| 9657 | return ExprError(); |
| 9658 | |
| 9659 | if (Key.get() != OrigElement.Key) |
| 9660 | ArgChanged = true; |
| 9661 | |
| 9662 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 9663 | if (Value.isInvalid()) |
| 9664 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9665 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9666 | if (Value.get() != OrigElement.Value) |
| 9667 | ArgChanged = true; |
| 9668 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9669 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9670 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 9671 | }; |
| 9672 | Elements.push_back(Expansion); |
| 9673 | continue; |
| 9674 | } |
| 9675 | |
| 9676 | // Record right away that the argument was changed. This needs |
| 9677 | // to happen even if the array expands to nothing. |
| 9678 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9679 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9680 | // The transform has determined that we should perform an elementwise |
| 9681 | // expansion of the pattern. Do so. |
| 9682 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 9683 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 9684 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9685 | if (Key.isInvalid()) |
| 9686 | return ExprError(); |
| 9687 | |
| 9688 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 9689 | if (Value.isInvalid()) |
| 9690 | return ExprError(); |
| 9691 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9692 | ObjCDictionaryElement Element = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9693 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 9694 | }; |
| 9695 | |
| 9696 | // If any unexpanded parameter packs remain, we still have a |
| 9697 | // pack expansion. |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9698 | // FIXME: Can this really happen? |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9699 | if (Key.get()->containsUnexpandedParameterPack() || |
| 9700 | Value.get()->containsUnexpandedParameterPack()) |
| 9701 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9702 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9703 | Elements.push_back(Element); |
| 9704 | } |
| 9705 | |
Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 9706 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 9707 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9708 | // We've finished with this pack expansion. |
| 9709 | continue; |
| 9710 | } |
| 9711 | |
| 9712 | // Transform and check key. |
| 9713 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9714 | if (Key.isInvalid()) |
| 9715 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9716 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9717 | if (Key.get() != OrigElement.Key) |
| 9718 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9719 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9720 | // Transform and check value. |
| 9721 | ExprResult Value |
| 9722 | = getDerived().TransformExpr(OrigElement.Value); |
| 9723 | if (Value.isInvalid()) |
| 9724 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9725 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9726 | if (Value.get() != OrigElement.Value) |
| 9727 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9728 | |
| 9729 | ObjCDictionaryElement Element = { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 9730 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9731 | }; |
| 9732 | Elements.push_back(Element); |
| 9733 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9734 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9735 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 9736 | return SemaRef.MaybeBindToTemporary(E); |
| 9737 | |
| 9738 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 9739 | Elements.data(), |
| 9740 | Elements.size()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9741 | } |
| 9742 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9743 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9744 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9745 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9746 | TypeSourceInfo *EncodedTypeInfo |
| 9747 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 9748 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9749 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9751 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9752 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9753 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9754 | |
| 9755 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9756 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9757 | E->getRParenLoc()); |
| 9758 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9759 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9760 | template<typename Derived> |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9761 | ExprResult TreeTransform<Derived>:: |
| 9762 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 9763 | // This is a kind of implicit conversion, and it needs to get dropped |
| 9764 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 9765 | // do, as well a more specific one: this expression is only valid when |
| 9766 | // it appears *immediately* as an argument expression. |
| 9767 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9768 | } |
| 9769 | |
| 9770 | template<typename Derived> |
| 9771 | ExprResult TreeTransform<Derived>:: |
| 9772 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9773 | TypeSourceInfo *TSInfo |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9774 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9775 | if (!TSInfo) |
| 9776 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9777 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9778 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9779 | if (Result.isInvalid()) |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9780 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9781 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9782 | if (!getDerived().AlwaysRebuild() && |
| 9783 | TSInfo == E->getTypeInfoAsWritten() && |
| 9784 | Result.get() == E->getSubExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9785 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9786 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9787 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9788 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9789 | Result.get()); |
| 9790 | } |
| 9791 | |
| 9792 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9793 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9794 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9795 | // Transform arguments. |
| 9796 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9797 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9798 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9799 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9800 | &ArgChanged)) |
| 9801 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9802 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9803 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 9804 | // Class message: transform the receiver type. |
| 9805 | TypeSourceInfo *ReceiverTypeInfo |
| 9806 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 9807 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9808 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9809 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9810 | // If nothing changed, just retain the existing message send. |
| 9811 | if (!getDerived().AlwaysRebuild() && |
| 9812 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9813 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9814 | |
| 9815 | // Build a new class message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9816 | SmallVector<SourceLocation, 16> SelLocs; |
| 9817 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9818 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 9819 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9820 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9821 | E->getMethodDecl(), |
| 9822 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9823 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9824 | E->getRightLoc()); |
| 9825 | } |
| 9826 | |
| 9827 | // Instance message: transform the receiver |
| 9828 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 9829 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9830 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9831 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 9832 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9833 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9834 | |
| 9835 | // If nothing changed, just retain the existing message send. |
| 9836 | if (!getDerived().AlwaysRebuild() && |
| 9837 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9838 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9839 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9840 | // Build a new instance message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9841 | SmallVector<SourceLocation, 16> SelLocs; |
| 9842 | E->getSelectorLocs(SelLocs); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9843 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9844 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9845 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9846 | E->getMethodDecl(), |
| 9847 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9848 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9849 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9850 | } |
| 9851 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9852 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9853 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9854 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9855 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9856 | } |
| 9857 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9858 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9859 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9860 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9861 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9862 | } |
| 9863 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9864 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9865 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9866 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9867 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9868 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9869 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9870 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9871 | |
| 9872 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9873 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9874 | // If nothing changed, just retain the existing expression. |
| 9875 | if (!getDerived().AlwaysRebuild() && |
| 9876 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9877 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9878 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9879 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9880 | E->getLocation(), |
| 9881 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9882 | } |
| 9883 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9884 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9885 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9886 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9887 | // 'super' and types never change. Property never changes. Just |
| 9888 | // retain the existing expression. |
| 9889 | if (!E->isObjectReceiver()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9890 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9891 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9892 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9893 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9894 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9895 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9896 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9897 | // We don't need to transform the property; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9898 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9899 | // If nothing changed, just retain the existing expression. |
| 9900 | if (!getDerived().AlwaysRebuild() && |
| 9901 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9902 | return E; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9903 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9904 | if (E->isExplicitProperty()) |
| 9905 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 9906 | E->getExplicitProperty(), |
| 9907 | E->getLocation()); |
| 9908 | |
| 9909 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 9910 | SemaRef.Context.PseudoObjectTy, |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9911 | E->getImplicitPropertyGetter(), |
| 9912 | E->getImplicitPropertySetter(), |
| 9913 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9914 | } |
| 9915 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9916 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9917 | ExprResult |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9918 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 9919 | // Transform the base expression. |
| 9920 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 9921 | if (Base.isInvalid()) |
| 9922 | return ExprError(); |
| 9923 | |
| 9924 | // Transform the key expression. |
| 9925 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 9926 | if (Key.isInvalid()) |
| 9927 | return ExprError(); |
| 9928 | |
| 9929 | // If nothing changed, just retain the existing expression. |
| 9930 | if (!getDerived().AlwaysRebuild() && |
| 9931 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9932 | return E; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9933 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9934 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9935 | Base.get(), Key.get(), |
| 9936 | E->getAtIndexMethodDecl(), |
| 9937 | E->setAtIndexMethodDecl()); |
| 9938 | } |
| 9939 | |
| 9940 | template<typename Derived> |
| 9941 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9942 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9943 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9944 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9945 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9946 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9947 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9948 | // If nothing changed, just retain the existing expression. |
| 9949 | if (!getDerived().AlwaysRebuild() && |
| 9950 | Base.get() == E->getBase()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9951 | return E; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9952 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9953 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 9954 | E->getOpLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9955 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9956 | } |
| 9957 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9958 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9959 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9960 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9961 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9962 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9963 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9964 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9965 | SubExprs, &ArgumentChanged)) |
| 9966 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9967 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9968 | if (!getDerived().AlwaysRebuild() && |
| 9969 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9970 | return E; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9971 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9972 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9973 | SubExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9974 | E->getRParenLoc()); |
| 9975 | } |
| 9976 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9977 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9978 | ExprResult |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 9979 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 9980 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 9981 | if (SrcExpr.isInvalid()) |
| 9982 | return ExprError(); |
| 9983 | |
| 9984 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9985 | if (!Type) |
| 9986 | return ExprError(); |
| 9987 | |
| 9988 | if (!getDerived().AlwaysRebuild() && |
| 9989 | Type == E->getTypeSourceInfo() && |
| 9990 | SrcExpr.get() == E->getSrcExpr()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9991 | return E; |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 9992 | |
| 9993 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 9994 | SrcExpr.get(), Type, |
| 9995 | E->getRParenLoc()); |
| 9996 | } |
| 9997 | |
| 9998 | template<typename Derived> |
| 9999 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10000 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10001 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10002 | |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10003 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10004 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 10005 | |
| 10006 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 10007 | blockScope->TheDecl->setBlockMissingReturnType( |
| 10008 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10009 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 10010 | SmallVector<ParmVarDecl*, 4> params; |
| 10011 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10012 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 10013 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10014 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 10015 | oldBlock->param_begin(), |
| 10016 | oldBlock->param_size(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10017 | nullptr, paramTypes, ¶ms)) { |
| 10018 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10019 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10020 | } |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10021 | |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10022 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 10023 | QualType exprResultType = |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 10024 | getDerived().TransformType(exprFunctionType->getReturnType()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 10025 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 10026 | QualType functionType = |
| 10027 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10028 | exprFunctionType->getExtProtoInfo()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10029 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10030 | |
| 10031 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10032 | if (!params.empty()) |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 10033 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 10034 | |
| 10035 | if (!oldBlock->blockMissingReturnType()) { |
| 10036 | blockScope->HasImplicitReturnType = false; |
| 10037 | blockScope->ReturnType = exprResultType; |
| 10038 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10039 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10040 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10041 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10042 | if (body.isInvalid()) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10043 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10044 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 10045 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 10046 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10047 | #ifndef NDEBUG |
| 10048 | // In builds with assertions, make sure that we captured everything we |
| 10049 | // captured before. |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10050 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 10051 | for (const auto &I : oldBlock->captures()) { |
| 10052 | VarDecl *oldCapture = I.getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10053 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10054 | // Ignore parameter packs. |
| 10055 | if (isa<ParmVarDecl>(oldCapture) && |
| 10056 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 10057 | continue; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10058 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 10059 | VarDecl *newCapture = |
| 10060 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 10061 | oldCapture)); |
| 10062 | assert(blockScope->CaptureMap.count(newCapture)); |
| 10063 | } |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10064 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 10065 | } |
| 10066 | #endif |
| 10067 | |
| 10068 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10069 | /*Scope=*/nullptr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10070 | } |
| 10071 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10072 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10073 | ExprResult |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 10074 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 10075 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 10076 | } |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 10077 | |
| 10078 | template<typename Derived> |
| 10079 | ExprResult |
| 10080 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10081 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 10082 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10083 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10084 | SubExprs.reserve(E->getNumSubExprs()); |
| 10085 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 10086 | SubExprs, &ArgumentChanged)) |
| 10087 | return ExprError(); |
| 10088 | |
| 10089 | if (!getDerived().AlwaysRebuild() && |
| 10090 | !ArgumentChanged) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10091 | return E; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10092 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10093 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 10094 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 10095 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10096 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10097 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10098 | // Type reconstruction |
| 10099 | //===----------------------------------------------------------------------===// |
| 10100 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10101 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10102 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 10103 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10104 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10105 | getDerived().getBaseEntity()); |
| 10106 | } |
| 10107 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10108 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10109 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 10110 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10111 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10112 | getDerived().getBaseEntity()); |
| 10113 | } |
| 10114 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10115 | template<typename Derived> |
| 10116 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10117 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 10118 | bool WrittenAsLValue, |
| 10119 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 10120 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10121 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10122 | } |
| 10123 | |
| 10124 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10125 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10126 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 10127 | QualType ClassType, |
| 10128 | SourceLocation Sigil) { |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 10129 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 10130 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10131 | } |
| 10132 | |
| 10133 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10134 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10135 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 10136 | ArrayType::ArraySizeModifier SizeMod, |
| 10137 | const llvm::APInt *Size, |
| 10138 | Expr *SizeExpr, |
| 10139 | unsigned IndexTypeQuals, |
| 10140 | SourceRange BracketsRange) { |
| 10141 | if (SizeExpr || !Size) |
| 10142 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 10143 | IndexTypeQuals, BracketsRange, |
| 10144 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10145 | |
| 10146 | QualType Types[] = { |
| 10147 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 10148 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 10149 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10150 | }; |
Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 10151 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10152 | QualType SizeType; |
| 10153 | for (unsigned I = 0; I != NumTypes; ++I) |
| 10154 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 10155 | SizeType = Types[I]; |
| 10156 | break; |
| 10157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10158 | |
Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 10159 | // Note that we can return a VariableArrayType here in the case where |
| 10160 | // the element type was a dependent VariableArrayType. |
| 10161 | IntegerLiteral *ArraySize |
| 10162 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 10163 | /*FIXME*/BracketsRange.getBegin()); |
| 10164 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10165 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10166 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10168 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10169 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10170 | QualType |
| 10171 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10172 | ArrayType::ArraySizeModifier SizeMod, |
| 10173 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10174 | unsigned IndexTypeQuals, |
| 10175 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10176 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10177 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10178 | } |
| 10179 | |
| 10180 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10181 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10182 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10183 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10184 | unsigned IndexTypeQuals, |
| 10185 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10186 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 10187 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10189 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10190 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10191 | QualType |
| 10192 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10193 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10194 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10195 | unsigned IndexTypeQuals, |
| 10196 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10197 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10198 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10199 | IndexTypeQuals, BracketsRange); |
| 10200 | } |
| 10201 | |
| 10202 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10203 | QualType |
| 10204 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10205 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10206 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10207 | unsigned IndexTypeQuals, |
| 10208 | SourceRange BracketsRange) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10209 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10210 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10211 | IndexTypeQuals, BracketsRange); |
| 10212 | } |
| 10213 | |
| 10214 | template<typename Derived> |
| 10215 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 10216 | unsigned NumElements, |
| 10217 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10218 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 10219 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10220 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10221 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10222 | template<typename Derived> |
| 10223 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 10224 | unsigned NumElements, |
| 10225 | SourceLocation AttributeLoc) { |
| 10226 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 10227 | NumElements, true); |
| 10228 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 10229 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 10230 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10231 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10232 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10233 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10234 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10235 | QualType |
| 10236 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10237 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10238 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10239 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10240 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10241 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10242 | template<typename Derived> |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 10243 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 10244 | QualType T, |
Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 10245 | MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10246 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 10247 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10248 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 10249 | getDerived().getBaseEntity(), |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 10250 | EPI); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10251 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10252 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10253 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 10254 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 10255 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 10256 | } |
| 10257 | |
| 10258 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10259 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 10260 | assert(D && "no decl found"); |
| 10261 | if (D->isInvalidDecl()) return QualType(); |
| 10262 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 10263 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10264 | TypeDecl *Ty; |
| 10265 | if (isa<UsingDecl>(D)) { |
| 10266 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 10267 | assert(Using->hasTypename() && |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10268 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 10269 | |
| 10270 | // A valid resolved using typename decl points to exactly one type decl. |
| 10271 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 10272 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10273 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 10274 | } else { |
| 10275 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 10276 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 10277 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 10278 | } |
| 10279 | |
| 10280 | return SemaRef.Context.getTypeDeclType(Ty); |
| 10281 | } |
| 10282 | |
| 10283 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 10284 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 10285 | SourceLocation Loc) { |
| 10286 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10287 | } |
| 10288 | |
| 10289 | template<typename Derived> |
| 10290 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 10291 | return SemaRef.Context.getTypeOfType(Underlying); |
| 10292 | } |
| 10293 | |
| 10294 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 10295 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 10296 | SourceLocation Loc) { |
| 10297 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10298 | } |
| 10299 | |
| 10300 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 10301 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 10302 | UnaryTransformType::UTTKind UKind, |
| 10303 | SourceLocation Loc) { |
| 10304 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 10305 | } |
| 10306 | |
| 10307 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10308 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 10309 | TemplateName Template, |
| 10310 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 10311 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 10312 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10313 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10314 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 10315 | template<typename Derived> |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 10316 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 10317 | SourceLocation KWLoc) { |
| 10318 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 10319 | } |
| 10320 | |
| 10321 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10322 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10323 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10324 | bool TemplateKW, |
| 10325 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10326 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10327 | Template); |
| 10328 | } |
| 10329 | |
| 10330 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10331 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10332 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 10333 | const IdentifierInfo &Name, |
| 10334 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10335 | QualType ObjectType, |
| 10336 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10337 | UnqualifiedId TemplateName; |
| 10338 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10339 | Sema::TemplateTy Template; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10340 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10341 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10342 | SS, TemplateKWLoc, TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10343 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10344 | /*EnteringContext=*/false, |
| 10345 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10346 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 10347 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10348 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10349 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10350 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10351 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10352 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10353 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10354 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10355 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10356 | // FIXME: Bogus location information. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10357 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 10358 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10359 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10360 | Sema::TemplateTy Template; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10361 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10362 | SS, TemplateKWLoc, Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10363 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 10364 | /*EnteringContext=*/false, |
| 10365 | Template); |
Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 10366 | return Template.get(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10367 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10368 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 10369 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10370 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10371 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 10372 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10373 | Expr *OrigCallee, |
| 10374 | Expr *First, |
| 10375 | Expr *Second) { |
| 10376 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 10377 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10378 | |
Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 10379 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 10380 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 10381 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 10382 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 10383 | First, Second); |
| 10384 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 10385 | if (Result.isInvalid()) |
| 10386 | return ExprError(); |
| 10387 | First = Result.get(); |
| 10388 | } |
| 10389 | |
| 10390 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 10391 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 10392 | if (Result.isInvalid()) |
| 10393 | return ExprError(); |
| 10394 | Second = Result.get(); |
| 10395 | } |
| 10396 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10397 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 10398 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10399 | if (!First->getType()->isOverloadableType() && |
| 10400 | !Second->getType()->isOverloadableType()) |
| 10401 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 10402 | Callee->getLocStart(), |
| 10403 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 10404 | } else if (Op == OO_Arrow) { |
| 10405 | // -> is never a builtin operation. |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10406 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 10407 | } else if (Second == nullptr || isPostIncDec) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10408 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10409 | // The argument is not of overloadable type, so try to create a |
| 10410 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10411 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10412 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10413 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10414 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10415 | } |
| 10416 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10417 | if (!First->getType()->isOverloadableType() && |
| 10418 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10419 | // Neither of the arguments is an overloadable type, so try to |
| 10420 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10421 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10422 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10423 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10424 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10425 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10426 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10427 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10428 | } |
| 10429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10430 | |
| 10431 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10432 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 10433 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10434 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10435 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10436 | assert(ULE->requiresADL()); |
Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 10437 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10438 | } else { |
Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 10439 | // If we've resolved this to a particular non-member function, just call |
| 10440 | // that function. If we resolved it to a member function, |
| 10441 | // CreateOverloaded* will find that function for us. |
| 10442 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 10443 | if (!isa<CXXMethodDecl>(ND)) |
| 10444 | Functions.addDecl(ND); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10445 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10446 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10447 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10448 | Expr *Args[2] = { First, Second }; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10449 | unsigned NumArgs = 1 + (Second != nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10450 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10451 | // Create the overloaded operator invocation for unary operators. |
| 10452 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10453 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10454 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10455 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10456 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10457 | |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 10458 | if (Op == OO_Subscript) { |
| 10459 | SourceLocation LBrace; |
| 10460 | SourceLocation RBrace; |
| 10461 | |
| 10462 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 10463 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 10464 | LBrace = SourceLocation::getFromRawEncoding( |
| 10465 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 10466 | RBrace = SourceLocation::getFromRawEncoding( |
| 10467 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 10468 | } else { |
| 10469 | LBrace = Callee->getLocStart(); |
| 10470 | RBrace = OpLoc; |
| 10471 | } |
| 10472 | |
| 10473 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 10474 | First, Second); |
| 10475 | } |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 10476 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10477 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 10478 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10479 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10480 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 10481 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10482 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10483 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10484 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10485 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10486 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10487 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10488 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10489 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10490 | SourceLocation OperatorLoc, |
| 10491 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10492 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10493 | TypeSourceInfo *ScopeType, |
| 10494 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10495 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10496 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10497 | QualType BaseType = Base->getType(); |
| 10498 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10499 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10500 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 10501 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 10502 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10503 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10504 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10505 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10506 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10507 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10508 | /*FIXME?*/true); |
| 10509 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10510 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10511 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10512 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 10513 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 10514 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 10515 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 10516 | |
Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 10517 | // The scope type is now known to be a valid nested name specifier |
| 10518 | // component. Tack it on to the end of the nested name specifier. |
Alexey Bataev | 2a06681 | 2014-10-16 03:04:35 +0000 | [diff] [blame] | 10519 | if (ScopeType) { |
| 10520 | if (!ScopeType->getType()->getAs<TagType>()) { |
| 10521 | getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 10522 | diag::err_expected_class_or_namespace) |
| 10523 | << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 10524 | return ExprError(); |
| 10525 | } |
| 10526 | SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), |
| 10527 | CCLoc); |
| 10528 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10529 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10530 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10531 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10532 | OperatorLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10533 | SS, TemplateKWLoc, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10534 | /*FIXME: FirstQualifier*/ nullptr, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10535 | NameInfo, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10536 | /*TemplateArgs*/ nullptr); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10537 | } |
| 10538 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 10539 | template<typename Derived> |
| 10540 | StmtResult |
| 10541 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 10542 | SourceLocation Loc = S->getLocStart(); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 10543 | CapturedDecl *CD = S->getCapturedDecl(); |
| 10544 | unsigned NumParams = CD->getNumParams(); |
| 10545 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 10546 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 10547 | for (unsigned I = 0; I < NumParams; ++I) { |
| 10548 | if (I != ContextParamPos) { |
| 10549 | Params.push_back( |
| 10550 | std::make_pair( |
| 10551 | CD->getParam(I)->getName(), |
| 10552 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 10553 | } else { |
| 10554 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 10555 | } |
| 10556 | } |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10557 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 10558 | S->getCapturedRegionKind(), Params); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10559 | StmtResult Body; |
| 10560 | { |
| 10561 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 10562 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 10563 | } |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 10564 | |
| 10565 | if (Body.isInvalid()) { |
| 10566 | getSema().ActOnCapturedRegionError(); |
| 10567 | return StmtError(); |
| 10568 | } |
| 10569 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 10570 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 10571 | } |
| 10572 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 10573 | } // end namespace clang |
| 10574 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 10575 | #endif |