Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | 577f75a | 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 | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 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 | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 16 | |
John McCall | 2d88708 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaInternal.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 18 | #include "clang/Sema/Lookup.h" |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 19 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 20 | #include "clang/Sema/SemaDiagnostic.h" |
John McCall | 781472f | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 21 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
John McCall | 7cd088e | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclObjC.h" |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
| 27 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 28 | #include "clang/AST/Stmt.h" |
| 29 | #include "clang/AST/StmtCXX.h" |
| 30 | #include "clang/AST/StmtObjC.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 31 | #include "clang/Sema/Ownership.h" |
| 32 | #include "clang/Sema/Designator.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 33 | #include "clang/Lex/Preprocessor.h" |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/ArrayRef.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 35 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 7e44e3f | 2010-12-02 00:05:49 +0000 | [diff] [blame] | 36 | #include "TypeLocBuilder.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 37 | #include <algorithm> |
| 38 | |
| 39 | namespace clang { |
John McCall | 781472f | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 40 | using namespace sema; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 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 | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 71 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 9151c11 | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 72 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | 577f75a | 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 | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 78 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 79 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 93 | template<typename Derived> |
| 94 | class TreeTransform { |
Douglas Gregor | d373119 | 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; |
| 101 | |
| 102 | public: |
| 103 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 104 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 105 | } |
| 106 | |
| 107 | ~ForgetPartiallySubstitutedPackRAII() { |
| 108 | Self.RememberPartiallySubstitutedPack(Old); |
| 109 | } |
| 110 | }; |
| 111 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 112 | protected: |
| 113 | Sema &SemaRef; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | dfca6f5 | 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; |
| 119 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | public: |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 121 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 122 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | const Derived &getDerived() const { |
| 129 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | } |
| 131 | |
John McCall | 60d7b3a | 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 | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 134 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Douglas Gregor | 577f75a | 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. |
| 144 | bool AlwaysRebuild() { return false; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 146 | /// \brief Returns the location of the entity being transformed, if that |
| 147 | /// information was not available elsewhere in the AST. |
| 148 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 150 | /// provide an alternative implementation that provides better location |
| 151 | /// information. |
| 152 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 154 | /// \brief Returns the name of the entity being transformed, if that |
| 155 | /// information was not available elsewhere in the AST. |
| 156 | /// |
| 157 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 158 | /// implementation with a more precise name. |
| 159 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 160 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 161 | /// \brief Sets the "base" location and entity when that |
| 162 | /// information is known based on another transformation. |
| 163 | /// |
| 164 | /// By default, the source location and entity are ignored. Subclasses can |
| 165 | /// override this function to provide a customized implementation. |
| 166 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 168 | /// \brief RAII object that temporarily sets the base location and entity |
| 169 | /// used for reporting diagnostics in types. |
| 170 | class TemporaryBase { |
| 171 | TreeTransform &Self; |
| 172 | SourceLocation OldLocation; |
| 173 | DeclarationName OldEntity; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 174 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 175 | public: |
| 176 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 178 | OldLocation = Self.getDerived().getBaseLocation(); |
| 179 | OldEntity = Self.getDerived().getBaseEntity(); |
Douglas Gregor | ae201f7 | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 180 | |
| 181 | if (Location.isValid()) |
| 182 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 183 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 185 | ~TemporaryBase() { |
| 186 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 187 | } |
| 188 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | |
| 190 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 191 | /// transformed. |
| 192 | /// |
| 193 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 195 | /// not change. For example, template instantiation need not traverse |
| 196 | /// non-dependent types. |
| 197 | bool AlreadyTransformed(QualType T) { |
| 198 | return T.isNull(); |
| 199 | } |
| 200 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 201 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 202 | /// because it is a default argument. |
| 203 | /// |
| 204 | /// Subclasses can provide an alternative implementation of this routine to |
| 205 | /// determine which kinds of call arguments get dropped. By default, |
| 206 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 207 | bool DropCallArgument(Expr *E) { |
| 208 | return E->isDefaultArgument(); |
| 209 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 210 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 211 | /// \brief Determine whether we should expand a pack expansion with the |
| 212 | /// given set of parameter packs into separate arguments by repeatedly |
| 213 | /// transforming the pattern. |
| 214 | /// |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 215 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 216 | /// Subclasses can override this routine to provide different behavior. |
| 217 | /// |
| 218 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 219 | /// pack expansion. |
| 220 | /// |
| 221 | /// \param PatternRange The source range that covers the entire pattern of |
| 222 | /// the pack expansion. |
| 223 | /// |
| 224 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 225 | /// pattern. |
| 226 | /// |
| 227 | /// \param NumUnexpanded The number of unexpanded parameter packs in |
| 228 | /// \p Unexpanded. |
| 229 | /// |
| 230 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 231 | /// expand the corresponding pack expansions into separate arguments. When |
| 232 | /// set, \c NumExpansions must also be set. |
| 233 | /// |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 234 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 235 | /// pack expansion after all of the expanded arguments. This is used |
| 236 | /// when extending explicitly-specified template argument packs per |
| 237 | /// C++0x [temp.arg.explicit]p9. |
| 238 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 239 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 240 | /// the expanded form of the corresponding pack expansion. This is both an |
| 241 | /// input and an output parameter, which can be set by the caller if the |
| 242 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 243 | /// and will be set by the callee when the number of expansions is known. |
| 244 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 245 | /// set this value in other cases. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 246 | /// |
| 247 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 248 | /// are to be instantiated with arguments of different lengths), false |
| 249 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 250 | /// must be set. |
| 251 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 252 | SourceRange PatternRange, |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 253 | llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 254 | bool &ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 255 | bool &RetainExpansion, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 256 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 257 | ShouldExpand = false; |
| 258 | return false; |
| 259 | } |
| 260 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 261 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 262 | /// when performing an instantiation that must preserve the parameter pack |
| 263 | /// use. |
| 264 | /// |
| 265 | /// This routine is meant to be overridden by the template instantiator. |
| 266 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 267 | return TemplateArgument(); |
| 268 | } |
| 269 | |
| 270 | /// \brief "Remember" the partially-substituted pack template argument |
| 271 | /// after performing an instantiation that must preserve the parameter pack |
| 272 | /// use. |
| 273 | /// |
| 274 | /// This routine is meant to be overridden by the template instantiator. |
| 275 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 276 | |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 277 | /// \brief Note to the derived class when a function parameter pack is |
| 278 | /// being expanded. |
| 279 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 280 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 281 | /// \brief Transforms the given type into another type. |
| 282 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 283 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 284 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 285 | /// function. This is expensive, but we don't mind, because |
| 286 | /// this method is deprecated anyway; all users should be |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 287 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 288 | /// |
| 289 | /// \returns the transformed type. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 290 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 292 | /// \brief Transforms the given type-with-location into a new |
| 293 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 294 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 295 | /// By default, this routine transforms a type by delegating to the |
| 296 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 297 | /// may override this function (to take over all type |
| 298 | /// transformations) or some set of the TransformXXXType functions |
| 299 | /// to alter the transformation. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 300 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 301 | |
| 302 | /// \brief Transform the given type-with-location into a new |
| 303 | /// type, collecting location information in the given builder |
| 304 | /// as necessary. |
| 305 | /// |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 306 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 308 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 309 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 311 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 312 | /// statement or the TransformExpr() function to transform an expression. |
| 313 | /// Subclasses may override this function to transform statements using some |
| 314 | /// other mechanism. |
| 315 | /// |
| 316 | /// \returns the transformed statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 317 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 318 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 319 | /// \brief Transform the given expression. |
| 320 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 321 | /// By default, this routine transforms an expression by delegating to the |
| 322 | /// appropriate TransformXXXExpr function to build a new expression. |
| 323 | /// Subclasses may override this function to transform expressions using some |
| 324 | /// other mechanism. |
| 325 | /// |
| 326 | /// \returns the transformed expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 327 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 328 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 329 | /// \brief Transform the given list of expressions. |
| 330 | /// |
| 331 | /// This routine transforms a list of expressions by invoking |
| 332 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 333 | /// support for variadic templates by expanding any pack expansions (if the |
| 334 | /// derived class permits such expansion) along the way. When pack expansions |
| 335 | /// are present, the number of outputs may not equal the number of inputs. |
| 336 | /// |
| 337 | /// \param Inputs The set of expressions to be transformed. |
| 338 | /// |
| 339 | /// \param NumInputs The number of expressions in \c Inputs. |
| 340 | /// |
| 341 | /// \param IsCall If \c true, then this transform is being performed on |
| 342 | /// function-call arguments, and any arguments that should be dropped, will |
| 343 | /// be. |
| 344 | /// |
| 345 | /// \param Outputs The transformed input expressions will be added to this |
| 346 | /// vector. |
| 347 | /// |
| 348 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 349 | /// due to transformation. |
| 350 | /// |
| 351 | /// \returns true if an error occurred, false otherwise. |
| 352 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 353 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 354 | bool *ArgChanged = 0); |
| 355 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 356 | /// \brief Transform the given declaration, which is referenced from a type |
| 357 | /// or expression. |
| 358 | /// |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 359 | /// By default, acts as the identity function on declarations, unless the |
| 360 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 361 | /// may override this function to provide alternate behavior. |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 362 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
| 363 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 364 | = TransformedLocalDecls.find(D); |
| 365 | if (Known != TransformedLocalDecls.end()) |
| 366 | return Known->second; |
| 367 | |
| 368 | return D; |
| 369 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 370 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 371 | /// \brief Transform the attributes associated with the given declaration and |
| 372 | /// place them on the new declaration. |
| 373 | /// |
| 374 | /// By default, this operation does nothing. Subclasses may override this |
| 375 | /// behavior to transform attributes. |
| 376 | void transformAttrs(Decl *Old, Decl *New) { } |
| 377 | |
| 378 | /// \brief Note that a local declaration has been transformed by this |
| 379 | /// transformer. |
| 380 | /// |
| 381 | /// Local declarations are typically transformed via a call to |
| 382 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 383 | /// the transformer itself has to transform the declarations. This routine |
| 384 | /// can be overridden by a subclass that keeps track of such mappings. |
| 385 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 386 | TransformedLocalDecls[Old] = New; |
| 387 | } |
| 388 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 389 | /// \brief Transform the definition of the given declaration. |
| 390 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 392 | /// Subclasses may override this function to provide alternate behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 393 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 394 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 395 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 397 | /// \brief Transform the given declaration, which was the first part of a |
| 398 | /// nested-name-specifier in a member access expression. |
| 399 | /// |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 400 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 401 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 402 | /// the \c T in \c x->T::member |
| 403 | /// |
| 404 | /// By default, invokes TransformDecl() to transform the declaration. |
| 405 | /// Subclasses may override this function to provide alternate behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 406 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 407 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 408 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 409 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 410 | /// \brief Transform the given nested-name-specifier with source-location |
| 411 | /// information. |
| 412 | /// |
| 413 | /// By default, transforms all of the types and declarations within the |
| 414 | /// nested-name-specifier. Subclasses may override this function to provide |
| 415 | /// alternate behavior. |
| 416 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 417 | NestedNameSpecifierLoc NNS, |
| 418 | QualType ObjectType = QualType(), |
| 419 | NamedDecl *FirstQualifierInScope = 0); |
| 420 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 421 | /// \brief Transform the given declaration name. |
| 422 | /// |
| 423 | /// By default, transforms the types of conversion function, constructor, |
| 424 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 425 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 426 | /// override this function to provide alternate behavior. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 427 | DeclarationNameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 428 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 430 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 431 | /// |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 432 | /// \param SS The nested-name-specifier that qualifies the template |
| 433 | /// name. This nested-name-specifier must already have been transformed. |
| 434 | /// |
| 435 | /// \param Name The template name to transform. |
| 436 | /// |
| 437 | /// \param NameLoc The source location of the template name. |
| 438 | /// |
| 439 | /// \param ObjectType If we're translating a template name within a member |
| 440 | /// access expression, this is the type of the object whose member template |
| 441 | /// is being referenced. |
| 442 | /// |
| 443 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 444 | /// also refers to a name within the current (lexical) scope, this is the |
| 445 | /// declaration it refers to. |
| 446 | /// |
| 447 | /// By default, transforms the template name by transforming the declarations |
| 448 | /// and nested-name-specifiers that occur within the template name. |
| 449 | /// Subclasses may override this function to provide alternate behavior. |
| 450 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 451 | TemplateName Name, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 452 | SourceLocation NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 453 | QualType ObjectType = QualType(), |
| 454 | NamedDecl *FirstQualifierInScope = 0); |
| 455 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | /// \brief Transform the given template argument. |
| 457 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | /// By default, this operation transforms the type, expression, or |
| 459 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 460 | /// new template argument from the transformed result. Subclasses may |
| 461 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 462 | /// |
| 463 | /// Returns true if there was an error. |
| 464 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 465 | TemplateArgumentLoc &Output); |
| 466 | |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 467 | /// \brief Transform the given set of template arguments. |
| 468 | /// |
| 469 | /// By default, this operation transforms all of the template arguments |
| 470 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 471 | /// the transformed arguments to the output list. |
| 472 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 473 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 474 | /// a convenience function. Subclasses that wish to override this behavior |
| 475 | /// should override the iterator-based member template version. |
| 476 | /// |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 477 | /// \param Inputs The set of template arguments to be transformed. |
| 478 | /// |
| 479 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 480 | /// |
| 481 | /// \param Outputs The set of transformed template arguments output by this |
| 482 | /// routine. |
| 483 | /// |
| 484 | /// Returns true if an error occurred. |
| 485 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 486 | unsigned NumInputs, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 487 | TemplateArgumentListInfo &Outputs) { |
| 488 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 489 | } |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 490 | |
| 491 | /// \brief Transform the given set of template arguments. |
| 492 | /// |
| 493 | /// By default, this operation transforms all of the template arguments |
| 494 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 495 | /// the transformed arguments to the output list. |
| 496 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 497 | /// \param First An iterator to the first template argument. |
| 498 | /// |
| 499 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 500 | /// |
| 501 | /// \param Outputs The set of transformed template arguments output by this |
| 502 | /// routine. |
| 503 | /// |
| 504 | /// Returns true if an error occurred. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 505 | template<typename InputIterator> |
| 506 | bool TransformTemplateArguments(InputIterator First, |
| 507 | InputIterator Last, |
| 508 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 509 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 510 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 511 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 512 | TemplateArgumentLoc &ArgLoc); |
| 513 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 514 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 515 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 516 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 517 | getDerived().getBaseLocation()); |
| 518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 520 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 521 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 522 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 523 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 524 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 525 | StmtResult |
| 526 | TransformSEHHandler(Stmt *Handler); |
| 527 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 528 | QualType |
| 529 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 530 | TemplateSpecializationTypeLoc TL, |
| 531 | TemplateName Template); |
| 532 | |
| 533 | QualType |
| 534 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 535 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 536 | TemplateName Template, |
| 537 | CXXScopeSpec &SS); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 538 | |
| 539 | QualType |
| 540 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 541 | DependentTemplateSpecializationTypeLoc TL, |
| 542 | NestedNameSpecifierLoc QualifierLoc); |
| 543 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 544 | /// \brief Transforms the parameters of a function type into the |
| 545 | /// given vectors. |
| 546 | /// |
| 547 | /// The result vectors should be kept in sync; null entries in the |
| 548 | /// variables vector are acceptable. |
| 549 | /// |
| 550 | /// Return true on error. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 551 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 552 | ParmVarDecl **Params, unsigned NumParams, |
| 553 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 554 | SmallVectorImpl<QualType> &PTypes, |
| 555 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 556 | |
| 557 | /// \brief Transforms a single function-type parameter. Return null |
| 558 | /// on error. |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 559 | /// |
| 560 | /// \param indexAdjustment - A number to add to the parameter's |
| 561 | /// scope index; can be negative |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 562 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 563 | int indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 564 | llvm::Optional<unsigned> NumExpansions, |
| 565 | bool ExpectParameterPack); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 566 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 567 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 568 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 569 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 570 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 571 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 572 | #define STMT(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 573 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 574 | #define EXPR(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 575 | ExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 576 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 577 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 579 | /// \brief Build a new pointer type given its pointee type. |
| 580 | /// |
| 581 | /// By default, performs semantic analysis when building the pointer type. |
| 582 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 583 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 584 | |
| 585 | /// \brief Build a new block pointer type given its pointee type. |
| 586 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 587 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 588 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 589 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 590 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 591 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 592 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 593 | /// By default, performs semantic analysis when building the |
| 594 | /// reference type. Subclasses may override this routine to provide |
| 595 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 596 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 597 | /// \param LValue whether the type was written with an lvalue sigil |
| 598 | /// or an rvalue sigil. |
| 599 | QualType RebuildReferenceType(QualType ReferentType, |
| 600 | bool LValue, |
| 601 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 602 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 603 | /// \brief Build a new member pointer type given the pointee type and the |
| 604 | /// class type it refers into. |
| 605 | /// |
| 606 | /// By default, performs semantic analysis when building the member pointer |
| 607 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 608 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 609 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 610 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 611 | /// \brief Build a new array type given the element type, size |
| 612 | /// modifier, size of the array (if known), size expression, and index type |
| 613 | /// qualifiers. |
| 614 | /// |
| 615 | /// By default, performs semantic analysis when building the array type. |
| 616 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 617 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 618 | QualType RebuildArrayType(QualType ElementType, |
| 619 | ArrayType::ArraySizeModifier SizeMod, |
| 620 | const llvm::APInt *Size, |
| 621 | Expr *SizeExpr, |
| 622 | unsigned IndexTypeQuals, |
| 623 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 624 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 625 | /// \brief Build a new constant array type given the element type, size |
| 626 | /// modifier, (known) size of the array, and index type qualifiers. |
| 627 | /// |
| 628 | /// By default, performs semantic analysis when building the array type. |
| 629 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 630 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 631 | ArrayType::ArraySizeModifier SizeMod, |
| 632 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 633 | unsigned IndexTypeQuals, |
| 634 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 636 | /// \brief Build a new incomplete array type given the element type, size |
| 637 | /// modifier, and index type qualifiers. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis when building the array type. |
| 640 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 642 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 643 | unsigned IndexTypeQuals, |
| 644 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 645 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 647 | /// size modifier, size expression, and index type qualifiers. |
| 648 | /// |
| 649 | /// By default, performs semantic analysis when building the array type. |
| 650 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 652 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 653 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 654 | unsigned IndexTypeQuals, |
| 655 | SourceRange BracketsRange); |
| 656 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 658 | /// size modifier, size expression, and index type qualifiers. |
| 659 | /// |
| 660 | /// By default, performs semantic analysis when building the array type. |
| 661 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 662 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 663 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 664 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 665 | unsigned IndexTypeQuals, |
| 666 | SourceRange BracketsRange); |
| 667 | |
| 668 | /// \brief Build a new vector type given the element type and |
| 669 | /// number of elements. |
| 670 | /// |
| 671 | /// By default, performs semantic analysis when building the vector type. |
| 672 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 673 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 674 | VectorType::VectorKind VecKind); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 675 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 676 | /// \brief Build a new extended vector type given the element type and |
| 677 | /// number of elements. |
| 678 | /// |
| 679 | /// By default, performs semantic analysis when building the vector type. |
| 680 | /// Subclasses may override this routine to provide different behavior. |
| 681 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 682 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 683 | |
| 684 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 685 | /// given the element type and number of elements. |
| 686 | /// |
| 687 | /// By default, performs semantic analysis when building the vector type. |
| 688 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 690 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 691 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 693 | /// \brief Build a new function type. |
| 694 | /// |
| 695 | /// By default, performs semantic analysis when building the function type. |
| 696 | /// Subclasses may override this routine to provide different behavior. |
| 697 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 698 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 699 | unsigned NumParamTypes, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 700 | bool Variadic, bool HasTrailingReturn, |
| 701 | unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 702 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 703 | const FunctionType::ExtInfo &Info); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 704 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 705 | /// \brief Build a new unprototyped function type. |
| 706 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 707 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 708 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 709 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 710 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 711 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 712 | /// \brief Build a new typedef type. |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 713 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 714 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 715 | } |
| 716 | |
| 717 | /// \brief Build a new class/struct/union type. |
| 718 | QualType RebuildRecordType(RecordDecl *Record) { |
| 719 | return SemaRef.Context.getTypeDeclType(Record); |
| 720 | } |
| 721 | |
| 722 | /// \brief Build a new Enum type. |
| 723 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 724 | return SemaRef.Context.getTypeDeclType(Enum); |
| 725 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 726 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 727 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 728 | /// |
| 729 | /// By default, performs semantic analysis when building the typeof type. |
| 730 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 731 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 732 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 734 | /// |
| 735 | /// By default, builds a new TypeOfType with the given underlying type. |
| 736 | QualType RebuildTypeOfType(QualType Underlying); |
| 737 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 738 | /// \brief Build a new unary transform type. |
| 739 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 740 | UnaryTransformType::UTTKind UKind, |
| 741 | SourceLocation Loc); |
| 742 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 744 | /// |
| 745 | /// By default, performs semantic analysis when building the decltype type. |
| 746 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 747 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 748 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 749 | /// \brief Build a new C++0x auto type. |
| 750 | /// |
| 751 | /// By default, builds a new AutoType with the given deduced type. |
| 752 | QualType RebuildAutoType(QualType Deduced) { |
| 753 | return SemaRef.Context.getAutoType(Deduced); |
| 754 | } |
| 755 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 756 | /// \brief Build a new template specialization type. |
| 757 | /// |
| 758 | /// By default, performs semantic analysis when building the template |
| 759 | /// specialization type. Subclasses may override this routine to provide |
| 760 | /// different behavior. |
| 761 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 762 | SourceLocation TemplateLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 763 | TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 765 | /// \brief Build a new parenthesized type. |
| 766 | /// |
| 767 | /// By default, builds a new ParenType type from the inner type. |
| 768 | /// Subclasses may override this routine to provide different behavior. |
| 769 | QualType RebuildParenType(QualType InnerType) { |
| 770 | return SemaRef.Context.getParenType(InnerType); |
| 771 | } |
| 772 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 773 | /// \brief Build a new qualified name type. |
| 774 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 775 | /// By default, builds a new ElaboratedType type from the keyword, |
| 776 | /// the nested-name-specifier and the named type. |
| 777 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 778 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 779 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 780 | NestedNameSpecifierLoc QualifierLoc, |
| 781 | QualType Named) { |
| 782 | return SemaRef.Context.getElaboratedType(Keyword, |
| 783 | QualifierLoc.getNestedNameSpecifier(), |
| 784 | Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 786 | |
| 787 | /// \brief Build a new typename type that refers to a template-id. |
| 788 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 789 | /// By default, builds a new DependentNameType type from the |
| 790 | /// nested-name-specifier and the given type. Subclasses may override |
| 791 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 792 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 793 | ElaboratedTypeKeyword Keyword, |
| 794 | NestedNameSpecifierLoc QualifierLoc, |
| 795 | const IdentifierInfo *Name, |
| 796 | SourceLocation NameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 797 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 798 | // Rebuild the template name. |
| 799 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 800 | CXXScopeSpec SS; |
| 801 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 802 | TemplateName InstName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 803 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 804 | |
| 805 | if (InstName.isNull()) |
| 806 | return QualType(); |
| 807 | |
| 808 | // If it's still dependent, make a dependent specialization. |
| 809 | if (InstName.getAsDependentTemplateName()) |
| 810 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 811 | QualifierLoc.getNestedNameSpecifier(), |
| 812 | Name, |
| 813 | Args); |
| 814 | |
| 815 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 816 | // specialization. |
| 817 | QualType T = |
| 818 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 819 | if (T.isNull()) return QualType(); |
| 820 | |
| 821 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 822 | return T; |
| 823 | |
| 824 | return SemaRef.Context.getElaboratedType(Keyword, |
| 825 | QualifierLoc.getNestedNameSpecifier(), |
| 826 | T); |
| 827 | } |
| 828 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 829 | /// \brief Build a new typename type that refers to an identifier. |
| 830 | /// |
| 831 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 832 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 833 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 834 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 835 | SourceLocation KeywordLoc, |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 836 | NestedNameSpecifierLoc QualifierLoc, |
| 837 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 838 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 839 | CXXScopeSpec SS; |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 840 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 841 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 842 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 843 | // If the name is still dependent, just build a new dependent name type. |
| 844 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 845 | return SemaRef.Context.getDependentNameType(Keyword, |
| 846 | QualifierLoc.getNestedNameSpecifier(), |
| 847 | Id); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 850 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 851 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | e29425b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 852 | *Id, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 853 | |
| 854 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 855 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 856 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 857 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 858 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 859 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 860 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 861 | if (!DC) |
| 862 | return QualType(); |
| 863 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 864 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 865 | return QualType(); |
| 866 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 867 | TagDecl *Tag = 0; |
| 868 | SemaRef.LookupQualifiedName(Result, DC); |
| 869 | switch (Result.getResultKind()) { |
| 870 | case LookupResult::NotFound: |
| 871 | case LookupResult::NotFoundInCurrentInstantiation: |
| 872 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 873 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 874 | case LookupResult::Found: |
| 875 | Tag = Result.getAsSingle<TagDecl>(); |
| 876 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 877 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 878 | case LookupResult::FoundOverloaded: |
| 879 | case LookupResult::FoundUnresolvedValue: |
| 880 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 881 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 882 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 883 | case LookupResult::Ambiguous: |
| 884 | // Let the LookupResult structure handle ambiguities. |
| 885 | return QualType(); |
| 886 | } |
| 887 | |
| 888 | if (!Tag) { |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 889 | // Check where the name exists but isn't a tag type and use that to emit |
| 890 | // better diagnostics. |
| 891 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 892 | SemaRef.LookupQualifiedName(Result, DC); |
| 893 | switch (Result.getResultKind()) { |
| 894 | case LookupResult::Found: |
| 895 | case LookupResult::FoundOverloaded: |
| 896 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 897 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 898 | unsigned Kind = 0; |
| 899 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 900 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 901 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 902 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 903 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 904 | break; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 905 | } |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 906 | default: |
| 907 | // FIXME: Would be nice to highlight just the source range. |
| 908 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 909 | << Kind << Id << DC; |
| 910 | break; |
| 911 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 912 | return QualType(); |
| 913 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 914 | |
Richard Trieu | bbf34c0 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 915 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 916 | IdLoc, *Id)) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 917 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 918 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 919 | return QualType(); |
| 920 | } |
| 921 | |
| 922 | // Build the elaborated-type-specifier type. |
| 923 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 924 | return SemaRef.Context.getElaboratedType(Keyword, |
| 925 | QualifierLoc.getNestedNameSpecifier(), |
| 926 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 927 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 928 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 929 | /// \brief Build a new pack expansion type. |
| 930 | /// |
| 931 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 932 | /// Subclasses may override this routine to provide different behavior. |
| 933 | QualType RebuildPackExpansionType(QualType Pattern, |
| 934 | SourceRange PatternRange, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 935 | SourceLocation EllipsisLoc, |
| 936 | llvm::Optional<unsigned> NumExpansions) { |
| 937 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 938 | NumExpansions); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 939 | } |
| 940 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 941 | /// \brief Build a new atomic type given its value type. |
| 942 | /// |
| 943 | /// By default, performs semantic analysis when building the atomic type. |
| 944 | /// Subclasses may override this routine to provide different behavior. |
| 945 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 946 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 947 | /// \brief Build a new template name given a nested name specifier, a flag |
| 948 | /// indicating whether the "template" keyword was provided, and the template |
| 949 | /// that the template name refers to. |
| 950 | /// |
| 951 | /// By default, builds the new template name directly. Subclasses may override |
| 952 | /// this routine to provide different behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 953 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 954 | bool TemplateKW, |
| 955 | TemplateDecl *Template); |
| 956 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 957 | /// \brief Build a new template name given a nested name specifier and the |
| 958 | /// name that is referred to as a template. |
| 959 | /// |
| 960 | /// By default, performs semantic analysis to determine whether the name can |
| 961 | /// be resolved to a specific template, then builds the appropriate kind of |
| 962 | /// template name. Subclasses may override this routine to provide different |
| 963 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 964 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 965 | const IdentifierInfo &Name, |
| 966 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 967 | QualType ObjectType, |
| 968 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 970 | /// \brief Build a new template name given a nested name specifier and the |
| 971 | /// overloaded operator name that is referred to as a template. |
| 972 | /// |
| 973 | /// By default, performs semantic analysis to determine whether the name can |
| 974 | /// be resolved to a specific template, then builds the appropriate kind of |
| 975 | /// template name. Subclasses may override this routine to provide different |
| 976 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 977 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 978 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 979 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 980 | QualType ObjectType); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 981 | |
| 982 | /// \brief Build a new template name given a template template parameter pack |
| 983 | /// and the |
| 984 | /// |
| 985 | /// By default, performs semantic analysis to determine whether the name can |
| 986 | /// be resolved to a specific template, then builds the appropriate kind of |
| 987 | /// template name. Subclasses may override this routine to provide different |
| 988 | /// behavior. |
| 989 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 990 | const TemplateArgument &ArgPack) { |
| 991 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 992 | } |
| 993 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 994 | /// \brief Build a new compound statement. |
| 995 | /// |
| 996 | /// By default, performs semantic analysis to build the new statement. |
| 997 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 998 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 999 | MultiStmtArg Statements, |
| 1000 | SourceLocation RBraceLoc, |
| 1001 | bool IsStmtExpr) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1002 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1003 | IsStmtExpr); |
| 1004 | } |
| 1005 | |
| 1006 | /// \brief Build a new case statement. |
| 1007 | /// |
| 1008 | /// By default, performs semantic analysis to build the new statement. |
| 1009 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1010 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1011 | Expr *LHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1012 | SourceLocation EllipsisLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1013 | Expr *RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1014 | SourceLocation ColonLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1015 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1016 | ColonLoc); |
| 1017 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1018 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1019 | /// \brief Attach the body to a new case statement. |
| 1020 | /// |
| 1021 | /// By default, performs semantic analysis to build the new statement. |
| 1022 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1023 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1024 | getSema().ActOnCaseStmtBody(S, Body); |
| 1025 | return S; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1026 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1028 | /// \brief Build a new default statement. |
| 1029 | /// |
| 1030 | /// By default, performs semantic analysis to build the new statement. |
| 1031 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1032 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1033 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1034 | Stmt *SubStmt) { |
| 1035 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1036 | /*CurScope=*/0); |
| 1037 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1039 | /// \brief Build a new label statement. |
| 1040 | /// |
| 1041 | /// By default, performs semantic analysis to build the new statement. |
| 1042 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1043 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1044 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1045 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1046 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1048 | /// \brief Build a new "if" statement. |
| 1049 | /// |
| 1050 | /// By default, performs semantic analysis to build the new statement. |
| 1051 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1052 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1053 | VarDecl *CondVar, Stmt *Then, |
| 1054 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1055 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1056 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1058 | /// \brief Start building a new switch statement. |
| 1059 | /// |
| 1060 | /// By default, performs semantic analysis to build the new statement. |
| 1061 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1062 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1063 | Expr *Cond, VarDecl *CondVar) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1064 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1065 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1066 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1068 | /// \brief Attach the body to the switch 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 | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1072 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1073 | Stmt *Switch, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1074 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | /// \brief Build a new while statement. |
| 1078 | /// |
| 1079 | /// By default, performs semantic analysis to build the new statement. |
| 1080 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1081 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1082 | VarDecl *CondVar, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1083 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1084 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1086 | /// \brief Build a new do-while statement. |
| 1087 | /// |
| 1088 | /// By default, performs semantic analysis to build the new statement. |
| 1089 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1090 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1091 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1092 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1093 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1094 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /// \brief Build a new for statement. |
| 1098 | /// |
| 1099 | /// By default, performs semantic analysis to build the new statement. |
| 1100 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1101 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1102 | Stmt *Init, Sema::FullExprArg Cond, |
| 1103 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1104 | SourceLocation RParenLoc, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1105 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1106 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1107 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1109 | /// \brief Build a new goto statement. |
| 1110 | /// |
| 1111 | /// By default, performs semantic analysis to build the new statement. |
| 1112 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1113 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1114 | LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1115 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /// \brief Build a new indirect goto statement. |
| 1119 | /// |
| 1120 | /// By default, performs semantic analysis to build the new statement. |
| 1121 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1122 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1123 | SourceLocation StarLoc, |
| 1124 | Expr *Target) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1125 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1128 | /// \brief Build a new return statement. |
| 1129 | /// |
| 1130 | /// By default, performs semantic analysis to build the new statement. |
| 1131 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1132 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1133 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1136 | /// \brief Build a new declaration statement. |
| 1137 | /// |
| 1138 | /// By default, performs semantic analysis to build the new statement. |
| 1139 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1140 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1141 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1142 | SourceLocation EndLoc) { |
Richard Smith | 406c38e | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1143 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1144 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1145 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1146 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1147 | /// \brief Build a new inline asm statement. |
| 1148 | /// |
| 1149 | /// By default, performs semantic analysis to build the new statement. |
| 1150 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1151 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1152 | bool IsSimple, |
| 1153 | bool IsVolatile, |
| 1154 | unsigned NumOutputs, |
| 1155 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1156 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1157 | MultiExprArg Constraints, |
| 1158 | MultiExprArg Exprs, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1159 | Expr *AsmString, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1160 | MultiExprArg Clobbers, |
| 1161 | SourceLocation RParenLoc, |
| 1162 | bool MSAsm) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1163 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1164 | NumInputs, Names, move(Constraints), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1165 | Exprs, AsmString, Clobbers, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1166 | RParenLoc, MSAsm); |
| 1167 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1168 | |
| 1169 | /// \brief Build a new Objective-C @try statement. |
| 1170 | /// |
| 1171 | /// By default, performs semantic analysis to build the new statement. |
| 1172 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1173 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1174 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1175 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1176 | Stmt *Finally) { |
| 1177 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1178 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1181 | /// \brief Rebuild an Objective-C exception declaration. |
| 1182 | /// |
| 1183 | /// By default, performs semantic analysis to build the new declaration. |
| 1184 | /// Subclasses may override this routine to provide different behavior. |
| 1185 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1186 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1187 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1188 | ExceptionDecl->getInnerLocStart(), |
| 1189 | ExceptionDecl->getLocation(), |
| 1190 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1191 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1192 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1193 | /// \brief Build a new Objective-C @catch statement. |
| 1194 | /// |
| 1195 | /// By default, performs semantic analysis to build the new statement. |
| 1196 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1197 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1198 | SourceLocation RParenLoc, |
| 1199 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1200 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1201 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1202 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1203 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1204 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1205 | /// \brief Build a new Objective-C @finally statement. |
| 1206 | /// |
| 1207 | /// By default, performs semantic analysis to build the new statement. |
| 1208 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1209 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1210 | Stmt *Body) { |
| 1211 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1212 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1213 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1214 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1215 | /// |
| 1216 | /// By default, performs semantic analysis to build the new statement. |
| 1217 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1218 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1219 | Expr *Operand) { |
| 1220 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1221 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1222 | |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1223 | /// \brief Rebuild the operand to an Objective-C @synchronized statement. |
| 1224 | /// |
| 1225 | /// By default, performs semantic analysis to build the new statement. |
| 1226 | /// Subclasses may override this routine to provide different behavior. |
| 1227 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1228 | Expr *object) { |
| 1229 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1230 | } |
| 1231 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1232 | /// \brief Build a new Objective-C @synchronized statement. |
| 1233 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1234 | /// By default, performs semantic analysis to build the new statement. |
| 1235 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1236 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1237 | Expr *Object, Stmt *Body) { |
| 1238 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1239 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1240 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1241 | /// \brief Build a new Objective-C @autoreleasepool statement. |
| 1242 | /// |
| 1243 | /// By default, performs semantic analysis to build the new statement. |
| 1244 | /// Subclasses may override this routine to provide different behavior. |
| 1245 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1246 | Stmt *Body) { |
| 1247 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1248 | } |
John McCall | 990567c | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1249 | |
| 1250 | /// \brief Build the collection operand to a new Objective-C fast |
| 1251 | /// enumeration statement. |
| 1252 | /// |
| 1253 | /// By default, performs semantic analysis to build the new statement. |
| 1254 | /// Subclasses may override this routine to provide different behavior. |
| 1255 | ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc, |
| 1256 | Expr *collection) { |
| 1257 | return getSema().ActOnObjCForCollectionOperand(forLoc, collection); |
| 1258 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1259 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1260 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1261 | /// |
| 1262 | /// By default, performs semantic analysis to build the new statement. |
| 1263 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1264 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1265 | SourceLocation LParenLoc, |
| 1266 | Stmt *Element, |
| 1267 | Expr *Collection, |
| 1268 | SourceLocation RParenLoc, |
| 1269 | Stmt *Body) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1270 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1271 | Element, |
| 1272 | Collection, |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1273 | RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1274 | Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1275 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1276 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1277 | /// \brief Build a new C++ exception declaration. |
| 1278 | /// |
| 1279 | /// By default, performs semantic analysis to build the new decaration. |
| 1280 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1281 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1282 | TypeSourceInfo *Declarator, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1283 | SourceLocation StartLoc, |
| 1284 | SourceLocation IdLoc, |
| 1285 | IdentifierInfo *Id) { |
Douglas Gregor | efdf988 | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1286 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1287 | StartLoc, IdLoc, Id); |
| 1288 | if (Var) |
| 1289 | getSema().CurContext->addDecl(Var); |
| 1290 | return Var; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | /// \brief Build a new C++ catch statement. |
| 1294 | /// |
| 1295 | /// By default, performs semantic analysis to build the new statement. |
| 1296 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1297 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1298 | VarDecl *ExceptionDecl, |
| 1299 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1300 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1301 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1304 | /// \brief Build a new C++ try statement. |
| 1305 | /// |
| 1306 | /// By default, performs semantic analysis to build the new statement. |
| 1307 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1308 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1309 | Stmt *TryBlock, |
| 1310 | MultiStmtArg Handlers) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1311 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1314 | /// \brief Build a new C++0x range-based for statement. |
| 1315 | /// |
| 1316 | /// By default, performs semantic analysis to build the new statement. |
| 1317 | /// Subclasses may override this routine to provide different behavior. |
| 1318 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1319 | SourceLocation ColonLoc, |
| 1320 | Stmt *Range, Stmt *BeginEnd, |
| 1321 | Expr *Cond, Expr *Inc, |
| 1322 | Stmt *LoopVar, |
| 1323 | SourceLocation RParenLoc) { |
| 1324 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
| 1325 | Cond, Inc, LoopVar, RParenLoc); |
| 1326 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1327 | |
| 1328 | /// \brief Build a new C++0x range-based for statement. |
| 1329 | /// |
| 1330 | /// By default, performs semantic analysis to build the new statement. |
| 1331 | /// Subclasses may override this routine to provide different behavior. |
| 1332 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
| 1333 | bool IsIfExists, |
| 1334 | NestedNameSpecifierLoc QualifierLoc, |
| 1335 | DeclarationNameInfo NameInfo, |
| 1336 | Stmt *Nested) { |
| 1337 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1338 | QualifierLoc, NameInfo, Nested); |
| 1339 | } |
| 1340 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1341 | /// \brief Attach body to a C++0x range-based for statement. |
| 1342 | /// |
| 1343 | /// By default, performs semantic analysis to finish the new statement. |
| 1344 | /// Subclasses may override this routine to provide different behavior. |
| 1345 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1346 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1347 | } |
| 1348 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1349 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, |
| 1350 | SourceLocation TryLoc, |
| 1351 | Stmt *TryBlock, |
| 1352 | Stmt *Handler) { |
| 1353 | return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1354 | } |
| 1355 | |
| 1356 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, |
| 1357 | Expr *FilterExpr, |
| 1358 | Stmt *Block) { |
| 1359 | return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); |
| 1360 | } |
| 1361 | |
| 1362 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, |
| 1363 | Stmt *Block) { |
| 1364 | return getSema().ActOnSEHFinallyBlock(Loc,Block); |
| 1365 | } |
| 1366 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1367 | /// \brief Build a new expression that references a declaration. |
| 1368 | /// |
| 1369 | /// By default, performs semantic analysis to build the new expression. |
| 1370 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1371 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1372 | LookupResult &R, |
| 1373 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1374 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | /// \brief Build a new expression that references a declaration. |
| 1379 | /// |
| 1380 | /// By default, performs semantic analysis to build the new expression. |
| 1381 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1382 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1383 | ValueDecl *VD, |
| 1384 | const DeclarationNameInfo &NameInfo, |
| 1385 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1386 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1387 | SS.Adopt(QualifierLoc); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1388 | |
| 1389 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1390 | |
| 1391 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1394 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1396 | /// By default, performs semantic analysis to build the new expression. |
| 1397 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1398 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1400 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1403 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1405 | /// By default, performs semantic analysis to build the new expression. |
| 1406 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1407 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1408 | SourceLocation OperatorLoc, |
| 1409 | bool isArrow, |
| 1410 | CXXScopeSpec &SS, |
| 1411 | TypeSourceInfo *ScopeType, |
| 1412 | SourceLocation CCLoc, |
| 1413 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1414 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1415 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1416 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1418 | /// By default, performs semantic analysis to build the new expression. |
| 1419 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1420 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1421 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1422 | Expr *SubExpr) { |
| 1423 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1424 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1426 | /// \brief Build a new builtin offsetof expression. |
| 1427 | /// |
| 1428 | /// By default, performs semantic analysis to build the new expression. |
| 1429 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1430 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1431 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1432 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1433 | unsigned NumComponents, |
| 1434 | SourceLocation RParenLoc) { |
| 1435 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1436 | NumComponents, RParenLoc); |
| 1437 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1438 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1439 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
| 1440 | /// type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1441 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1442 | /// By default, performs semantic analysis to build the new expression. |
| 1443 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1444 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1445 | SourceLocation OpLoc, |
| 1446 | UnaryExprOrTypeTrait ExprKind, |
| 1447 | SourceRange R) { |
| 1448 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1451 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1452 | /// expression argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1453 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1454 | /// By default, performs semantic analysis to build the new expression. |
| 1455 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1456 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1457 | UnaryExprOrTypeTrait ExprKind, |
| 1458 | SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1459 | ExprResult Result |
Chandler Carruth | e72c55b | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1460 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1461 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1462 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1463 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1464 | return move(Result); |
| 1465 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1466 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1467 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1468 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1469 | /// By default, performs semantic analysis to build the new expression. |
| 1470 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1471 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1472 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1473 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1474 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1475 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1476 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | RBracketLoc); |
| 1478 | } |
| 1479 | |
| 1480 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1481 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1482 | /// By default, performs semantic analysis to build the new expression. |
| 1483 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1484 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | MultiExprArg Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1486 | SourceLocation RParenLoc, |
| 1487 | Expr *ExecConfig = 0) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1488 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1489 | move(Args), RParenLoc, ExecConfig); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1493 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1494 | /// By default, performs semantic analysis to build the new expression. |
| 1495 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1496 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1497 | bool isArrow, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1498 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1499 | SourceLocation TemplateKWLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1500 | const DeclarationNameInfo &MemberNameInfo, |
| 1501 | ValueDecl *Member, |
| 1502 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1503 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1504 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1505 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1506 | isArrow); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1507 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1508 | // We have a reference to an unnamed field. This is always the |
| 1509 | // base of an anonymous struct/union member access, i.e. the |
| 1510 | // field is always of record type. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1511 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1512 | assert(Member->getType()->isRecordType() && |
| 1513 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1514 | |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1515 | BaseResult = |
| 1516 | getSema().PerformObjectMemberConversion(BaseResult.take(), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1517 | QualifierLoc.getNestedNameSpecifier(), |
| 1518 | FoundDecl, Member); |
| 1519 | if (BaseResult.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1520 | return ExprError(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1521 | Base = BaseResult.take(); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1522 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1523 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1524 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1525 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1526 | cast<FieldDecl>(Member)->getType(), |
| 1527 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1528 | return getSema().Owned(ME); |
| 1529 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1530 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1531 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1532 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1533 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1534 | Base = BaseResult.take(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1535 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1536 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1537 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1538 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1539 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1540 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1541 | R.resolveKind(); |
| 1542 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1543 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1544 | SS, TemplateKWLoc, |
| 1545 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1546 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1547 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1549 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1550 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1551 | /// By default, performs semantic analysis to build the new expression. |
| 1552 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1553 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1554 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1555 | Expr *LHS, Expr *RHS) { |
| 1556 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1561 | /// By default, performs semantic analysis to build the new expression. |
| 1562 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1563 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1564 | SourceLocation QuestionLoc, |
| 1565 | Expr *LHS, |
| 1566 | SourceLocation ColonLoc, |
| 1567 | Expr *RHS) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1568 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1569 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1572 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | /// By default, performs semantic analysis to build the new expression. |
| 1575 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1576 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1577 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1578 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1579 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1580 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1581 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1583 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1584 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1585 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1586 | /// By default, performs semantic analysis to build the new expression. |
| 1587 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1588 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1589 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1590 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1591 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1592 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1593 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1595 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1596 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1597 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1598 | /// By default, performs semantic analysis to build the new expression. |
| 1599 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1600 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1601 | SourceLocation OpLoc, |
| 1602 | SourceLocation AccessorLoc, |
| 1603 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1604 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1605 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1606 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1607 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1608 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1609 | SS, SourceLocation(), |
| 1610 | /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1611 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1612 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1613 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1614 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1615 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1616 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | /// By default, performs semantic analysis to build the new expression. |
| 1618 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1619 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1620 | MultiExprArg Inits, |
| 1621 | SourceLocation RBraceLoc, |
| 1622 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1623 | ExprResult Result |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1624 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1625 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1626 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1627 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1628 | // Patch in the result type we were given, which may have been computed |
| 1629 | // when the initial InitListExpr was built. |
| 1630 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1631 | ILE->setType(ResultTy); |
| 1632 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1633 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1636 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1637 | /// By default, performs semantic analysis to build the new expression. |
| 1638 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1639 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | MultiExprArg ArrayExprs, |
| 1641 | SourceLocation EqualOrColonLoc, |
| 1642 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1643 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1644 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1646 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1648 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | ArrayExprs.release(); |
| 1651 | return move(Result); |
| 1652 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1653 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1655 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1656 | /// By default, builds the implicit value initialization without performing |
| 1657 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1658 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1659 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1661 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1663 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1664 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1665 | /// By default, performs semantic analysis to build the new expression. |
| 1666 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1667 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1668 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1669 | SourceLocation RParenLoc) { |
| 1670 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1671 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1672 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1677 | /// By default, performs semantic analysis to build the new expression. |
| 1678 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1679 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1680 | MultiExprArg SubExprs, |
| 1681 | SourceLocation RParenLoc) { |
| 1682 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1685 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1686 | /// |
| 1687 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1688 | /// rather than attempting to map the label statement itself. |
| 1689 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1690 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1691 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1692 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1694 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1697 | /// By default, performs semantic analysis to build the new expression. |
| 1698 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1699 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1700 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1701 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1702 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1703 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1704 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1705 | /// \brief Build a new __builtin_choose_expr expression. |
| 1706 | /// |
| 1707 | /// By default, performs semantic analysis to build the new expression. |
| 1708 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1709 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1710 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1711 | SourceLocation RParenLoc) { |
| 1712 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1713 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | RParenLoc); |
| 1715 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1716 | |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1717 | /// \brief Build a new generic selection expression. |
| 1718 | /// |
| 1719 | /// By default, performs semantic analysis to build the new expression. |
| 1720 | /// Subclasses may override this routine to provide different behavior. |
| 1721 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1722 | SourceLocation DefaultLoc, |
| 1723 | SourceLocation RParenLoc, |
| 1724 | Expr *ControllingExpr, |
| 1725 | TypeSourceInfo **Types, |
| 1726 | Expr **Exprs, |
| 1727 | unsigned NumAssocs) { |
| 1728 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 1729 | ControllingExpr, Types, Exprs, |
| 1730 | NumAssocs); |
| 1731 | } |
| 1732 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1733 | /// \brief Build a new overloaded operator call expression. |
| 1734 | /// |
| 1735 | /// By default, performs semantic analysis to build the new expression. |
| 1736 | /// The semantic analysis provides the behavior of template instantiation, |
| 1737 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1738 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1739 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1740 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1741 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1743 | Expr *Callee, |
| 1744 | Expr *First, |
| 1745 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1746 | |
| 1747 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1748 | /// reinterpret_cast. |
| 1749 | /// |
| 1750 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1752 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1753 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1754 | Stmt::StmtClass Class, |
| 1755 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1756 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1757 | SourceLocation RAngleLoc, |
| 1758 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1759 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1760 | SourceLocation RParenLoc) { |
| 1761 | switch (Class) { |
| 1762 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1763 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1764 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1765 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1766 | |
| 1767 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1768 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1770 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1772 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1773 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1775 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1776 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1778 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1779 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1780 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1781 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1783 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1784 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1785 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1786 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1787 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1788 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1790 | /// \brief Build a new C++ static_cast expression. |
| 1791 | /// |
| 1792 | /// By default, performs semantic analysis to build the new expression. |
| 1793 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1794 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1796 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | SourceLocation RAngleLoc, |
| 1798 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1799 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1800 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1801 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1802 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1803 | SourceRange(LAngleLoc, RAngleLoc), |
| 1804 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | /// \brief Build a new C++ dynamic_cast expression. |
| 1808 | /// |
| 1809 | /// By default, performs semantic analysis to build the new expression. |
| 1810 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1811 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1812 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1813 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1814 | SourceLocation RAngleLoc, |
| 1815 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1816 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1817 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1818 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1819 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1820 | SourceRange(LAngleLoc, RAngleLoc), |
| 1821 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1825 | /// |
| 1826 | /// By default, performs semantic analysis to build the new expression. |
| 1827 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1828 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1829 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1830 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1831 | SourceLocation RAngleLoc, |
| 1832 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1833 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1834 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1835 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1836 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1837 | SourceRange(LAngleLoc, RAngleLoc), |
| 1838 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /// \brief Build a new C++ const_cast expression. |
| 1842 | /// |
| 1843 | /// By default, performs semantic analysis to build the new expression. |
| 1844 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1845 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1846 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1847 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1848 | SourceLocation RAngleLoc, |
| 1849 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1850 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1851 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1852 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1853 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1854 | SourceRange(LAngleLoc, RAngleLoc), |
| 1855 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1856 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1858 | /// \brief Build a new C++ functional-style cast expression. |
| 1859 | /// |
| 1860 | /// By default, performs semantic analysis to build the new expression. |
| 1861 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1862 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1863 | SourceLocation LParenLoc, |
| 1864 | Expr *Sub, |
| 1865 | SourceLocation RParenLoc) { |
| 1866 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1867 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1868 | RParenLoc); |
| 1869 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1870 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1871 | /// \brief Build a new C++ typeid(type) expression. |
| 1872 | /// |
| 1873 | /// By default, performs semantic analysis to build the new expression. |
| 1874 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1875 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1876 | SourceLocation TypeidLoc, |
| 1877 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1878 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1879 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1880 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1881 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1882 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1883 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1884 | /// \brief Build a new C++ typeid(expr) expression. |
| 1885 | /// |
| 1886 | /// By default, performs semantic analysis to build the new expression. |
| 1887 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1888 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1889 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1890 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1891 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1892 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1893 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1896 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1897 | /// |
| 1898 | /// By default, performs semantic analysis to build the new expression. |
| 1899 | /// Subclasses may override this routine to provide different behavior. |
| 1900 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1901 | SourceLocation TypeidLoc, |
| 1902 | TypeSourceInfo *Operand, |
| 1903 | SourceLocation RParenLoc) { |
| 1904 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1905 | RParenLoc); |
| 1906 | } |
| 1907 | |
| 1908 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1909 | /// |
| 1910 | /// By default, performs semantic analysis to build the new expression. |
| 1911 | /// Subclasses may override this routine to provide different behavior. |
| 1912 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1913 | SourceLocation TypeidLoc, |
| 1914 | Expr *Operand, |
| 1915 | SourceLocation RParenLoc) { |
| 1916 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1917 | RParenLoc); |
| 1918 | } |
| 1919 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1920 | /// \brief Build a new C++ "this" expression. |
| 1921 | /// |
| 1922 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1923 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1924 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1925 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1926 | QualType ThisType, |
| 1927 | bool isImplicit) { |
Eli Friedman | b69b42c | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 1928 | getSema().CheckCXXThisCapture(ThisLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1929 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1930 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1931 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | /// \brief Build a new C++ throw expression. |
| 1935 | /// |
| 1936 | /// By default, performs semantic analysis to build the new expression. |
| 1937 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 1938 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 1939 | bool IsThrownVariableInScope) { |
| 1940 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | /// \brief Build a new C++ default-argument expression. |
| 1944 | /// |
| 1945 | /// By default, builds a new default-argument expression, which does not |
| 1946 | /// require any semantic analysis. Subclasses may override this routine to |
| 1947 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1948 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1949 | ParmVarDecl *Param) { |
| 1950 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1951 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | /// \brief Build a new C++ zero-initialization expression. |
| 1955 | /// |
| 1956 | /// By default, performs semantic analysis to build the new expression. |
| 1957 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1958 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1959 | SourceLocation LParenLoc, |
| 1960 | SourceLocation RParenLoc) { |
| 1961 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1962 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1963 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1964 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1966 | /// \brief Build a new C++ "new" expression. |
| 1967 | /// |
| 1968 | /// By default, performs semantic analysis to build the new expression. |
| 1969 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1970 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1971 | bool UseGlobal, |
| 1972 | SourceLocation PlacementLParen, |
| 1973 | MultiExprArg PlacementArgs, |
| 1974 | SourceLocation PlacementRParen, |
| 1975 | SourceRange TypeIdParens, |
| 1976 | QualType AllocatedType, |
| 1977 | TypeSourceInfo *AllocatedTypeInfo, |
| 1978 | Expr *ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 1979 | SourceRange DirectInitRange, |
| 1980 | Expr *Initializer) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1981 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1982 | PlacementLParen, |
| 1983 | move(PlacementArgs), |
| 1984 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1985 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1986 | AllocatedType, |
| 1987 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1988 | ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 1989 | DirectInitRange, |
| 1990 | Initializer); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | /// \brief Build a new C++ "delete" expression. |
| 1994 | /// |
| 1995 | /// By default, performs semantic analysis to build the new expression. |
| 1996 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1997 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1998 | bool IsGlobalDelete, |
| 1999 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2000 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2001 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2002 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2003 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2004 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2005 | /// \brief Build a new unary type trait expression. |
| 2006 | /// |
| 2007 | /// By default, performs semantic analysis to build the new expression. |
| 2008 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2009 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 2010 | SourceLocation StartLoc, |
| 2011 | TypeSourceInfo *T, |
| 2012 | SourceLocation RParenLoc) { |
| 2013 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2016 | /// \brief Build a new binary type trait expression. |
| 2017 | /// |
| 2018 | /// By default, performs semantic analysis to build the new expression. |
| 2019 | /// Subclasses may override this routine to provide different behavior. |
| 2020 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 2021 | SourceLocation StartLoc, |
| 2022 | TypeSourceInfo *LhsT, |
| 2023 | TypeSourceInfo *RhsT, |
| 2024 | SourceLocation RParenLoc) { |
| 2025 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 2026 | } |
| 2027 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2028 | /// \brief Build a new array type trait expression. |
| 2029 | /// |
| 2030 | /// By default, performs semantic analysis to build the new expression. |
| 2031 | /// Subclasses may override this routine to provide different behavior. |
| 2032 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2033 | SourceLocation StartLoc, |
| 2034 | TypeSourceInfo *TSInfo, |
| 2035 | Expr *DimExpr, |
| 2036 | SourceLocation RParenLoc) { |
| 2037 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2038 | } |
| 2039 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2040 | /// \brief Build a new expression trait expression. |
| 2041 | /// |
| 2042 | /// By default, performs semantic analysis to build the new expression. |
| 2043 | /// Subclasses may override this routine to provide different behavior. |
| 2044 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2045 | SourceLocation StartLoc, |
| 2046 | Expr *Queried, |
| 2047 | SourceLocation RParenLoc) { |
| 2048 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2049 | } |
| 2050 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2051 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2052 | /// expression. |
| 2053 | /// |
| 2054 | /// By default, performs semantic analysis to build the new expression. |
| 2055 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2056 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2057 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2058 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2059 | const DeclarationNameInfo &NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2060 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2061 | CXXScopeSpec SS; |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2062 | SS.Adopt(QualifierLoc); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2063 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2064 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2065 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2066 | NameInfo, TemplateArgs); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2067 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2068 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | /// \brief Build a new template-id expression. |
| 2072 | /// |
| 2073 | /// By default, performs semantic analysis to build the new expression. |
| 2074 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2075 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2076 | SourceLocation TemplateKWLoc, |
| 2077 | LookupResult &R, |
| 2078 | bool RequiresADL, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2079 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2080 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2081 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | /// \brief Build a new object-construction expression. |
| 2085 | /// |
| 2086 | /// By default, performs semantic analysis to build the new expression. |
| 2087 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2088 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2089 | SourceLocation Loc, |
| 2090 | CXXConstructorDecl *Constructor, |
| 2091 | bool IsElidable, |
| 2092 | MultiExprArg Args, |
| 2093 | bool HadMultipleCandidates, |
| 2094 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2095 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2096 | SourceRange ParenRange) { |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 2097 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2098 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2099 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2100 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2101 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2102 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 2103 | move_arg(ConvertedArgs), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2104 | HadMultipleCandidates, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2105 | RequiresZeroInit, ConstructKind, |
| 2106 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | /// \brief Build a new object-construction expression. |
| 2110 | /// |
| 2111 | /// By default, performs semantic analysis to build the new expression. |
| 2112 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2113 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2114 | SourceLocation LParenLoc, |
| 2115 | MultiExprArg Args, |
| 2116 | SourceLocation RParenLoc) { |
| 2117 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2118 | LParenLoc, |
| 2119 | move(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2120 | RParenLoc); |
| 2121 | } |
| 2122 | |
| 2123 | /// \brief Build a new object-construction expression. |
| 2124 | /// |
| 2125 | /// By default, performs semantic analysis to build the new expression. |
| 2126 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2127 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2128 | SourceLocation LParenLoc, |
| 2129 | MultiExprArg Args, |
| 2130 | SourceLocation RParenLoc) { |
| 2131 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2132 | LParenLoc, |
| 2133 | move(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2134 | RParenLoc); |
| 2135 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2136 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2137 | /// \brief Build a new member reference expression. |
| 2138 | /// |
| 2139 | /// By default, performs semantic analysis to build the new expression. |
| 2140 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2141 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2142 | QualType BaseType, |
| 2143 | bool IsArrow, |
| 2144 | SourceLocation OperatorLoc, |
| 2145 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2146 | SourceLocation TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2147 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2148 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2149 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2150 | CXXScopeSpec SS; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2151 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2152 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2153 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2154 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2155 | SS, TemplateKWLoc, |
| 2156 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2157 | MemberNameInfo, |
| 2158 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2161 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2162 | /// |
| 2163 | /// By default, performs semantic analysis to build the new expression. |
| 2164 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2165 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2166 | SourceLocation OperatorLoc, |
| 2167 | bool IsArrow, |
| 2168 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2169 | SourceLocation TemplateKWLoc, |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2170 | NamedDecl *FirstQualifierInScope, |
| 2171 | LookupResult &R, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2172 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2173 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2174 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2175 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2176 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2177 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2178 | SS, TemplateKWLoc, |
| 2179 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2180 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2181 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2182 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2183 | /// \brief Build a new noexcept expression. |
| 2184 | /// |
| 2185 | /// By default, performs semantic analysis to build the new expression. |
| 2186 | /// Subclasses may override this routine to provide different behavior. |
| 2187 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2188 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2189 | } |
| 2190 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2191 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2192 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2193 | SourceLocation PackLoc, |
| 2194 | SourceLocation RParenLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2195 | llvm::Optional<unsigned> Length) { |
| 2196 | if (Length) |
| 2197 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2198 | OperatorLoc, Pack, PackLoc, |
| 2199 | RParenLoc, *Length); |
| 2200 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2201 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2202 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2203 | RParenLoc); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2206 | /// \brief Build a new Objective-C @encode expression. |
| 2207 | /// |
| 2208 | /// By default, performs semantic analysis to build the new expression. |
| 2209 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2210 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2211 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2212 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2213 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2214 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2215 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2216 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2217 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2218 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2219 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2220 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2221 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2222 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2223 | MultiExprArg Args, |
| 2224 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2225 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2226 | ReceiverTypeInfo->getType(), |
| 2227 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2228 | Sel, Method, LBracLoc, SelectorLocs, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2229 | RBracLoc, move(Args)); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2233 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2234 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2235 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2236 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2237 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2238 | MultiExprArg Args, |
| 2239 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2240 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2241 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2242 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2243 | Sel, Method, LBracLoc, SelectorLocs, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2244 | RBracLoc, move(Args)); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2247 | /// \brief Build a new Objective-C ivar reference expression. |
| 2248 | /// |
| 2249 | /// By default, performs semantic analysis to build the new expression. |
| 2250 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2251 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2252 | SourceLocation IvarLoc, |
| 2253 | bool IsArrow, bool IsFreeIvar) { |
| 2254 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2255 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2256 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2257 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2258 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2259 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2260 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2261 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2262 | false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2263 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2264 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2265 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2266 | if (Result.get()) |
| 2267 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2268 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2269 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2270 | /*FIXME:*/IvarLoc, IsArrow, |
| 2271 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2272 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2273 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2274 | /*TemplateArgs=*/0); |
| 2275 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2276 | |
| 2277 | /// \brief Build a new Objective-C property reference expression. |
| 2278 | /// |
| 2279 | /// By default, performs semantic analysis to build the new expression. |
| 2280 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2281 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2282 | ObjCPropertyDecl *Property, |
| 2283 | SourceLocation PropertyLoc) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2284 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2285 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2286 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2287 | Sema::LookupMemberName); |
| 2288 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2289 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2290 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2291 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2292 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2293 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2294 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2295 | if (Result.get()) |
| 2296 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2297 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2298 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2299 | /*FIXME:*/PropertyLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2300 | SS, SourceLocation(), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2301 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2302 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2303 | /*TemplateArgs=*/0); |
| 2304 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2305 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2306 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2307 | /// |
| 2308 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2309 | /// Subclasses may override this routine to provide different behavior. |
| 2310 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2311 | ObjCMethodDecl *Getter, |
| 2312 | ObjCMethodDecl *Setter, |
| 2313 | SourceLocation PropertyLoc) { |
| 2314 | // Since these expressions can only be value-dependent, we do not |
| 2315 | // need to perform semantic analysis again. |
| 2316 | return Owned( |
| 2317 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2318 | VK_LValue, OK_ObjCProperty, |
| 2319 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2322 | /// \brief Build a new Objective-C "isa" expression. |
| 2323 | /// |
| 2324 | /// By default, performs semantic analysis to build the new expression. |
| 2325 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2326 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2327 | bool IsArrow) { |
| 2328 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2329 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2330 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2331 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2332 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2333 | /*FIME:*/IsaLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2334 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2335 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2336 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2337 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2338 | if (Result.get()) |
| 2339 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2340 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2341 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2342 | /*FIXME:*/IsaLoc, IsArrow, |
| 2343 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2344 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2345 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2346 | /*TemplateArgs=*/0); |
| 2347 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2348 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2349 | /// \brief Build a new shuffle vector expression. |
| 2350 | /// |
| 2351 | /// By default, performs semantic analysis to build the new expression. |
| 2352 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2353 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2354 | MultiExprArg SubExprs, |
| 2355 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2356 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2357 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2358 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2359 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2360 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2361 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2362 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2363 | // Build a reference to the __builtin_shufflevector builtin |
| 2364 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2365 | ExprResult Callee |
| 2366 | = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
| 2367 | VK_LValue, BuiltinLoc)); |
| 2368 | Callee = SemaRef.UsualUnaryConversions(Callee.take()); |
| 2369 | if (Callee.isInvalid()) |
| 2370 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2371 | |
| 2372 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2373 | unsigned NumSubExprs = SubExprs.size(); |
| 2374 | Expr **Subs = (Expr **)SubExprs.release(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2375 | ExprResult TheCall = SemaRef.Owned( |
| 2376 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2377 | Subs, NumSubExprs, |
Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2378 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2379 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2380 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2381 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2382 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2383 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2384 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2385 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2386 | /// \brief Build a new template argument pack expansion. |
| 2387 | /// |
| 2388 | /// By default, performs semantic analysis to build a new pack expansion |
| 2389 | /// for a template argument. Subclasses may override this routine to provide |
| 2390 | /// different behavior. |
| 2391 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2392 | SourceLocation EllipsisLoc, |
| 2393 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2394 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2395 | case TemplateArgument::Expression: { |
| 2396 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2397 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2398 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2399 | if (Result.isInvalid()) |
| 2400 | return TemplateArgumentLoc(); |
| 2401 | |
| 2402 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2403 | } |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2404 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2405 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2406 | return TemplateArgumentLoc(TemplateArgument( |
| 2407 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2408 | NumExpansions), |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2409 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2410 | Pattern.getTemplateNameLoc(), |
| 2411 | EllipsisLoc); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2412 | |
| 2413 | case TemplateArgument::Null: |
| 2414 | case TemplateArgument::Integral: |
| 2415 | case TemplateArgument::Declaration: |
| 2416 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2417 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2418 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2419 | |
| 2420 | case TemplateArgument::Type: |
| 2421 | if (TypeSourceInfo *Expansion |
| 2422 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2423 | EllipsisLoc, |
| 2424 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2425 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2426 | Expansion); |
| 2427 | break; |
| 2428 | } |
| 2429 | |
| 2430 | return TemplateArgumentLoc(); |
| 2431 | } |
| 2432 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2433 | /// \brief Build a new expression pack expansion. |
| 2434 | /// |
| 2435 | /// By default, performs semantic analysis to build a new pack expansion |
| 2436 | /// for an expression. Subclasses may override this routine to provide |
| 2437 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2438 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2439 | llvm::Optional<unsigned> NumExpansions) { |
| 2440 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2441 | } |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2442 | |
| 2443 | /// \brief Build a new atomic operation expression. |
| 2444 | /// |
| 2445 | /// By default, performs semantic analysis to build the new expression. |
| 2446 | /// Subclasses may override this routine to provide different behavior. |
| 2447 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2448 | MultiExprArg SubExprs, |
| 2449 | QualType RetTy, |
| 2450 | AtomicExpr::AtomicOp Op, |
| 2451 | SourceLocation RParenLoc) { |
| 2452 | // Just create the expression; there is not any interesting semantic |
| 2453 | // analysis here because we can't actually build an AtomicExpr until |
| 2454 | // we are sure it is semantically sound. |
| 2455 | unsigned NumSubExprs = SubExprs.size(); |
| 2456 | Expr **Subs = (Expr **)SubExprs.release(); |
| 2457 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs, |
| 2458 | NumSubExprs, RetTy, Op, |
| 2459 | RParenLoc); |
| 2460 | } |
| 2461 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2462 | private: |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2463 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2464 | QualType ObjectType, |
| 2465 | NamedDecl *FirstQualifierInScope, |
| 2466 | CXXScopeSpec &SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2467 | |
| 2468 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2469 | QualType ObjectType, |
| 2470 | NamedDecl *FirstQualifierInScope, |
| 2471 | CXXScopeSpec &SS); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2472 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2473 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2474 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2475 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2476 | if (!S) |
| 2477 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2478 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2479 | switch (S->getStmtClass()) { |
| 2480 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2481 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2482 | // Transform individual statement nodes |
| 2483 | #define STMT(Node, Parent) \ |
| 2484 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2485 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2486 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2487 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2488 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2489 | // Transform expressions by calling TransformExpr. |
| 2490 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2491 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2492 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2493 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2494 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2495 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2496 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2497 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2498 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2499 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2500 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2503 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2505 | |
| 2506 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2507 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2508 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2509 | if (!E) |
| 2510 | return SemaRef.Owned(E); |
| 2511 | |
| 2512 | switch (E->getStmtClass()) { |
| 2513 | case Stmt::NoStmtClass: break; |
| 2514 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2515 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2516 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2517 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2518 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2519 | } |
| 2520 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2521 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | template<typename Derived> |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2525 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2526 | unsigned NumInputs, |
| 2527 | bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2528 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2529 | bool *ArgChanged) { |
| 2530 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2531 | // If requested, drop call arguments that need to be dropped. |
| 2532 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2533 | if (ArgChanged) |
| 2534 | *ArgChanged = true; |
| 2535 | |
| 2536 | break; |
| 2537 | } |
| 2538 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2539 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2540 | Expr *Pattern = Expansion->getPattern(); |
| 2541 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2542 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2543 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2544 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2545 | |
| 2546 | // Determine whether the set of unexpanded parameter packs can and should |
| 2547 | // be expanded. |
| 2548 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2549 | bool RetainExpansion = false; |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2550 | llvm::Optional<unsigned> OrigNumExpansions |
| 2551 | = Expansion->getNumExpansions(); |
| 2552 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2553 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2554 | Pattern->getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2555 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2556 | Expand, RetainExpansion, |
| 2557 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2558 | return true; |
| 2559 | |
| 2560 | if (!Expand) { |
| 2561 | // The transform has determined that we should perform a simple |
| 2562 | // transformation on the pack expansion, producing another pack |
| 2563 | // expansion. |
| 2564 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2565 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2566 | if (OutPattern.isInvalid()) |
| 2567 | return true; |
| 2568 | |
| 2569 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2570 | Expansion->getEllipsisLoc(), |
| 2571 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2572 | if (Out.isInvalid()) |
| 2573 | return true; |
| 2574 | |
| 2575 | if (ArgChanged) |
| 2576 | *ArgChanged = true; |
| 2577 | Outputs.push_back(Out.get()); |
| 2578 | continue; |
| 2579 | } |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2580 | |
| 2581 | // Record right away that the argument was changed. This needs |
| 2582 | // to happen even if the array expands to nothing. |
| 2583 | if (ArgChanged) *ArgChanged = true; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2584 | |
| 2585 | // The transform has determined that we should perform an elementwise |
| 2586 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2587 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2588 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2589 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2590 | if (Out.isInvalid()) |
| 2591 | return true; |
| 2592 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2593 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2594 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2595 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2596 | if (Out.isInvalid()) |
| 2597 | return true; |
| 2598 | } |
| 2599 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2600 | Outputs.push_back(Out.get()); |
| 2601 | } |
| 2602 | |
| 2603 | continue; |
| 2604 | } |
| 2605 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2606 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2607 | if (Result.isInvalid()) |
| 2608 | return true; |
| 2609 | |
| 2610 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2611 | *ArgChanged = true; |
| 2612 | |
| 2613 | Outputs.push_back(Result.get()); |
| 2614 | } |
| 2615 | |
| 2616 | return false; |
| 2617 | } |
| 2618 | |
| 2619 | template<typename Derived> |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2620 | NestedNameSpecifierLoc |
| 2621 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2622 | NestedNameSpecifierLoc NNS, |
| 2623 | QualType ObjectType, |
| 2624 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2625 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2626 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 2627 | Qualifier = Qualifier.getPrefix()) |
| 2628 | Qualifiers.push_back(Qualifier); |
| 2629 | |
| 2630 | CXXScopeSpec SS; |
| 2631 | while (!Qualifiers.empty()) { |
| 2632 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2633 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| 2634 | |
| 2635 | switch (QNNS->getKind()) { |
| 2636 | case NestedNameSpecifier::Identifier: |
| 2637 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
| 2638 | *QNNS->getAsIdentifier(), |
| 2639 | Q.getLocalBeginLoc(), |
| 2640 | Q.getLocalEndLoc(), |
| 2641 | ObjectType, false, SS, |
| 2642 | FirstQualifierInScope, false)) |
| 2643 | return NestedNameSpecifierLoc(); |
| 2644 | |
| 2645 | break; |
| 2646 | |
| 2647 | case NestedNameSpecifier::Namespace: { |
| 2648 | NamespaceDecl *NS |
| 2649 | = cast_or_null<NamespaceDecl>( |
| 2650 | getDerived().TransformDecl( |
| 2651 | Q.getLocalBeginLoc(), |
| 2652 | QNNS->getAsNamespace())); |
| 2653 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2654 | break; |
| 2655 | } |
| 2656 | |
| 2657 | case NestedNameSpecifier::NamespaceAlias: { |
| 2658 | NamespaceAliasDecl *Alias |
| 2659 | = cast_or_null<NamespaceAliasDecl>( |
| 2660 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2661 | QNNS->getAsNamespaceAlias())); |
| 2662 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| 2663 | Q.getLocalEndLoc()); |
| 2664 | break; |
| 2665 | } |
| 2666 | |
| 2667 | case NestedNameSpecifier::Global: |
| 2668 | // There is no meaningful transformation that one could perform on the |
| 2669 | // global scope. |
| 2670 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2671 | break; |
| 2672 | |
| 2673 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2674 | case NestedNameSpecifier::TypeSpec: { |
| 2675 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2676 | FirstQualifierInScope, SS); |
| 2677 | |
| 2678 | if (!TL) |
| 2679 | return NestedNameSpecifierLoc(); |
| 2680 | |
| 2681 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| 2682 | (SemaRef.getLangOptions().CPlusPlus0x && |
| 2683 | TL.getType()->isEnumeralType())) { |
| 2684 | assert(!TL.getType().hasLocalQualifiers() && |
| 2685 | "Can't get cv-qualifiers here"); |
Richard Smith | 95aafb2 | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 2686 | if (TL.getType()->isEnumeralType()) |
| 2687 | SemaRef.Diag(TL.getBeginLoc(), |
| 2688 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2689 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2690 | Q.getLocalEndLoc()); |
| 2691 | break; |
| 2692 | } |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2693 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2694 | // error because a previous error should have already been emitted. |
| 2695 | TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); |
| 2696 | if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { |
| 2697 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 2698 | << TL.getType() << SS.getRange(); |
| 2699 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2700 | return NestedNameSpecifierLoc(); |
| 2701 | } |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2702 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2703 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2704 | // The qualifier-in-scope and object type only apply to the leftmost entity. |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2705 | FirstQualifierInScope = 0; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2706 | ObjectType = QualType(); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | // Don't rebuild the nested-name-specifier if we don't have to. |
| 2710 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 2711 | !getDerived().AlwaysRebuild()) |
| 2712 | return NNS; |
| 2713 | |
| 2714 | // If we can re-use the source-location data from the original |
| 2715 | // nested-name-specifier, do so. |
| 2716 | if (SS.location_size() == NNS.getDataLength() && |
| 2717 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2718 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2719 | |
| 2720 | // Allocate new nested-name-specifier location information. |
| 2721 | return SS.getWithLocInContext(SemaRef.Context); |
| 2722 | } |
| 2723 | |
| 2724 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2725 | DeclarationNameInfo |
| 2726 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2727 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2728 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2729 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2730 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2731 | |
| 2732 | switch (Name.getNameKind()) { |
| 2733 | case DeclarationName::Identifier: |
| 2734 | case DeclarationName::ObjCZeroArgSelector: |
| 2735 | case DeclarationName::ObjCOneArgSelector: |
| 2736 | case DeclarationName::ObjCMultiArgSelector: |
| 2737 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2738 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2739 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2740 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2741 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2742 | case DeclarationName::CXXConstructorName: |
| 2743 | case DeclarationName::CXXDestructorName: |
| 2744 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2745 | TypeSourceInfo *NewTInfo; |
| 2746 | CanQualType NewCanTy; |
| 2747 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2748 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2749 | if (!NewTInfo) |
| 2750 | return DeclarationNameInfo(); |
| 2751 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2752 | } |
| 2753 | else { |
| 2754 | NewTInfo = 0; |
| 2755 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2756 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2757 | if (NewT.isNull()) |
| 2758 | return DeclarationNameInfo(); |
| 2759 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2760 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2761 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2762 | DeclarationName NewName |
| 2763 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2764 | NewCanTy); |
| 2765 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2766 | NewNameInfo.setName(NewName); |
| 2767 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2768 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2769 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2772 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2777 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 2778 | TemplateName Name, |
| 2779 | SourceLocation NameLoc, |
| 2780 | QualType ObjectType, |
| 2781 | NamedDecl *FirstQualifierInScope) { |
| 2782 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 2783 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 2784 | assert(Template && "qualified template name must refer to a template"); |
| 2785 | |
| 2786 | TemplateDecl *TransTemplate |
| 2787 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2788 | Template)); |
| 2789 | if (!TransTemplate) |
| 2790 | return TemplateName(); |
| 2791 | |
| 2792 | if (!getDerived().AlwaysRebuild() && |
| 2793 | SS.getScopeRep() == QTN->getQualifier() && |
| 2794 | TransTemplate == Template) |
| 2795 | return Name; |
| 2796 | |
| 2797 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 2798 | TransTemplate); |
| 2799 | } |
| 2800 | |
| 2801 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 2802 | if (SS.getScopeRep()) { |
| 2803 | // These apply to the scope specifier, not the template. |
| 2804 | ObjectType = QualType(); |
| 2805 | FirstQualifierInScope = 0; |
| 2806 | } |
| 2807 | |
| 2808 | if (!getDerived().AlwaysRebuild() && |
| 2809 | SS.getScopeRep() == DTN->getQualifier() && |
| 2810 | ObjectType.isNull()) |
| 2811 | return Name; |
| 2812 | |
| 2813 | if (DTN->isIdentifier()) { |
| 2814 | return getDerived().RebuildTemplateName(SS, |
| 2815 | *DTN->getIdentifier(), |
| 2816 | NameLoc, |
| 2817 | ObjectType, |
| 2818 | FirstQualifierInScope); |
| 2819 | } |
| 2820 | |
| 2821 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 2822 | ObjectType); |
| 2823 | } |
| 2824 | |
| 2825 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 2826 | TemplateDecl *TransTemplate |
| 2827 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2828 | Template)); |
| 2829 | if (!TransTemplate) |
| 2830 | return TemplateName(); |
| 2831 | |
| 2832 | if (!getDerived().AlwaysRebuild() && |
| 2833 | TransTemplate == Template) |
| 2834 | return Name; |
| 2835 | |
| 2836 | return TemplateName(TransTemplate); |
| 2837 | } |
| 2838 | |
| 2839 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2840 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2841 | TemplateTemplateParmDecl *TransParam |
| 2842 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2843 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 2844 | if (!TransParam) |
| 2845 | return TemplateName(); |
| 2846 | |
| 2847 | if (!getDerived().AlwaysRebuild() && |
| 2848 | TransParam == SubstPack->getParameterPack()) |
| 2849 | return Name; |
| 2850 | |
| 2851 | return getDerived().RebuildTemplateName(TransParam, |
| 2852 | SubstPack->getArgumentPack()); |
| 2853 | } |
| 2854 | |
| 2855 | // These should be getting filtered out before they reach the AST. |
| 2856 | llvm_unreachable("overloaded function decl survived to here"); |
| 2857 | return TemplateName(); |
| 2858 | } |
| 2859 | |
| 2860 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2861 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2862 | const TemplateArgument &Arg, |
| 2863 | TemplateArgumentLoc &Output) { |
| 2864 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2865 | switch (Arg.getKind()) { |
| 2866 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2867 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2868 | break; |
| 2869 | |
| 2870 | case TemplateArgument::Type: |
| 2871 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2872 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2873 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2874 | break; |
| 2875 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2876 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2877 | case TemplateArgument::TemplateExpansion: { |
| 2878 | NestedNameSpecifierLocBuilder Builder; |
| 2879 | TemplateName Template = Arg.getAsTemplate(); |
| 2880 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 2881 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 2882 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 2883 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
| 2884 | |
| 2885 | if (Arg.getKind() == TemplateArgument::Template) |
| 2886 | Output = TemplateArgumentLoc(Arg, |
| 2887 | Builder.getWithLocInContext(SemaRef.Context), |
| 2888 | Loc); |
| 2889 | else |
| 2890 | Output = TemplateArgumentLoc(Arg, |
| 2891 | Builder.getWithLocInContext(SemaRef.Context), |
| 2892 | Loc, Loc); |
| 2893 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2894 | break; |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2895 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2896 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2897 | case TemplateArgument::Expression: |
| 2898 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2899 | break; |
| 2900 | |
| 2901 | case TemplateArgument::Declaration: |
| 2902 | case TemplateArgument::Integral: |
| 2903 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2904 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2905 | break; |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | template<typename Derived> |
| 2910 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2911 | const TemplateArgumentLoc &Input, |
| 2912 | TemplateArgumentLoc &Output) { |
| 2913 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2914 | switch (Arg.getKind()) { |
| 2915 | case TemplateArgument::Null: |
| 2916 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2917 | Output = Input; |
| 2918 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2919 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2920 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2921 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2922 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2923 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2924 | |
| 2925 | DI = getDerived().TransformType(DI); |
| 2926 | if (!DI) return true; |
| 2927 | |
| 2928 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2929 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2930 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2931 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2932 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2933 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2934 | DeclarationName Name; |
| 2935 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2936 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2937 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2938 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2939 | if (!D) return true; |
| 2940 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2941 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2942 | if (SourceExpr) { |
| 2943 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 2944 | Sema::ConstantEvaluated); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2945 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2946 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2950 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2951 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2952 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2953 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2954 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 2955 | if (QualifierLoc) { |
| 2956 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 2957 | if (!QualifierLoc) |
| 2958 | return true; |
| 2959 | } |
| 2960 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2961 | CXXScopeSpec SS; |
| 2962 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2963 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2964 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 2965 | Input.getTemplateNameLoc()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2966 | if (Template.isNull()) |
| 2967 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2968 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2969 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2970 | Input.getTemplateNameLoc()); |
| 2971 | return false; |
| 2972 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2973 | |
| 2974 | case TemplateArgument::TemplateExpansion: |
| 2975 | llvm_unreachable("Caller should expand pack expansions"); |
| 2976 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2977 | case TemplateArgument::Expression: { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 2978 | // Template argument expressions are constant expressions. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2979 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 2980 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2981 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2982 | Expr *InputExpr = Input.getSourceExpression(); |
| 2983 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2984 | |
Chris Lattner | 223de24 | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 2985 | ExprResult E = getDerived().TransformExpr(InputExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2986 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2987 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2988 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2989 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2990 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2991 | case TemplateArgument::Pack: { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2992 | SmallVector<TemplateArgument, 4> TransformedArgs; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2993 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2994 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2995 | AEnd = Arg.pack_end(); |
| 2996 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2997 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2998 | // FIXME: preserve source information here when we start |
| 2999 | // caring about parameter packs. |
| 3000 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3001 | TemplateArgumentLoc InputArg; |
| 3002 | TemplateArgumentLoc OutputArg; |
| 3003 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 3004 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3005 | return true; |
| 3006 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3007 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3008 | } |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 3009 | |
| 3010 | TemplateArgument *TransformedArgsPtr |
| 3011 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 3012 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 3013 | TransformedArgsPtr); |
| 3014 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 3015 | TransformedArgs.size()), |
| 3016 | Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3017 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3018 | } |
| 3019 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3020 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3021 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3022 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3025 | /// \brief Iterator adaptor that invents template argument location information |
| 3026 | /// for each of the template arguments in its underlying iterator. |
| 3027 | template<typename Derived, typename InputIterator> |
| 3028 | class TemplateArgumentLocInventIterator { |
| 3029 | TreeTransform<Derived> &Self; |
| 3030 | InputIterator Iter; |
| 3031 | |
| 3032 | public: |
| 3033 | typedef TemplateArgumentLoc value_type; |
| 3034 | typedef TemplateArgumentLoc reference; |
| 3035 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3036 | difference_type; |
| 3037 | typedef std::input_iterator_tag iterator_category; |
| 3038 | |
| 3039 | class pointer { |
| 3040 | TemplateArgumentLoc Arg; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3041 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3042 | public: |
| 3043 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 3044 | |
| 3045 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3046 | }; |
| 3047 | |
| 3048 | TemplateArgumentLocInventIterator() { } |
| 3049 | |
| 3050 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3051 | InputIterator Iter) |
| 3052 | : Self(Self), Iter(Iter) { } |
| 3053 | |
| 3054 | TemplateArgumentLocInventIterator &operator++() { |
| 3055 | ++Iter; |
| 3056 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3059 | TemplateArgumentLocInventIterator operator++(int) { |
| 3060 | TemplateArgumentLocInventIterator Old(*this); |
| 3061 | ++(*this); |
| 3062 | return Old; |
| 3063 | } |
| 3064 | |
| 3065 | reference operator*() const { |
| 3066 | TemplateArgumentLoc Result; |
| 3067 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3068 | return Result; |
| 3069 | } |
| 3070 | |
| 3071 | pointer operator->() const { return pointer(**this); } |
| 3072 | |
| 3073 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3074 | const TemplateArgumentLocInventIterator &Y) { |
| 3075 | return X.Iter == Y.Iter; |
| 3076 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3077 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3078 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3079 | const TemplateArgumentLocInventIterator &Y) { |
| 3080 | return X.Iter != Y.Iter; |
| 3081 | } |
| 3082 | }; |
| 3083 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3084 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3085 | template<typename InputIterator> |
| 3086 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3087 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3088 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3089 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3090 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3091 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3092 | |
| 3093 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3094 | // Unpack argument packs, which we translate them into separate |
| 3095 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3096 | // FIXME: We could do much better if we could guarantee that the |
| 3097 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3098 | // all of the template arguments in the argument pack. |
| 3099 | typedef TemplateArgumentLocInventIterator<Derived, |
| 3100 | TemplateArgument::pack_iterator> |
| 3101 | PackLocIterator; |
| 3102 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 3103 | In.getArgument().pack_begin()), |
| 3104 | PackLocIterator(*this, |
| 3105 | In.getArgument().pack_end()), |
| 3106 | Outputs)) |
| 3107 | return true; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3108 | |
| 3109 | continue; |
| 3110 | } |
| 3111 | |
| 3112 | if (In.getArgument().isPackExpansion()) { |
| 3113 | // We have a pack expansion, for which we will be substituting into |
| 3114 | // the pattern. |
| 3115 | SourceLocation Ellipsis; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3116 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3117 | TemplateArgumentLoc Pattern |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3118 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 3119 | getSema().Context); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3120 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3121 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3122 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3123 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 3124 | |
| 3125 | // Determine whether the set of unexpanded parameter packs can and should |
| 3126 | // be expanded. |
| 3127 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3128 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3129 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3130 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3131 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3132 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3133 | Expand, |
| 3134 | RetainExpansion, |
| 3135 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3136 | return true; |
| 3137 | |
| 3138 | if (!Expand) { |
| 3139 | // The transform has determined that we should perform a simple |
| 3140 | // transformation on the pack expansion, producing another pack |
| 3141 | // expansion. |
| 3142 | TemplateArgumentLoc OutPattern; |
| 3143 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3144 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3145 | return true; |
| 3146 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3147 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3148 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3149 | if (Out.getArgument().isNull()) |
| 3150 | return true; |
| 3151 | |
| 3152 | Outputs.addArgument(Out); |
| 3153 | continue; |
| 3154 | } |
| 3155 | |
| 3156 | // The transform has determined that we should perform an elementwise |
| 3157 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3158 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3159 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3160 | |
| 3161 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3162 | return true; |
| 3163 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3164 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3165 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3166 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3167 | if (Out.getArgument().isNull()) |
| 3168 | return true; |
| 3169 | } |
| 3170 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3171 | Outputs.addArgument(Out); |
| 3172 | } |
| 3173 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3174 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3175 | // forgetting the partially-substituted parameter pack. |
| 3176 | if (RetainExpansion) { |
| 3177 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3178 | |
| 3179 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3180 | return true; |
| 3181 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3182 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3183 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3184 | if (Out.getArgument().isNull()) |
| 3185 | return true; |
| 3186 | |
| 3187 | Outputs.addArgument(Out); |
| 3188 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3189 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3190 | continue; |
| 3191 | } |
| 3192 | |
| 3193 | // The simple case: |
| 3194 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3195 | return true; |
| 3196 | |
| 3197 | Outputs.addArgument(Out); |
| 3198 | } |
| 3199 | |
| 3200 | return false; |
| 3201 | |
| 3202 | } |
| 3203 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3204 | //===----------------------------------------------------------------------===// |
| 3205 | // Type transformation |
| 3206 | //===----------------------------------------------------------------------===// |
| 3207 | |
| 3208 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3209 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3210 | if (getDerived().AlreadyTransformed(T)) |
| 3211 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3212 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3213 | // Temporary workaround. All of these transformations should |
| 3214 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3215 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3216 | getDerived().getBaseLocation()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3217 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3218 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3219 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3220 | if (!NewDI) |
| 3221 | return QualType(); |
| 3222 | |
| 3223 | return NewDI->getType(); |
| 3224 | } |
| 3225 | |
| 3226 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3227 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3228 | // Refine the base location to the type's location. |
| 3229 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3230 | getDerived().getBaseEntity()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3231 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3232 | return DI; |
| 3233 | |
| 3234 | TypeLocBuilder TLB; |
| 3235 | |
| 3236 | TypeLoc TL = DI->getTypeLoc(); |
| 3237 | TLB.reserve(TL.getFullDataSize()); |
| 3238 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3239 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3240 | if (Result.isNull()) |
| 3241 | return 0; |
| 3242 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3243 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | template<typename Derived> |
| 3247 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3248 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3249 | switch (T.getTypeLocClass()) { |
| 3250 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3251 | #define TYPELOC(CLASS, PARENT) \ |
| 3252 | case TypeLoc::CLASS: \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3253 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3254 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3255 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3256 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3257 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3258 | return QualType(); |
| 3259 | } |
| 3260 | |
| 3261 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3262 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3263 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3264 | /// types). This is the right thing for template instantiation, but |
| 3265 | /// probably not for other clients. |
| 3266 | template<typename Derived> |
| 3267 | QualType |
| 3268 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3269 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3270 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3271 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3272 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3273 | if (Result.isNull()) |
| 3274 | return QualType(); |
| 3275 | |
| 3276 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3277 | // FIXME: this is the right thing for template instantiation, but |
| 3278 | // probably not for other clients. |
| 3279 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3280 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3281 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3282 | // Suppress Objective-C lifetime qualifiers if they don't make sense for the |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3283 | // resulting type. |
| 3284 | if (Quals.hasObjCLifetime()) { |
| 3285 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3286 | Quals.removeObjCLifetime(); |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3287 | else if (Result.getObjCLifetime()) { |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3288 | // Objective-C ARC: |
| 3289 | // A lifetime qualifier applied to a substituted template parameter |
| 3290 | // overrides the lifetime qualifier from the template argument. |
| 3291 | if (const SubstTemplateTypeParmType *SubstTypeParam |
| 3292 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3293 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3294 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3295 | Qs.removeObjCLifetime(); |
| 3296 | Replacement |
| 3297 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3298 | Qs); |
| 3299 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
| 3300 | SubstTypeParam->getReplacedParameter(), |
| 3301 | Replacement); |
| 3302 | TLB.TypeWasModifiedSafely(Result); |
| 3303 | } else { |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3304 | // Otherwise, complain about the addition of a qualifier to an |
| 3305 | // already-qualified type. |
| 3306 | SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3307 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3308 | << Result << R; |
| 3309 | |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3310 | Quals.removeObjCLifetime(); |
| 3311 | } |
| 3312 | } |
| 3313 | } |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3314 | if (!Quals.empty()) { |
| 3315 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3316 | TLB.push<QualifiedTypeLoc>(Result); |
| 3317 | // No location information to preserve. |
| 3318 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3319 | |
| 3320 | return Result; |
| 3321 | } |
| 3322 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3323 | template<typename Derived> |
| 3324 | TypeLoc |
| 3325 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3326 | QualType ObjectType, |
| 3327 | NamedDecl *UnqualLookup, |
| 3328 | CXXScopeSpec &SS) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3329 | QualType T = TL.getType(); |
| 3330 | if (getDerived().AlreadyTransformed(T)) |
| 3331 | return TL; |
| 3332 | |
| 3333 | TypeLocBuilder TLB; |
| 3334 | QualType Result; |
| 3335 | |
| 3336 | if (isa<TemplateSpecializationType>(T)) { |
| 3337 | TemplateSpecializationTypeLoc SpecTL |
| 3338 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3339 | |
| 3340 | TemplateName Template = |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3341 | getDerived().TransformTemplateName(SS, |
| 3342 | SpecTL.getTypePtr()->getTemplateName(), |
| 3343 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3344 | ObjectType, UnqualLookup); |
| 3345 | if (Template.isNull()) |
| 3346 | return TypeLoc(); |
| 3347 | |
| 3348 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3349 | Template); |
| 3350 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3351 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3352 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3353 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3354 | TemplateName Template |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3355 | = getDerived().RebuildTemplateName(SS, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3356 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3357 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3358 | ObjectType, UnqualLookup); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3359 | if (Template.isNull()) |
| 3360 | return TypeLoc(); |
| 3361 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3362 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3363 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3364 | Template, |
| 3365 | SS); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3366 | } else { |
| 3367 | // Nothing special needs to be done for these. |
| 3368 | Result = getDerived().TransformType(TLB, TL); |
| 3369 | } |
| 3370 | |
| 3371 | if (Result.isNull()) |
| 3372 | return TypeLoc(); |
| 3373 | |
| 3374 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3375 | } |
| 3376 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3377 | template<typename Derived> |
| 3378 | TypeSourceInfo * |
| 3379 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3380 | QualType ObjectType, |
| 3381 | NamedDecl *UnqualLookup, |
| 3382 | CXXScopeSpec &SS) { |
| 3383 | // FIXME: Painfully copy-paste from the above! |
| 3384 | |
| 3385 | QualType T = TSInfo->getType(); |
| 3386 | if (getDerived().AlreadyTransformed(T)) |
| 3387 | return TSInfo; |
| 3388 | |
| 3389 | TypeLocBuilder TLB; |
| 3390 | QualType Result; |
| 3391 | |
| 3392 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3393 | if (isa<TemplateSpecializationType>(T)) { |
| 3394 | TemplateSpecializationTypeLoc SpecTL |
| 3395 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3396 | |
| 3397 | TemplateName Template |
| 3398 | = getDerived().TransformTemplateName(SS, |
| 3399 | SpecTL.getTypePtr()->getTemplateName(), |
| 3400 | SpecTL.getTemplateNameLoc(), |
| 3401 | ObjectType, UnqualLookup); |
| 3402 | if (Template.isNull()) |
| 3403 | return 0; |
| 3404 | |
| 3405 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3406 | Template); |
| 3407 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3408 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3409 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3410 | |
| 3411 | TemplateName Template |
| 3412 | = getDerived().RebuildTemplateName(SS, |
| 3413 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3414 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3415 | ObjectType, UnqualLookup); |
| 3416 | if (Template.isNull()) |
| 3417 | return 0; |
| 3418 | |
| 3419 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| 3420 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3421 | Template, |
| 3422 | SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3423 | } else { |
| 3424 | // Nothing special needs to be done for these. |
| 3425 | Result = getDerived().TransformType(TLB, TL); |
| 3426 | } |
| 3427 | |
| 3428 | if (Result.isNull()) |
| 3429 | return 0; |
| 3430 | |
| 3431 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3432 | } |
| 3433 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3434 | template <class TyLoc> static inline |
| 3435 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3436 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3437 | NewT.setNameLoc(T.getNameLoc()); |
| 3438 | return T.getType(); |
| 3439 | } |
| 3440 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3441 | template<typename Derived> |
| 3442 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3443 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3444 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3445 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3446 | if (T.needsExtraLocalData()) |
| 3447 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3448 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3449 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3450 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3451 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3452 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3453 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3454 | // FIXME: recurse? |
| 3455 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3456 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3457 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3458 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3459 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3460 | PointerTypeLoc TL) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3461 | QualType PointeeType |
| 3462 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3463 | if (PointeeType.isNull()) |
| 3464 | return QualType(); |
| 3465 | |
| 3466 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3467 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3468 | // A dependent pointer type 'T *' has is being transformed such |
| 3469 | // that an Objective-C class type is being replaced for 'T'. The |
| 3470 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3471 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3472 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3473 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3474 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3475 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3476 | return Result; |
| 3477 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3478 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3479 | if (getDerived().AlwaysRebuild() || |
| 3480 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3481 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3482 | if (Result.isNull()) |
| 3483 | return QualType(); |
| 3484 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3485 | |
| 3486 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3487 | // pointing to. |
| 3488 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
| 3489 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3490 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3491 | NewT.setSigilLoc(TL.getSigilLoc()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3492 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3494 | |
| 3495 | template<typename Derived> |
| 3496 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3497 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3498 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3499 | QualType PointeeType |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3500 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3501 | if (PointeeType.isNull()) |
| 3502 | return QualType(); |
| 3503 | |
| 3504 | QualType Result = TL.getType(); |
| 3505 | if (getDerived().AlwaysRebuild() || |
| 3506 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3507 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3508 | TL.getSigilLoc()); |
| 3509 | if (Result.isNull()) |
| 3510 | return QualType(); |
| 3511 | } |
| 3512 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3513 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3514 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3515 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3518 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3519 | /// don't care whether the type itself is an l-value type or an r-value |
| 3520 | /// type; we only care if the type was *written* as an l-value type |
| 3521 | /// or an r-value type. |
| 3522 | template<typename Derived> |
| 3523 | QualType |
| 3524 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3525 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3526 | const ReferenceType *T = TL.getTypePtr(); |
| 3527 | |
| 3528 | // Note that this works with the pointee-as-written. |
| 3529 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3530 | if (PointeeType.isNull()) |
| 3531 | return QualType(); |
| 3532 | |
| 3533 | QualType Result = TL.getType(); |
| 3534 | if (getDerived().AlwaysRebuild() || |
| 3535 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3536 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3537 | T->isSpelledAsLValue(), |
| 3538 | TL.getSigilLoc()); |
| 3539 | if (Result.isNull()) |
| 3540 | return QualType(); |
| 3541 | } |
| 3542 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3543 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3544 | // referring to. |
| 3545 | TLB.TypeWasModifiedSafely( |
| 3546 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3547 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3548 | // r-value references can be rebuilt as l-value references. |
| 3549 | ReferenceTypeLoc NewTL; |
| 3550 | if (isa<LValueReferenceType>(Result)) |
| 3551 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3552 | else |
| 3553 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3554 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3555 | |
| 3556 | return Result; |
| 3557 | } |
| 3558 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3559 | template<typename Derived> |
| 3560 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3561 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3562 | LValueReferenceTypeLoc TL) { |
| 3563 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3566 | template<typename Derived> |
| 3567 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3568 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3569 | RValueReferenceTypeLoc TL) { |
| 3570 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3571 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3572 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3573 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3575 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3576 | MemberPointerTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3577 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3578 | if (PointeeType.isNull()) |
| 3579 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3580 | |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3581 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3582 | TypeSourceInfo* NewClsTInfo = 0; |
| 3583 | if (OldClsTInfo) { |
| 3584 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3585 | if (!NewClsTInfo) |
| 3586 | return QualType(); |
| 3587 | } |
| 3588 | |
| 3589 | const MemberPointerType *T = TL.getTypePtr(); |
| 3590 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3591 | QualType NewClsType; |
| 3592 | if (NewClsTInfo) |
| 3593 | NewClsType = NewClsTInfo->getType(); |
| 3594 | else { |
| 3595 | NewClsType = getDerived().TransformType(OldClsType); |
| 3596 | if (NewClsType.isNull()) |
| 3597 | return QualType(); |
| 3598 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3600 | QualType Result = TL.getType(); |
| 3601 | if (getDerived().AlwaysRebuild() || |
| 3602 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3603 | NewClsType != OldClsType) { |
| 3604 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3605 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3606 | if (Result.isNull()) |
| 3607 | return QualType(); |
| 3608 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3609 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3610 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3611 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3612 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3613 | |
| 3614 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3617 | template<typename Derived> |
| 3618 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3619 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3620 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3621 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3622 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3623 | if (ElementType.isNull()) |
| 3624 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3625 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3626 | QualType Result = TL.getType(); |
| 3627 | if (getDerived().AlwaysRebuild() || |
| 3628 | ElementType != T->getElementType()) { |
| 3629 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3630 | T->getSizeModifier(), |
| 3631 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3632 | T->getIndexTypeCVRQualifiers(), |
| 3633 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3634 | if (Result.isNull()) |
| 3635 | return QualType(); |
| 3636 | } |
Eli Friedman | 457a377 | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 3637 | |
| 3638 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 3639 | // a ConstantArrayType is allowed to have an element type which is a |
| 3640 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 3641 | // types have the same location layout. |
| 3642 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3643 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3644 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3646 | Expr *Size = TL.getSizeExpr(); |
| 3647 | if (Size) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3648 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3649 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3650 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 3651 | } |
| 3652 | NewTL.setSizeExpr(Size); |
| 3653 | |
| 3654 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3655 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3656 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3657 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3658 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3659 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3660 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3661 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3662 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3663 | if (ElementType.isNull()) |
| 3664 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3666 | QualType Result = TL.getType(); |
| 3667 | if (getDerived().AlwaysRebuild() || |
| 3668 | ElementType != T->getElementType()) { |
| 3669 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3670 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3671 | T->getIndexTypeCVRQualifiers(), |
| 3672 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3673 | if (Result.isNull()) |
| 3674 | return QualType(); |
| 3675 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3676 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3677 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3678 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3679 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3680 | NewTL.setSizeExpr(0); |
| 3681 | |
| 3682 | return Result; |
| 3683 | } |
| 3684 | |
| 3685 | template<typename Derived> |
| 3686 | QualType |
| 3687 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3688 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3689 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3690 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3691 | if (ElementType.isNull()) |
| 3692 | return QualType(); |
| 3693 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3694 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3695 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3696 | if (SizeResult.isInvalid()) |
| 3697 | return QualType(); |
| 3698 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3699 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3700 | |
| 3701 | QualType Result = TL.getType(); |
| 3702 | if (getDerived().AlwaysRebuild() || |
| 3703 | ElementType != T->getElementType() || |
| 3704 | Size != T->getSizeExpr()) { |
| 3705 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3706 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3707 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3708 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3709 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3710 | if (Result.isNull()) |
| 3711 | return QualType(); |
| 3712 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3713 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3714 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3715 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3716 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3717 | NewTL.setSizeExpr(Size); |
| 3718 | |
| 3719 | return Result; |
| 3720 | } |
| 3721 | |
| 3722 | template<typename Derived> |
| 3723 | QualType |
| 3724 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3725 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3726 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3727 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3728 | if (ElementType.isNull()) |
| 3729 | return QualType(); |
| 3730 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3731 | // Array bounds are constant expressions. |
| 3732 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3733 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3734 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3735 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3736 | Expr *origSize = TL.getSizeExpr(); |
| 3737 | if (!origSize) origSize = T->getSizeExpr(); |
| 3738 | |
| 3739 | ExprResult sizeResult |
| 3740 | = getDerived().TransformExpr(origSize); |
| 3741 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3742 | return QualType(); |
| 3743 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3744 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3745 | |
| 3746 | QualType Result = TL.getType(); |
| 3747 | if (getDerived().AlwaysRebuild() || |
| 3748 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3749 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3750 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3751 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3752 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3753 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3754 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3755 | if (Result.isNull()) |
| 3756 | return QualType(); |
| 3757 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3758 | |
| 3759 | // We might have any sort of array type now, but fortunately they |
| 3760 | // all have the same location layout. |
| 3761 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3762 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3763 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3764 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3765 | |
| 3766 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3767 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3768 | |
| 3769 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3770 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3771 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3772 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3773 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3774 | |
| 3775 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3776 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3777 | if (ElementType.isNull()) |
| 3778 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3780 | // Vector sizes are constant expressions. |
| 3781 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3782 | Sema::ConstantEvaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3783 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3784 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3785 | if (Size.isInvalid()) |
| 3786 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3788 | QualType Result = TL.getType(); |
| 3789 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3790 | ElementType != T->getElementType() || |
| 3791 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3792 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3793 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3794 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3795 | if (Result.isNull()) |
| 3796 | return QualType(); |
| 3797 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3798 | |
| 3799 | // Result might be dependent or not. |
| 3800 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3801 | DependentSizedExtVectorTypeLoc NewTL |
| 3802 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3803 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3804 | } else { |
| 3805 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3806 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3807 | } |
| 3808 | |
| 3809 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3810 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | |
| 3812 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3813 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3814 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3815 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3816 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3817 | if (ElementType.isNull()) |
| 3818 | return QualType(); |
| 3819 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3820 | QualType Result = TL.getType(); |
| 3821 | if (getDerived().AlwaysRebuild() || |
| 3822 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3823 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3824 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3825 | if (Result.isNull()) |
| 3826 | return QualType(); |
| 3827 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3828 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3829 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3830 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3831 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3832 | return Result; |
| 3833 | } |
| 3834 | |
| 3835 | template<typename Derived> |
| 3836 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3837 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3838 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3839 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3840 | if (ElementType.isNull()) |
| 3841 | return QualType(); |
| 3842 | |
| 3843 | QualType Result = TL.getType(); |
| 3844 | if (getDerived().AlwaysRebuild() || |
| 3845 | ElementType != T->getElementType()) { |
| 3846 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3847 | T->getNumElements(), |
| 3848 | /*FIXME*/ SourceLocation()); |
| 3849 | if (Result.isNull()) |
| 3850 | return QualType(); |
| 3851 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3852 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3853 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3854 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3855 | |
| 3856 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3857 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3858 | |
| 3859 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3860 | ParmVarDecl * |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3861 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3862 | int indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 3863 | llvm::Optional<unsigned> NumExpansions, |
| 3864 | bool ExpectParameterPack) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3865 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3866 | TypeSourceInfo *NewDI = 0; |
| 3867 | |
| 3868 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3869 | // If we're substituting into a pack expansion type and we know the |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 3870 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3871 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3872 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3873 | |
| 3874 | TypeLocBuilder TLB; |
| 3875 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3876 | TLB.reserve(NewTL.getFullDataSize()); |
| 3877 | |
| 3878 | QualType Result = getDerived().TransformType(TLB, |
| 3879 | OldExpansionTL.getPatternLoc()); |
| 3880 | if (Result.isNull()) |
| 3881 | return 0; |
| 3882 | |
| 3883 | Result = RebuildPackExpansionType(Result, |
| 3884 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3885 | OldExpansionTL.getEllipsisLoc(), |
| 3886 | NumExpansions); |
| 3887 | if (Result.isNull()) |
| 3888 | return 0; |
| 3889 | |
| 3890 | PackExpansionTypeLoc NewExpansionTL |
| 3891 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3892 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3893 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3894 | } else |
| 3895 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3896 | if (!NewDI) |
| 3897 | return 0; |
| 3898 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3899 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3900 | return OldParm; |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3901 | |
| 3902 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 3903 | OldParm->getDeclContext(), |
| 3904 | OldParm->getInnerLocStart(), |
| 3905 | OldParm->getLocation(), |
| 3906 | OldParm->getIdentifier(), |
| 3907 | NewDI->getType(), |
| 3908 | NewDI, |
| 3909 | OldParm->getStorageClass(), |
| 3910 | OldParm->getStorageClassAsWritten(), |
| 3911 | /* DefArg */ NULL); |
| 3912 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 3913 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 3914 | return newParm; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | template<typename Derived> |
| 3918 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3919 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3920 | ParmVarDecl **Params, unsigned NumParams, |
| 3921 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3922 | SmallVectorImpl<QualType> &OutParamTypes, |
| 3923 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3924 | int indexAdjustment = 0; |
| 3925 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3926 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3927 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3928 | assert(OldParm->getFunctionScopeIndex() == i); |
| 3929 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3930 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3931 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3932 | if (OldParm->isParameterPack()) { |
| 3933 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3934 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3935 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3936 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3937 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3938 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3939 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3940 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3941 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 3942 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3943 | // Determine whether we should expand the parameter packs. |
| 3944 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3945 | bool RetainExpansion = false; |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3946 | llvm::Optional<unsigned> OrigNumExpansions |
| 3947 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3948 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3949 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3950 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3951 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3952 | ShouldExpand, |
| 3953 | RetainExpansion, |
| 3954 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3955 | return true; |
| 3956 | } |
| 3957 | |
| 3958 | if (ShouldExpand) { |
| 3959 | // Expand the function parameter pack into multiple, separate |
| 3960 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3961 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3962 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3963 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3964 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3965 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3966 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 3967 | OrigNumExpansions, |
| 3968 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3969 | if (!NewParm) |
| 3970 | return true; |
| 3971 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3972 | OutParamTypes.push_back(NewParm->getType()); |
| 3973 | if (PVars) |
| 3974 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3975 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3976 | |
| 3977 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3978 | // forgetting the partially-substituted parameter pack. |
| 3979 | if (RetainExpansion) { |
| 3980 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3981 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3982 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3983 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 3984 | OrigNumExpansions, |
| 3985 | /*ExpectParameterPack=*/false); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3986 | if (!NewParm) |
| 3987 | return true; |
| 3988 | |
| 3989 | OutParamTypes.push_back(NewParm->getType()); |
| 3990 | if (PVars) |
| 3991 | PVars->push_back(NewParm); |
| 3992 | } |
| 3993 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3994 | // The next parameter should have the same adjustment as the |
| 3995 | // last thing we pushed, but we post-incremented indexAdjustment |
| 3996 | // on every push. Also, if we push nothing, the adjustment should |
| 3997 | // go down by one. |
| 3998 | indexAdjustment--; |
| 3999 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4000 | // We're done with the pack expansion. |
| 4001 | continue; |
| 4002 | } |
| 4003 | |
| 4004 | // We'll substitute the parameter now without expanding the pack |
| 4005 | // expansion. |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4006 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4007 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4008 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4009 | NumExpansions, |
| 4010 | /*ExpectParameterPack=*/true); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4011 | } else { |
| 4012 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4013 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4014 | llvm::Optional<unsigned>(), |
| 4015 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4016 | } |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4017 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4018 | if (!NewParm) |
| 4019 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4020 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4021 | OutParamTypes.push_back(NewParm->getType()); |
| 4022 | if (PVars) |
| 4023 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4024 | continue; |
| 4025 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4026 | |
| 4027 | // Deal with the possibility that we don't have a parameter |
| 4028 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4029 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4030 | bool IsPackExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4031 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4032 | QualType NewType; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4033 | if (const PackExpansionType *Expansion |
| 4034 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4035 | // We have a function parameter pack that may need to be expanded. |
| 4036 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4037 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4038 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 4039 | |
| 4040 | // Determine whether we should expand the parameter packs. |
| 4041 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4042 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4043 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 4044 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4045 | ShouldExpand, |
| 4046 | RetainExpansion, |
| 4047 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4048 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | if (ShouldExpand) { |
| 4052 | // Expand the function parameter pack into multiple, separate |
| 4053 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4054 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4055 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4056 | QualType NewType = getDerived().TransformType(Pattern); |
| 4057 | if (NewType.isNull()) |
| 4058 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4059 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4060 | OutParamTypes.push_back(NewType); |
| 4061 | if (PVars) |
| 4062 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | // We're done with the pack expansion. |
| 4066 | continue; |
| 4067 | } |
| 4068 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4069 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4070 | // forgetting the partially-substituted parameter pack. |
| 4071 | if (RetainExpansion) { |
| 4072 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4073 | QualType NewType = getDerived().TransformType(Pattern); |
| 4074 | if (NewType.isNull()) |
| 4075 | return true; |
| 4076 | |
| 4077 | OutParamTypes.push_back(NewType); |
| 4078 | if (PVars) |
| 4079 | PVars->push_back(0); |
| 4080 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4081 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4082 | // We'll substitute the parameter now without expanding the pack |
| 4083 | // expansion. |
| 4084 | OldType = Expansion->getPattern(); |
| 4085 | IsPackExpansion = true; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4086 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4087 | NewType = getDerived().TransformType(OldType); |
| 4088 | } else { |
| 4089 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4090 | } |
| 4091 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4092 | if (NewType.isNull()) |
| 4093 | return true; |
| 4094 | |
| 4095 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4096 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4097 | NumExpansions); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4098 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4099 | OutParamTypes.push_back(NewType); |
| 4100 | if (PVars) |
| 4101 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4102 | } |
| 4103 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4104 | #ifndef NDEBUG |
| 4105 | if (PVars) { |
| 4106 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4107 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4108 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4109 | } |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4110 | #endif |
| 4111 | |
| 4112 | return false; |
| 4113 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4114 | |
| 4115 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4117 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4118 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4119 | // Transform the parameters and return type. |
| 4120 | // |
| 4121 | // We instantiate in source order, with the return type first followed by |
| 4122 | // the parameters, because users tend to expect this (even if they shouldn't |
| 4123 | // rely on it!). |
| 4124 | // |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4125 | // When the function has a trailing return type, we instantiate the |
| 4126 | // parameters before the return type, since the return type can then refer |
| 4127 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4128 | // |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4129 | SmallVector<QualType, 4> ParamTypes; |
| 4130 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4131 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4132 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4133 | QualType ResultType; |
| 4134 | |
| 4135 | if (TL.getTrailingReturn()) { |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4136 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 4137 | TL.getParmArray(), |
| 4138 | TL.getNumArgs(), |
| 4139 | TL.getTypePtr()->arg_type_begin(), |
| 4140 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4141 | return QualType(); |
| 4142 | |
| 4143 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4144 | if (ResultType.isNull()) |
| 4145 | return QualType(); |
| 4146 | } |
| 4147 | else { |
| 4148 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4149 | if (ResultType.isNull()) |
| 4150 | return QualType(); |
| 4151 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4152 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 4153 | TL.getParmArray(), |
| 4154 | TL.getNumArgs(), |
| 4155 | TL.getTypePtr()->arg_type_begin(), |
| 4156 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4157 | return QualType(); |
| 4158 | } |
| 4159 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4160 | QualType Result = TL.getType(); |
| 4161 | if (getDerived().AlwaysRebuild() || |
| 4162 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4163 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4164 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 4165 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 4166 | ParamTypes.data(), |
| 4167 | ParamTypes.size(), |
| 4168 | T->isVariadic(), |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 4169 | T->hasTrailingReturn(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4170 | T->getTypeQuals(), |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 4171 | T->getRefQualifier(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4172 | T->getExtInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4173 | if (Result.isNull()) |
| 4174 | return QualType(); |
| 4175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4176 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4177 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4178 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 4179 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4180 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4181 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4182 | NewTL.setArg(i, ParamDecls[i]); |
| 4183 | |
| 4184 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4186 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4187 | template<typename Derived> |
| 4188 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4189 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4190 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4191 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4192 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4193 | if (ResultType.isNull()) |
| 4194 | return QualType(); |
| 4195 | |
| 4196 | QualType Result = TL.getType(); |
| 4197 | if (getDerived().AlwaysRebuild() || |
| 4198 | ResultType != T->getResultType()) |
| 4199 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4200 | |
| 4201 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4202 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 4203 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4204 | NewTL.setTrailingReturn(false); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4205 | |
| 4206 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4207 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4209 | template<typename Derived> QualType |
| 4210 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4211 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4212 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4213 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4214 | if (!D) |
| 4215 | return QualType(); |
| 4216 | |
| 4217 | QualType Result = TL.getType(); |
| 4218 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4219 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4220 | if (Result.isNull()) |
| 4221 | return QualType(); |
| 4222 | } |
| 4223 | |
| 4224 | // We might get an arbitrary type spec type back. We should at |
| 4225 | // least always get a type spec type, though. |
| 4226 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4227 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4228 | |
| 4229 | return Result; |
| 4230 | } |
| 4231 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4232 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4233 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4234 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4235 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4236 | TypedefNameDecl *Typedef |
| 4237 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4238 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4239 | if (!Typedef) |
| 4240 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4241 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4242 | QualType Result = TL.getType(); |
| 4243 | if (getDerived().AlwaysRebuild() || |
| 4244 | Typedef != T->getDecl()) { |
| 4245 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4246 | if (Result.isNull()) |
| 4247 | return QualType(); |
| 4248 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4249 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4250 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4251 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4252 | |
| 4253 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4256 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4257 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4258 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4259 | // typeof expressions are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4260 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4262 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4263 | if (E.isInvalid()) |
| 4264 | return QualType(); |
| 4265 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4266 | QualType Result = TL.getType(); |
| 4267 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4268 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4269 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4270 | if (Result.isNull()) |
| 4271 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4272 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4273 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4274 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4275 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4276 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4277 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4278 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4279 | |
| 4280 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4282 | |
| 4283 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4284 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4285 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4286 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4287 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4288 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4289 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4291 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4292 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4293 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4294 | if (Result.isNull()) |
| 4295 | return QualType(); |
| 4296 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4297 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4298 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4299 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4300 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4301 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4302 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4303 | |
| 4304 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4306 | |
| 4307 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4308 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4309 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4310 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4311 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4312 | // decltype expressions are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4313 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4315 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4316 | if (E.isInvalid()) |
| 4317 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4319 | QualType Result = TL.getType(); |
| 4320 | if (getDerived().AlwaysRebuild() || |
| 4321 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4322 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4323 | if (Result.isNull()) |
| 4324 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4325 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4326 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4327 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4328 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4329 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4330 | |
| 4331 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4335 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4336 | TypeLocBuilder &TLB, |
| 4337 | UnaryTransformTypeLoc TL) { |
| 4338 | QualType Result = TL.getType(); |
| 4339 | if (Result->isDependentType()) { |
| 4340 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4341 | QualType NewBase = |
| 4342 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4343 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4344 | T->getUTTKind(), |
| 4345 | TL.getKWLoc()); |
| 4346 | if (Result.isNull()) |
| 4347 | return QualType(); |
| 4348 | } |
| 4349 | |
| 4350 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4351 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4352 | NewTL.setParensRange(TL.getParensRange()); |
| 4353 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4354 | return Result; |
| 4355 | } |
| 4356 | |
| 4357 | template<typename Derived> |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4358 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4359 | AutoTypeLoc TL) { |
| 4360 | const AutoType *T = TL.getTypePtr(); |
| 4361 | QualType OldDeduced = T->getDeducedType(); |
| 4362 | QualType NewDeduced; |
| 4363 | if (!OldDeduced.isNull()) { |
| 4364 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4365 | if (NewDeduced.isNull()) |
| 4366 | return QualType(); |
| 4367 | } |
| 4368 | |
| 4369 | QualType Result = TL.getType(); |
| 4370 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4371 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4372 | if (Result.isNull()) |
| 4373 | return QualType(); |
| 4374 | } |
| 4375 | |
| 4376 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4377 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4378 | |
| 4379 | return Result; |
| 4380 | } |
| 4381 | |
| 4382 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4383 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4384 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4385 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4386 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4387 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4388 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4389 | if (!Record) |
| 4390 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4392 | QualType Result = TL.getType(); |
| 4393 | if (getDerived().AlwaysRebuild() || |
| 4394 | Record != T->getDecl()) { |
| 4395 | Result = getDerived().RebuildRecordType(Record); |
| 4396 | if (Result.isNull()) |
| 4397 | return QualType(); |
| 4398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4400 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4401 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4402 | |
| 4403 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4404 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4405 | |
| 4406 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4407 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4408 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4409 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4410 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4411 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4412 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4413 | if (!Enum) |
| 4414 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4416 | QualType Result = TL.getType(); |
| 4417 | if (getDerived().AlwaysRebuild() || |
| 4418 | Enum != T->getDecl()) { |
| 4419 | Result = getDerived().RebuildEnumType(Enum); |
| 4420 | if (Result.isNull()) |
| 4421 | return QualType(); |
| 4422 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4423 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4424 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4425 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4426 | |
| 4427 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4428 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4429 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4430 | template<typename Derived> |
| 4431 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4432 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4433 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4434 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4435 | TL.getTypePtr()->getDecl()); |
| 4436 | if (!D) return QualType(); |
| 4437 | |
| 4438 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4439 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4440 | return T; |
| 4441 | } |
| 4442 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4443 | template<typename Derived> |
| 4444 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4445 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4446 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4447 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4448 | } |
| 4449 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4450 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4451 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4452 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4453 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4454 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| 4455 | |
| 4456 | // Substitute into the replacement type, which itself might involve something |
| 4457 | // that needs to be transformed. This only tends to occur with default |
| 4458 | // template arguments of template template parameters. |
| 4459 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4460 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4461 | if (Replacement.isNull()) |
| 4462 | return QualType(); |
| 4463 | |
| 4464 | // Always canonicalize the replacement type. |
| 4465 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4466 | QualType Result |
| 4467 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
| 4468 | Replacement); |
| 4469 | |
| 4470 | // Propagate type-source information. |
| 4471 | SubstTemplateTypeParmTypeLoc NewTL |
| 4472 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4473 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4474 | return Result; |
| 4475 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4479 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4480 | TypeLocBuilder &TLB, |
| 4481 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4482 | return TransformTypeSpecType(TLB, TL); |
| 4483 | } |
| 4484 | |
| 4485 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4486 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4487 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4488 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4489 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4490 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4491 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4492 | // because we can't have a dependent nested-name-specifier anyway. |
| 4493 | CXXScopeSpec SS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4495 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4496 | TL.getTemplateNameLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4497 | if (Template.isNull()) |
| 4498 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4499 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4500 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4501 | } |
| 4502 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4503 | template<typename Derived> |
| 4504 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4505 | AtomicTypeLoc TL) { |
| 4506 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4507 | if (ValueType.isNull()) |
| 4508 | return QualType(); |
| 4509 | |
| 4510 | QualType Result = TL.getType(); |
| 4511 | if (getDerived().AlwaysRebuild() || |
| 4512 | ValueType != TL.getValueLoc().getType()) { |
| 4513 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4514 | if (Result.isNull()) |
| 4515 | return QualType(); |
| 4516 | } |
| 4517 | |
| 4518 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4519 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4520 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4521 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4522 | |
| 4523 | return Result; |
| 4524 | } |
| 4525 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4526 | namespace { |
| 4527 | /// \brief Simple iterator that traverses the template arguments in a |
| 4528 | /// container that provides a \c getArgLoc() member function. |
| 4529 | /// |
| 4530 | /// This iterator is intended to be used with the iterator form of |
| 4531 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4532 | template<typename ArgLocContainer> |
| 4533 | class TemplateArgumentLocContainerIterator { |
| 4534 | ArgLocContainer *Container; |
| 4535 | unsigned Index; |
| 4536 | |
| 4537 | public: |
| 4538 | typedef TemplateArgumentLoc value_type; |
| 4539 | typedef TemplateArgumentLoc reference; |
| 4540 | typedef int difference_type; |
| 4541 | typedef std::input_iterator_tag iterator_category; |
| 4542 | |
| 4543 | class pointer { |
| 4544 | TemplateArgumentLoc Arg; |
| 4545 | |
| 4546 | public: |
| 4547 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4548 | |
| 4549 | const TemplateArgumentLoc *operator->() const { |
| 4550 | return &Arg; |
| 4551 | } |
| 4552 | }; |
| 4553 | |
| 4554 | |
| 4555 | TemplateArgumentLocContainerIterator() {} |
| 4556 | |
| 4557 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4558 | unsigned Index) |
| 4559 | : Container(&Container), Index(Index) { } |
| 4560 | |
| 4561 | TemplateArgumentLocContainerIterator &operator++() { |
| 4562 | ++Index; |
| 4563 | return *this; |
| 4564 | } |
| 4565 | |
| 4566 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4567 | TemplateArgumentLocContainerIterator Old(*this); |
| 4568 | ++(*this); |
| 4569 | return Old; |
| 4570 | } |
| 4571 | |
| 4572 | TemplateArgumentLoc operator*() const { |
| 4573 | return Container->getArgLoc(Index); |
| 4574 | } |
| 4575 | |
| 4576 | pointer operator->() const { |
| 4577 | return pointer(Container->getArgLoc(Index)); |
| 4578 | } |
| 4579 | |
| 4580 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4581 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4582 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4583 | } |
| 4584 | |
| 4585 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4586 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4587 | return !(X == Y); |
| 4588 | } |
| 4589 | }; |
| 4590 | } |
| 4591 | |
| 4592 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4593 | template <typename Derived> |
| 4594 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4595 | TypeLocBuilder &TLB, |
| 4596 | TemplateSpecializationTypeLoc TL, |
| 4597 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4598 | TemplateArgumentListInfo NewTemplateArgs; |
| 4599 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4600 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4601 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4602 | ArgIterator; |
| 4603 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4604 | ArgIterator(TL, TL.getNumArgs()), |
| 4605 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4606 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4607 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4608 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4609 | |
| 4610 | QualType Result = |
| 4611 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4612 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4613 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4614 | |
| 4615 | if (!Result.isNull()) { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4616 | // Specializations of template template parameters are represented as |
| 4617 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4618 | // within a dependent context can transform them into |
| 4619 | // DependentTemplateSpecializationTypes. |
| 4620 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4621 | DependentTemplateSpecializationTypeLoc NewTL |
| 4622 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4623 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4624 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4625 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4626 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4627 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4628 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4629 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4630 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4631 | return Result; |
| 4632 | } |
| 4633 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4634 | TemplateSpecializationTypeLoc NewTL |
| 4635 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4636 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4637 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4638 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4639 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4640 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4641 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4642 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4643 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4644 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4645 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4646 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4647 | template <typename Derived> |
| 4648 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4649 | TypeLocBuilder &TLB, |
| 4650 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4651 | TemplateName Template, |
| 4652 | CXXScopeSpec &SS) { |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4653 | TemplateArgumentListInfo NewTemplateArgs; |
| 4654 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4655 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4656 | typedef TemplateArgumentLocContainerIterator< |
| 4657 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4658 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4659 | ArgIterator(TL, TL.getNumArgs()), |
| 4660 | NewTemplateArgs)) |
| 4661 | return QualType(); |
| 4662 | |
| 4663 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4664 | |
| 4665 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4666 | QualType Result |
| 4667 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4668 | TL.getTypePtr()->getKeyword(), |
| 4669 | DTN->getQualifier(), |
| 4670 | DTN->getIdentifier(), |
| 4671 | NewTemplateArgs); |
| 4672 | |
| 4673 | DependentTemplateSpecializationTypeLoc NewTL |
| 4674 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4675 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4676 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4677 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4678 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4679 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4680 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4681 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4682 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4683 | return Result; |
| 4684 | } |
| 4685 | |
| 4686 | QualType Result |
| 4687 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4688 | TL.getTemplateNameLoc(), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4689 | NewTemplateArgs); |
| 4690 | |
| 4691 | if (!Result.isNull()) { |
| 4692 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4693 | TemplateSpecializationTypeLoc NewTL |
| 4694 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4695 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4696 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4697 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4698 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4699 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4700 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4701 | } |
| 4702 | |
| 4703 | return Result; |
| 4704 | } |
| 4705 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4706 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4707 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4708 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4709 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4710 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4711 | |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4712 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4713 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4714 | if (TL.getQualifierLoc()) { |
| 4715 | QualifierLoc |
| 4716 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4717 | if (!QualifierLoc) |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4718 | return QualType(); |
| 4719 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4720 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4721 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4722 | if (NamedT.isNull()) |
| 4723 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4724 | |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4725 | // C++0x [dcl.type.elab]p2: |
| 4726 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4727 | // resolves to an alias template specialization, the |
| 4728 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 1804174 | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 4729 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 4730 | if (const TemplateSpecializationType *TST = |
| 4731 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4732 | TemplateName Template = TST->getTemplateName(); |
| 4733 | if (TypeAliasTemplateDecl *TAT = |
| 4734 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4735 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4736 | diag::err_tag_reference_non_tag) << 4; |
| 4737 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4738 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4739 | } |
| 4740 | } |
| 4741 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4742 | QualType Result = TL.getType(); |
| 4743 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4744 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4745 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4746 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4747 | T->getKeyword(), |
| 4748 | QualifierLoc, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4749 | if (Result.isNull()) |
| 4750 | return QualType(); |
| 4751 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4752 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4753 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4754 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4755 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4756 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4758 | |
| 4759 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4760 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4761 | TypeLocBuilder &TLB, |
| 4762 | AttributedTypeLoc TL) { |
| 4763 | const AttributedType *oldType = TL.getTypePtr(); |
| 4764 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4765 | if (modifiedType.isNull()) |
| 4766 | return QualType(); |
| 4767 | |
| 4768 | QualType result = TL.getType(); |
| 4769 | |
| 4770 | // FIXME: dependent operand expressions? |
| 4771 | if (getDerived().AlwaysRebuild() || |
| 4772 | modifiedType != oldType->getModifiedType()) { |
| 4773 | // TODO: this is really lame; we should really be rebuilding the |
| 4774 | // equivalent type from first principles. |
| 4775 | QualType equivalentType |
| 4776 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4777 | if (equivalentType.isNull()) |
| 4778 | return QualType(); |
| 4779 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4780 | modifiedType, |
| 4781 | equivalentType); |
| 4782 | } |
| 4783 | |
| 4784 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4785 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4786 | if (TL.hasAttrOperand()) |
| 4787 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4788 | if (TL.hasAttrExprOperand()) |
| 4789 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4790 | else if (TL.hasAttrEnumOperand()) |
| 4791 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4792 | |
| 4793 | return result; |
| 4794 | } |
| 4795 | |
| 4796 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4797 | QualType |
| 4798 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4799 | ParenTypeLoc TL) { |
| 4800 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4801 | if (Inner.isNull()) |
| 4802 | return QualType(); |
| 4803 | |
| 4804 | QualType Result = TL.getType(); |
| 4805 | if (getDerived().AlwaysRebuild() || |
| 4806 | Inner != TL.getInnerLoc().getType()) { |
| 4807 | Result = getDerived().RebuildParenType(Inner); |
| 4808 | if (Result.isNull()) |
| 4809 | return QualType(); |
| 4810 | } |
| 4811 | |
| 4812 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4813 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4814 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4815 | return Result; |
| 4816 | } |
| 4817 | |
| 4818 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4819 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4820 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4821 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4822 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4823 | NestedNameSpecifierLoc QualifierLoc |
| 4824 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4825 | if (!QualifierLoc) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4826 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4828 | QualType Result |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4829 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4830 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4831 | QualifierLoc, |
| 4832 | T->getIdentifier(), |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4833 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4834 | if (Result.isNull()) |
| 4835 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4836 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4837 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4838 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4839 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4840 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4841 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4842 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4843 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4844 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4845 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4846 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4847 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4848 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4849 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4850 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4851 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4852 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4853 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4854 | QualType TreeTransform<Derived>:: |
| 4855 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4856 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4857 | NestedNameSpecifierLoc QualifierLoc; |
| 4858 | if (TL.getQualifierLoc()) { |
| 4859 | QualifierLoc |
| 4860 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4861 | if (!QualifierLoc) |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4862 | return QualType(); |
| 4863 | } |
| 4864 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4865 | return getDerived() |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4866 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | template<typename Derived> |
| 4870 | QualType TreeTransform<Derived>:: |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4871 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4872 | DependentTemplateSpecializationTypeLoc TL, |
| 4873 | NestedNameSpecifierLoc QualifierLoc) { |
| 4874 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 4875 | |
| 4876 | TemplateArgumentListInfo NewTemplateArgs; |
| 4877 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4878 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4879 | |
| 4880 | typedef TemplateArgumentLocContainerIterator< |
| 4881 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4882 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4883 | ArgIterator(TL, TL.getNumArgs()), |
| 4884 | NewTemplateArgs)) |
| 4885 | return QualType(); |
| 4886 | |
| 4887 | QualType Result |
| 4888 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4889 | QualifierLoc, |
| 4890 | T->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4891 | TL.getTemplateNameLoc(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4892 | NewTemplateArgs); |
| 4893 | if (Result.isNull()) |
| 4894 | return QualType(); |
| 4895 | |
| 4896 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4897 | QualType NamedT = ElabT->getNamedType(); |
| 4898 | |
| 4899 | // Copy information relevant to the template specialization. |
| 4900 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4901 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4902 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4903 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4904 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4905 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4906 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4907 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4908 | |
| 4909 | // Copy information relevant to the elaborated type. |
| 4910 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4911 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4912 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4913 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4914 | DependentTemplateSpecializationTypeLoc SpecTL |
| 4915 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4916 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4917 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4918 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4919 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4920 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4921 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4922 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4923 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4924 | } else { |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4925 | TemplateSpecializationTypeLoc SpecTL |
| 4926 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4927 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4928 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4929 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4930 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4931 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4932 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4933 | } |
| 4934 | return Result; |
| 4935 | } |
| 4936 | |
| 4937 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4938 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4939 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4940 | QualType Pattern |
| 4941 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 4942 | if (Pattern.isNull()) |
| 4943 | return QualType(); |
| 4944 | |
| 4945 | QualType Result = TL.getType(); |
| 4946 | if (getDerived().AlwaysRebuild() || |
| 4947 | Pattern != TL.getPatternLoc().getType()) { |
| 4948 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 4949 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4950 | TL.getEllipsisLoc(), |
| 4951 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4952 | if (Result.isNull()) |
| 4953 | return QualType(); |
| 4954 | } |
| 4955 | |
| 4956 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4957 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4958 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4962 | QualType |
| 4963 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4964 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4965 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4966 | TLB.pushFullCopy(TL); |
| 4967 | return TL.getType(); |
| 4968 | } |
| 4969 | |
| 4970 | template<typename Derived> |
| 4971 | QualType |
| 4972 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4973 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4974 | // ObjCObjectType is never dependent. |
| 4975 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4976 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4977 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4978 | |
| 4979 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4980 | QualType |
| 4981 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4982 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4983 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4984 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4985 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4988 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4989 | // Statement transformation |
| 4990 | //===----------------------------------------------------------------------===// |
| 4991 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4992 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4993 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4994 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4998 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4999 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5000 | return getDerived().TransformCompoundStmt(S, false); |
| 5001 | } |
| 5002 | |
| 5003 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5004 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5005 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5006 | bool IsStmtExpr) { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5007 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5008 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5009 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5010 | bool SubStmtChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5011 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5012 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 5013 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5014 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5015 | if (Result.isInvalid()) { |
| 5016 | // Immediately fail if this was a DeclStmt, since it's very |
| 5017 | // likely that this will cause problems for future statements. |
| 5018 | if (isa<DeclStmt>(*B)) |
| 5019 | return StmtError(); |
| 5020 | |
| 5021 | // Otherwise, just keep processing substatements and fail later. |
| 5022 | SubStmtInvalid = true; |
| 5023 | continue; |
| 5024 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5025 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5026 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 5027 | Statements.push_back(Result.takeAs<Stmt>()); |
| 5028 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5029 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5030 | if (SubStmtInvalid) |
| 5031 | return StmtError(); |
| 5032 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5033 | if (!getDerived().AlwaysRebuild() && |
| 5034 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5035 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5036 | |
| 5037 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 5038 | move_arg(Statements), |
| 5039 | S->getRBracLoc(), |
| 5040 | IsStmtExpr); |
| 5041 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5042 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5043 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5044 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5045 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5046 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5047 | { |
Eli Friedman | 6b3014b | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5048 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5049 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5050 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5051 | // Transform the left-hand case value. |
| 5052 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 5053 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5054 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5056 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5057 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 5058 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5059 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5060 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5061 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5062 | // Build the case statement. |
| 5063 | // Case statements are always rebuilt so that they will attached to their |
| 5064 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5065 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5066 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5067 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5068 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5069 | S->getColonLoc()); |
| 5070 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5071 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5072 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5073 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5074 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5075 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5076 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5077 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5078 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5079 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5083 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5084 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5085 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5086 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5087 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5088 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5089 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5090 | // Default statements are always rebuilt |
| 5091 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5092 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5093 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5094 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5095 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5096 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5098 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5099 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5100 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5101 | |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5102 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5103 | S->getDecl()); |
| 5104 | if (!LD) |
| 5105 | return StmtError(); |
| 5106 | |
| 5107 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5108 | // FIXME: Pass the real colon location in. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5109 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5110 | cast<LabelDecl>(LD), SourceLocation(), |
| 5111 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5112 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5113 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5114 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5115 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5116 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5117 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5118 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5119 | VarDecl *ConditionVar = 0; |
| 5120 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5121 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5122 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5123 | getDerived().TransformDefinition( |
| 5124 | S->getConditionVariable()->getLocation(), |
| 5125 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5126 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5127 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5128 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5129 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5130 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5131 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5132 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5133 | |
| 5134 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5135 | if (S->getCond()) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5136 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 5137 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5138 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5139 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5140 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5141 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5142 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5143 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5144 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5145 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5146 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5147 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5148 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5149 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5150 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5151 | if (Then.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5152 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5154 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5155 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5156 | if (Else.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5157 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5159 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5160 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5161 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5162 | Then.get() == S->getThen() && |
| 5163 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5164 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5165 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5166 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5167 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5168 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5172 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5173 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5174 | // Transform the condition. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5175 | ExprResult Cond; |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5176 | VarDecl *ConditionVar = 0; |
| 5177 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5178 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5179 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5180 | getDerived().TransformDefinition( |
| 5181 | S->getConditionVariable()->getLocation(), |
| 5182 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5183 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5184 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5185 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5186 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5187 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5188 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5189 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5190 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5191 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5192 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5193 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5194 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5195 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5196 | if (Switch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5197 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5198 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5199 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5200 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5201 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5202 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5203 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5204 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5205 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5206 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5207 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5208 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5209 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5210 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5211 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5212 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5213 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5214 | VarDecl *ConditionVar = 0; |
| 5215 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5216 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5217 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5218 | getDerived().TransformDefinition( |
| 5219 | S->getConditionVariable()->getLocation(), |
| 5220 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5221 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5222 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5223 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5224 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5225 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5226 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5227 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5228 | |
| 5229 | if (S->getCond()) { |
| 5230 | // Convert the condition to a boolean value. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5231 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 5232 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5233 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5234 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5235 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5236 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5237 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5238 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5239 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5240 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5241 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5242 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5243 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5244 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5245 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5246 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5247 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5248 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5249 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5250 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5251 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5252 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5253 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5254 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5255 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5256 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5257 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5258 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5259 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5260 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5261 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5262 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5263 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5264 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5265 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5266 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5267 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5268 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5269 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5270 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5271 | if (!getDerived().AlwaysRebuild() && |
| 5272 | Cond.get() == S->getCond() && |
| 5273 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5274 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5275 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5276 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5277 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5278 | S->getRParenLoc()); |
| 5279 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5280 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5281 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5282 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5283 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5284 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5285 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5286 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5287 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5288 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5289 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5290 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5291 | VarDecl *ConditionVar = 0; |
| 5292 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5293 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5294 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5295 | getDerived().TransformDefinition( |
| 5296 | S->getConditionVariable()->getLocation(), |
| 5297 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5298 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5299 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5300 | } else { |
| 5301 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5302 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5303 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5304 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5305 | |
| 5306 | if (S->getCond()) { |
| 5307 | // Convert the condition to a boolean value. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5308 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 5309 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5310 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5311 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5312 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5313 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5314 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5316 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5317 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5318 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5319 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5320 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5321 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5322 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5323 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5324 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5325 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5326 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 5327 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5328 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5329 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5330 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5331 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5332 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5333 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5334 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5335 | if (!getDerived().AlwaysRebuild() && |
| 5336 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5337 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5338 | Inc.get() == S->getInc() && |
| 5339 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5340 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5341 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5342 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5343 | Init.get(), FullCond, ConditionVar, |
| 5344 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5348 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5349 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5350 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5351 | S->getLabel()); |
| 5352 | if (!LD) |
| 5353 | return StmtError(); |
| 5354 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5355 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5356 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5357 | cast<LabelDecl>(LD)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5361 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5362 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5363 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5364 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5365 | return StmtError(); |
Eli Friedman | d29975f | 2012-01-31 22:47:07 +0000 | [diff] [blame] | 5366 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5367 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5368 | if (!getDerived().AlwaysRebuild() && |
| 5369 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5370 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5371 | |
| 5372 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5373 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5377 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5378 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5379 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5382 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5383 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5385 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5386 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5387 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5388 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5389 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5391 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5392 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5393 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5394 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5395 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5396 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5397 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5399 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5400 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5401 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5402 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5403 | bool DeclChanged = false; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5404 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5405 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5406 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5407 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5408 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5409 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5410 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5411 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5412 | if (Transformed != *D) |
| 5413 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5414 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5415 | Decls.push_back(Transformed); |
| 5416 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5417 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5418 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5419 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5420 | |
| 5421 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5422 | S->getStartLoc(), S->getEndLoc()); |
| 5423 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5425 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5426 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5427 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5428 | |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5429 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 5430 | ASTOwningVector<Expr*> Exprs(getSema()); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5431 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5432 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5433 | ExprResult AsmString; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5434 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5435 | |
| 5436 | bool ExprsChanged = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5437 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5438 | // Go through the outputs. |
| 5439 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5440 | Names.push_back(S->getOutputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5441 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5442 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5443 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5444 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5445 | // Transform the output expr. |
| 5446 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5447 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5448 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5449 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5450 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5451 | ExprsChanged |= Result.get() != OutputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5452 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5453 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5454 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5455 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5456 | // Go through the inputs. |
| 5457 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5458 | Names.push_back(S->getInputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5459 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5460 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5461 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5462 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5463 | // Transform the input expr. |
| 5464 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5465 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5466 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5467 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5468 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5469 | ExprsChanged |= Result.get() != InputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5470 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5471 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5472 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5473 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5474 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5475 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5476 | |
| 5477 | // Go through the clobbers. |
| 5478 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5479 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5480 | |
| 5481 | // No need to transform the asm string literal. |
| 5482 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 5483 | |
| 5484 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 5485 | S->isSimple(), |
| 5486 | S->isVolatile(), |
| 5487 | S->getNumOutputs(), |
| 5488 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5489 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5490 | move_arg(Constraints), |
| 5491 | move_arg(Exprs), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5492 | AsmString.get(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5493 | move_arg(Clobbers), |
| 5494 | S->getRParenLoc(), |
| 5495 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5496 | } |
| 5497 | |
| 5498 | |
| 5499 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5500 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5501 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5502 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5503 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5504 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5505 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5506 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5507 | // Transform the @catch statements (if present). |
| 5508 | bool AnyCatchChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5509 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5510 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5511 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5512 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5513 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5514 | if (Catch.get() != S->getCatchStmt(I)) |
| 5515 | AnyCatchChanged = true; |
| 5516 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5517 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5518 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5519 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5520 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5521 | if (S->getFinallyStmt()) { |
| 5522 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5523 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5524 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | // If nothing changed, just retain this statement. |
| 5528 | if (!getDerived().AlwaysRebuild() && |
| 5529 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5530 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5531 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5532 | return SemaRef.Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5533 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5534 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5535 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 5536 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5538 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5539 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5540 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5541 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5542 | // Transform the @catch parameter, if there is one. |
| 5543 | VarDecl *Var = 0; |
| 5544 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5545 | TypeSourceInfo *TSInfo = 0; |
| 5546 | if (FromVar->getTypeSourceInfo()) { |
| 5547 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5548 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5549 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5550 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5551 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5552 | QualType T; |
| 5553 | if (TSInfo) |
| 5554 | T = TSInfo->getType(); |
| 5555 | else { |
| 5556 | T = getDerived().TransformType(FromVar->getType()); |
| 5557 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5558 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5559 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5560 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5561 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5562 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5563 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5564 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5565 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5566 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5567 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5568 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5569 | |
| 5570 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5571 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5572 | Var, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5573 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5574 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5575 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5576 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5577 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5578 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5579 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5580 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5581 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5582 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5583 | // If nothing changed, just retain this statement. |
| 5584 | if (!getDerived().AlwaysRebuild() && |
| 5585 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5586 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5587 | |
| 5588 | // Build a new statement. |
| 5589 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5590 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5591 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5592 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5593 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5594 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5595 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5596 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5597 | if (S->getThrowExpr()) { |
| 5598 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5599 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5600 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5601 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5602 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5603 | if (!getDerived().AlwaysRebuild() && |
| 5604 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5605 | return getSema().Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5606 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5607 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5608 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5609 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5610 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5611 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5612 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5613 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5614 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5615 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5616 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5617 | return StmtError(); |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5618 | Object = |
| 5619 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5620 | Object.get()); |
| 5621 | if (Object.isInvalid()) |
| 5622 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5623 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5624 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5625 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5626 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5627 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5628 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5629 | // If nothing change, just retain the current statement. |
| 5630 | if (!getDerived().AlwaysRebuild() && |
| 5631 | Object.get() == S->getSynchExpr() && |
| 5632 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5633 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5634 | |
| 5635 | // Build a new statement. |
| 5636 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5637 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5641 | StmtResult |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5642 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5643 | ObjCAutoreleasePoolStmt *S) { |
| 5644 | // Transform the body. |
| 5645 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5646 | if (Body.isInvalid()) |
| 5647 | return StmtError(); |
| 5648 | |
| 5649 | // If nothing changed, just retain this statement. |
| 5650 | if (!getDerived().AlwaysRebuild() && |
| 5651 | Body.get() == S->getSubStmt()) |
| 5652 | return SemaRef.Owned(S); |
| 5653 | |
| 5654 | // Build a new statement. |
| 5655 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5656 | S->getAtLoc(), Body.get()); |
| 5657 | } |
| 5658 | |
| 5659 | template<typename Derived> |
| 5660 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5661 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5663 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5664 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5665 | if (Element.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5666 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5667 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5668 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5669 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5670 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5671 | return StmtError(); |
John McCall | 990567c | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 5672 | Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(), |
| 5673 | Collection.take()); |
| 5674 | if (Collection.isInvalid()) |
| 5675 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5676 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5677 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5678 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5679 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5680 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5681 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5682 | // If nothing changed, just retain this statement. |
| 5683 | if (!getDerived().AlwaysRebuild() && |
| 5684 | Element.get() == S->getElement() && |
| 5685 | Collection.get() == S->getCollection() && |
| 5686 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5687 | return SemaRef.Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5688 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5689 | // Build a new statement. |
| 5690 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5691 | /*FIXME:*/S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5692 | Element.get(), |
| 5693 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5694 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5695 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | |
| 5699 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5700 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5701 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5702 | // Transform the exception declaration, if any. |
| 5703 | VarDecl *Var = 0; |
| 5704 | if (S->getExceptionDecl()) { |
| 5705 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5706 | TypeSourceInfo *T = getDerived().TransformType( |
| 5707 | ExceptionDecl->getTypeSourceInfo()); |
| 5708 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5709 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5710 | |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5711 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 5712 | ExceptionDecl->getInnerLocStart(), |
| 5713 | ExceptionDecl->getLocation(), |
| 5714 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5715 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5716 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5718 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5719 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5720 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5721 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5722 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5723 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5724 | if (!getDerived().AlwaysRebuild() && |
| 5725 | !Var && |
| 5726 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5727 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5728 | |
| 5729 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5730 | Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5731 | Handler.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5732 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5733 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5734 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5735 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5736 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5737 | // Transform the try block itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5738 | StmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5739 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5740 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5741 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5742 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5743 | // Transform the handlers. |
| 5744 | bool HandlerChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5745 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5746 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5747 | StmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5748 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5749 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5750 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5751 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5752 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5753 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5754 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5755 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5756 | if (!getDerived().AlwaysRebuild() && |
| 5757 | TryBlock.get() == S->getTryBlock() && |
| 5758 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5759 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5760 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5761 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5762 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5763 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5764 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5765 | template<typename Derived> |
| 5766 | StmtResult |
| 5767 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5768 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 5769 | if (Range.isInvalid()) |
| 5770 | return StmtError(); |
| 5771 | |
| 5772 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 5773 | if (BeginEnd.isInvalid()) |
| 5774 | return StmtError(); |
| 5775 | |
| 5776 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 5777 | if (Cond.isInvalid()) |
| 5778 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 5779 | if (Cond.get()) |
| 5780 | Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); |
| 5781 | if (Cond.isInvalid()) |
| 5782 | return StmtError(); |
| 5783 | if (Cond.get()) |
| 5784 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5785 | |
| 5786 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 5787 | if (Inc.isInvalid()) |
| 5788 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 5789 | if (Inc.get()) |
| 5790 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5791 | |
| 5792 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 5793 | if (LoopVar.isInvalid()) |
| 5794 | return StmtError(); |
| 5795 | |
| 5796 | StmtResult NewStmt = S; |
| 5797 | if (getDerived().AlwaysRebuild() || |
| 5798 | Range.get() != S->getRangeStmt() || |
| 5799 | BeginEnd.get() != S->getBeginEndStmt() || |
| 5800 | Cond.get() != S->getCond() || |
| 5801 | Inc.get() != S->getInc() || |
| 5802 | LoopVar.get() != S->getLoopVarStmt()) |
| 5803 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5804 | S->getColonLoc(), Range.get(), |
| 5805 | BeginEnd.get(), Cond.get(), |
| 5806 | Inc.get(), LoopVar.get(), |
| 5807 | S->getRParenLoc()); |
| 5808 | |
| 5809 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 5810 | if (Body.isInvalid()) |
| 5811 | return StmtError(); |
| 5812 | |
| 5813 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 5814 | // it now so we have a new statement to attach the body to. |
| 5815 | if (Body.get() != S->getBody() && NewStmt.get() == S) |
| 5816 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5817 | S->getColonLoc(), Range.get(), |
| 5818 | BeginEnd.get(), Cond.get(), |
| 5819 | Inc.get(), LoopVar.get(), |
| 5820 | S->getRParenLoc()); |
| 5821 | |
| 5822 | if (NewStmt.get() == S) |
| 5823 | return SemaRef.Owned(S); |
| 5824 | |
| 5825 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 5826 | } |
| 5827 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 5828 | template<typename Derived> |
| 5829 | StmtResult |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5830 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 5831 | MSDependentExistsStmt *S) { |
| 5832 | // Transform the nested-name-specifier, if any. |
| 5833 | NestedNameSpecifierLoc QualifierLoc; |
| 5834 | if (S->getQualifierLoc()) { |
| 5835 | QualifierLoc |
| 5836 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 5837 | if (!QualifierLoc) |
| 5838 | return StmtError(); |
| 5839 | } |
| 5840 | |
| 5841 | // Transform the declaration name. |
| 5842 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 5843 | if (NameInfo.getName()) { |
| 5844 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5845 | if (!NameInfo.getName()) |
| 5846 | return StmtError(); |
| 5847 | } |
| 5848 | |
| 5849 | // Check whether anything changed. |
| 5850 | if (!getDerived().AlwaysRebuild() && |
| 5851 | QualifierLoc == S->getQualifierLoc() && |
| 5852 | NameInfo.getName() == S->getNameInfo().getName()) |
| 5853 | return S; |
| 5854 | |
| 5855 | // Determine whether this name exists, if we can. |
| 5856 | CXXScopeSpec SS; |
| 5857 | SS.Adopt(QualifierLoc); |
| 5858 | bool Dependent = false; |
| 5859 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { |
| 5860 | case Sema::IER_Exists: |
| 5861 | if (S->isIfExists()) |
| 5862 | break; |
| 5863 | |
| 5864 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 5865 | |
| 5866 | case Sema::IER_DoesNotExist: |
| 5867 | if (S->isIfNotExists()) |
| 5868 | break; |
| 5869 | |
| 5870 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 5871 | |
| 5872 | case Sema::IER_Dependent: |
| 5873 | Dependent = true; |
| 5874 | break; |
Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 5875 | |
| 5876 | case Sema::IER_Error: |
| 5877 | return StmtError(); |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5878 | } |
| 5879 | |
| 5880 | // We need to continue with the instantiation, so do so now. |
| 5881 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 5882 | if (SubStmt.isInvalid()) |
| 5883 | return StmtError(); |
| 5884 | |
| 5885 | // If we have resolved the name, just transform to the substatement. |
| 5886 | if (!Dependent) |
| 5887 | return SubStmt; |
| 5888 | |
| 5889 | // The name is still dependent, so build a dependent expression again. |
| 5890 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 5891 | S->isIfExists(), |
| 5892 | QualifierLoc, |
| 5893 | NameInfo, |
| 5894 | SubStmt.get()); |
| 5895 | } |
| 5896 | |
| 5897 | template<typename Derived> |
| 5898 | StmtResult |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 5899 | TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 5900 | StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5901 | if(TryBlock.isInvalid()) return StmtError(); |
| 5902 | |
| 5903 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 5904 | if(!getDerived().AlwaysRebuild() && |
| 5905 | TryBlock.get() == S->getTryBlock() && |
| 5906 | Handler.get() == S->getHandler()) |
| 5907 | return SemaRef.Owned(S); |
| 5908 | |
| 5909 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), |
| 5910 | S->getTryLoc(), |
| 5911 | TryBlock.take(), |
| 5912 | Handler.take()); |
| 5913 | } |
| 5914 | |
| 5915 | template<typename Derived> |
| 5916 | StmtResult |
| 5917 | TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 5918 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 5919 | if(Block.isInvalid()) return StmtError(); |
| 5920 | |
| 5921 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), |
| 5922 | Block.take()); |
| 5923 | } |
| 5924 | |
| 5925 | template<typename Derived> |
| 5926 | StmtResult |
| 5927 | TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 5928 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 5929 | if(FilterExpr.isInvalid()) return StmtError(); |
| 5930 | |
| 5931 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 5932 | if(Block.isInvalid()) return StmtError(); |
| 5933 | |
| 5934 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), |
| 5935 | FilterExpr.take(), |
| 5936 | Block.take()); |
| 5937 | } |
| 5938 | |
| 5939 | template<typename Derived> |
| 5940 | StmtResult |
| 5941 | TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 5942 | if(isa<SEHFinallyStmt>(Handler)) |
| 5943 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 5944 | else |
| 5945 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 5946 | } |
| 5947 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5948 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5949 | // Expression transformation |
| 5950 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5951 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5952 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5953 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5954 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5955 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5956 | |
| 5957 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5958 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5959 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5960 | NestedNameSpecifierLoc QualifierLoc; |
| 5961 | if (E->getQualifierLoc()) { |
| 5962 | QualifierLoc |
| 5963 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5964 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5965 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5966 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5967 | |
| 5968 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5969 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 5970 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5971 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5972 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5973 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5974 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 5975 | if (NameInfo.getName()) { |
| 5976 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5977 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5978 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5979 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5980 | |
| 5981 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5982 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5983 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5984 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5985 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5986 | |
| 5987 | // Mark it referenced in the new context regardless. |
| 5988 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 5989 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5990 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5991 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5992 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5993 | |
| 5994 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5995 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5996 | TemplateArgs = &TransArgs; |
| 5997 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5998 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5999 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6000 | E->getNumTemplateArgs(), |
| 6001 | TransArgs)) |
| 6002 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6003 | } |
| 6004 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6005 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 6006 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6007 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6008 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6009 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6010 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6011 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6012 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6013 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6015 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6016 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6017 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6018 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6019 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6020 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6021 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6022 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6023 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6024 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6025 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6026 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6027 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6028 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6029 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6030 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6031 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6032 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6033 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6034 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6035 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6036 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6037 | } |
| 6038 | |
| 6039 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6040 | ExprResult |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6041 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6042 | ExprResult ControllingExpr = |
| 6043 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6044 | if (ControllingExpr.isInvalid()) |
| 6045 | return ExprError(); |
| 6046 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6047 | SmallVector<Expr *, 4> AssocExprs; |
| 6048 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6049 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6050 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6051 | if (TS) { |
| 6052 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6053 | if (!AssocType) |
| 6054 | return ExprError(); |
| 6055 | AssocTypes.push_back(AssocType); |
| 6056 | } else { |
| 6057 | AssocTypes.push_back(0); |
| 6058 | } |
| 6059 | |
| 6060 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6061 | if (AssocExpr.isInvalid()) |
| 6062 | return ExprError(); |
| 6063 | AssocExprs.push_back(AssocExpr.release()); |
| 6064 | } |
| 6065 | |
| 6066 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6067 | E->getDefaultLoc(), |
| 6068 | E->getRParenLoc(), |
| 6069 | ControllingExpr.release(), |
| 6070 | AssocTypes.data(), |
| 6071 | AssocExprs.data(), |
| 6072 | E->getNumAssocs()); |
| 6073 | } |
| 6074 | |
| 6075 | template<typename Derived> |
| 6076 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6077 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6078 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6079 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6080 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6081 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6082 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6083 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6084 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6085 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6086 | E->getRParen()); |
| 6087 | } |
| 6088 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6089 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6090 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6091 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6092 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6093 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6094 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6095 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6096 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6097 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6098 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6099 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 6100 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6101 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6103 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6104 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6105 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6106 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 6107 | // Transform the type. |
| 6108 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6109 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6110 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6111 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6112 | // Transform all of the components into components similar to what the |
| 6113 | // parser uses. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6114 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 6115 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 6116 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6117 | // template code that we don't care. |
| 6118 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6119 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6120 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6121 | SmallVector<Component, 4> Components; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6122 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 6123 | const Node &ON = E->getComponent(I); |
| 6124 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 6125 | Comp.isBrackets = true; |
Abramo Bagnara | 06dec89 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 6126 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 6127 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6128 | switch (ON.getKind()) { |
| 6129 | case Node::Array: { |
| 6130 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6131 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6132 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6133 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6134 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6135 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 6136 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6137 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6138 | break; |
| 6139 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6140 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6141 | case Node::Field: |
| 6142 | case Node::Identifier: |
| 6143 | Comp.isBrackets = false; |
| 6144 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 6145 | if (!Comp.U.IdentInfo) |
| 6146 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6147 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6148 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6149 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 6150 | case Node::Base: |
| 6151 | // Will be recomputed during the rebuild. |
| 6152 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6153 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6154 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6155 | Components.push_back(Comp); |
| 6156 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6157 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6158 | // If nothing changed, retain the existing expression. |
| 6159 | if (!getDerived().AlwaysRebuild() && |
| 6160 | Type == E->getTypeSourceInfo() && |
| 6161 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6162 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6163 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6164 | // Build a new offsetof expression. |
| 6165 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 6166 | Components.data(), Components.size(), |
| 6167 | E->getRParenLoc()); |
| 6168 | } |
| 6169 | |
| 6170 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6171 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 6172 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6173 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 6174 | "opaque value expression requires transformation"); |
| 6175 | return SemaRef.Owned(E); |
| 6176 | } |
| 6177 | |
| 6178 | template<typename Derived> |
| 6179 | ExprResult |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6180 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | 01e19be | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 6181 | // Rebuild the syntactic form. The original syntactic form has |
| 6182 | // opaque-value expressions in it, so strip those away and rebuild |
| 6183 | // the result. This is a really awful way of doing this, but the |
| 6184 | // better solution (rebuilding the semantic expressions and |
| 6185 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 6186 | // TreeTransform to not strip away implicit conversions. |
| 6187 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 6188 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6189 | if (result.isInvalid()) return ExprError(); |
| 6190 | |
| 6191 | // If that gives us a pseudo-object result back, the pseudo-object |
| 6192 | // expression must have been an lvalue-to-rvalue conversion which we |
| 6193 | // should reapply. |
| 6194 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 6195 | result = SemaRef.checkPseudoObjectRValue(result.take()); |
| 6196 | |
| 6197 | return result; |
| 6198 | } |
| 6199 | |
| 6200 | template<typename Derived> |
| 6201 | ExprResult |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6202 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 6203 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6204 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6205 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6206 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6207 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6208 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6209 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6210 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6211 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6212 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6213 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6214 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 6215 | E->getKind(), |
| 6216 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6217 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6218 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6219 | ExprResult SubExpr; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6220 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6221 | // C++0x [expr.sizeof]p1: |
| 6222 | // The operand is either an expression, which is an unevaluated operand |
| 6223 | // [...] |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6224 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6225 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6226 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 6227 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6228 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6229 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6230 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6231 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6232 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6233 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6234 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6235 | E->getOperatorLoc(), |
| 6236 | E->getKind(), |
| 6237 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6238 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6239 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6240 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6241 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6242 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6243 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6244 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6245 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6246 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6247 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6248 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6249 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6250 | |
| 6251 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6252 | if (!getDerived().AlwaysRebuild() && |
| 6253 | LHS.get() == E->getLHS() && |
| 6254 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6255 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6256 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6257 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6258 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6259 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6260 | E->getRBracketLoc()); |
| 6261 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6262 | |
| 6263 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6264 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6265 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6266 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6267 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6268 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6269 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6270 | |
| 6271 | // Transform arguments. |
| 6272 | bool ArgChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6273 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6274 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6275 | &ArgChanged)) |
| 6276 | return ExprError(); |
| 6277 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6278 | if (!getDerived().AlwaysRebuild() && |
| 6279 | Callee.get() == E->getCallee() && |
| 6280 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6281 | return SemaRef.MaybeBindToTemporary(E);; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6282 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6283 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6284 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6285 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6286 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6287 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6288 | E->getRParenLoc()); |
| 6289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6290 | |
| 6291 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6292 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6293 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6294 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6295 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6296 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6297 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6298 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6299 | if (E->hasQualifier()) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6300 | QualifierLoc |
| 6301 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6302 | |
| 6303 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6304 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6305 | } |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6306 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6307 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6308 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6309 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6310 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6311 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6312 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6313 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6314 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6315 | if (FoundDecl == E->getMemberDecl()) { |
| 6316 | FoundDecl = Member; |
| 6317 | } else { |
| 6318 | FoundDecl = cast_or_null<NamedDecl>( |
| 6319 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6320 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6321 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6322 | } |
| 6323 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6324 | if (!getDerived().AlwaysRebuild() && |
| 6325 | Base.get() == E->getBase() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6326 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6327 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6328 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6329 | !E->hasExplicitTemplateArgs()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6330 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6331 | // Mark it referenced in the new context regardless. |
| 6332 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6333 | SemaRef.MarkMemberReferenced(E); |
| 6334 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6335 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6336 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6337 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6338 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6339 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6340 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6341 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6342 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6343 | E->getNumTemplateArgs(), |
| 6344 | TransArgs)) |
| 6345 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6346 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6347 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6348 | // FIXME: Bogus source location for the operator |
| 6349 | SourceLocation FakeOperatorLoc |
| 6350 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6351 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6352 | // FIXME: to do this check properly, we will need to preserve the |
| 6353 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6354 | // base (and therefore couldn't do the check) and a |
| 6355 | // nested-name-qualifier (and therefore could do the lookup). |
| 6356 | NamedDecl *FirstQualifierInScope = 0; |
| 6357 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6358 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6359 | E->isArrow(), |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6360 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6361 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6362 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6363 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6364 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6365 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6366 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6367 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6369 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6370 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6371 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6372 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6373 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6374 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6375 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6376 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6377 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6378 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6379 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6380 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6381 | if (!getDerived().AlwaysRebuild() && |
| 6382 | LHS.get() == E->getLHS() && |
| 6383 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6384 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6385 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6386 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6387 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6388 | } |
| 6389 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6390 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6391 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6392 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6393 | CompoundAssignOperator *E) { |
| 6394 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6395 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6396 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6397 | template<typename Derived> |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6398 | ExprResult TreeTransform<Derived>:: |
| 6399 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6400 | // Just rebuild the common and RHS expressions and see whether we |
| 6401 | // get any changes. |
| 6402 | |
| 6403 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6404 | if (commonExpr.isInvalid()) |
| 6405 | return ExprError(); |
| 6406 | |
| 6407 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6408 | if (rhs.isInvalid()) |
| 6409 | return ExprError(); |
| 6410 | |
| 6411 | if (!getDerived().AlwaysRebuild() && |
| 6412 | commonExpr.get() == e->getCommon() && |
| 6413 | rhs.get() == e->getFalseExpr()) |
| 6414 | return SemaRef.Owned(e); |
| 6415 | |
| 6416 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6417 | e->getQuestionLoc(), |
| 6418 | 0, |
| 6419 | e->getColonLoc(), |
| 6420 | rhs.get()); |
| 6421 | } |
| 6422 | |
| 6423 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6424 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6425 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6426 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6427 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6428 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6429 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6430 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6431 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6432 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6433 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6434 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6435 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6436 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6437 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6438 | if (!getDerived().AlwaysRebuild() && |
| 6439 | Cond.get() == E->getCond() && |
| 6440 | LHS.get() == E->getLHS() && |
| 6441 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6442 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6443 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6444 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6445 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6446 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6447 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6448 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6449 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6450 | |
| 6451 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6452 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6453 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6454 | // Implicit casts are eliminated during transformation, since they |
| 6455 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6456 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6457 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6458 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6459 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6460 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6461 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6462 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6463 | if (!Type) |
| 6464 | return ExprError(); |
| 6465 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6466 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6467 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6468 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6469 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6470 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6471 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6472 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6473 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6474 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6475 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6476 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6477 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6478 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6479 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6481 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6482 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6483 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6484 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6485 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6486 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6487 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6488 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6489 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6490 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6491 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6492 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6493 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6494 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6495 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6496 | Init.get() == E->getInitializer()) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6497 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6498 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6499 | // Note: the expression type doesn't necessarily match the |
| 6500 | // type-as-written, but that's okay, because it should always be |
| 6501 | // derivable from the initializer. |
| 6502 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6503 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6504 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6505 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6506 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6507 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6508 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6509 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6510 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6511 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6512 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6513 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6515 | if (!getDerived().AlwaysRebuild() && |
| 6516 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6517 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6518 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6519 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6520 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6521 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6522 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6523 | E->getAccessorLoc(), |
| 6524 | E->getAccessor()); |
| 6525 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6526 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6527 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6528 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6529 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6530 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6531 | |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6532 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6533 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 6534 | Inits, &InitChanged)) |
| 6535 | return ExprError(); |
| 6536 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6537 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6538 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6539 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6540 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6541 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6543 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6544 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6545 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6546 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6547 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6548 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6549 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6550 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6551 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6552 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6553 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6554 | // transform the designators. |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6555 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6556 | bool ExprChanged = false; |
| 6557 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6558 | DEnd = E->designators_end(); |
| 6559 | D != DEnd; ++D) { |
| 6560 | if (D->isFieldDesignator()) { |
| 6561 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6562 | D->getDotLoc(), |
| 6563 | D->getFieldLoc())); |
| 6564 | continue; |
| 6565 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6566 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6567 | if (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6568 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6569 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6570 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6571 | |
| 6572 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6573 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6574 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6575 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6576 | ArrayExprs.push_back(Index.release()); |
| 6577 | continue; |
| 6578 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6579 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6580 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6581 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6582 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6583 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6584 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6585 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6586 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6587 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6588 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6589 | |
| 6590 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6591 | End.get(), |
| 6592 | D->getLBracketLoc(), |
| 6593 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6594 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6595 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6596 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6597 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6598 | ArrayExprs.push_back(Start.release()); |
| 6599 | ArrayExprs.push_back(End.release()); |
| 6600 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6601 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6602 | if (!getDerived().AlwaysRebuild() && |
| 6603 | Init.get() == E->getInit() && |
| 6604 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6605 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6606 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6607 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 6608 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6609 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6610 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6611 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6612 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6613 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6614 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6615 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6616 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6617 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6618 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6619 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6620 | QualType T = getDerived().TransformType(E->getType()); |
| 6621 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6622 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6624 | if (!getDerived().AlwaysRebuild() && |
| 6625 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6626 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6628 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6629 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6630 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6631 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6632 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6633 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6634 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6635 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6636 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6637 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6638 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6639 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6640 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6641 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6642 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6643 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6644 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6645 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6646 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6647 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6648 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6649 | } |
| 6650 | |
| 6651 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6652 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6653 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6654 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6655 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6656 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6657 | &ArgumentChanged)) |
| 6658 | return ExprError(); |
| 6659 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6660 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 6661 | move_arg(Inits), |
| 6662 | E->getRParenLoc()); |
| 6663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6664 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6665 | /// \brief Transform an address-of-label expression. |
| 6666 | /// |
| 6667 | /// By default, the transformation of an address-of-label expression always |
| 6668 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6669 | /// the corresponding label statement by semantic analysis. |
| 6670 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6671 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6672 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6673 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6674 | E->getLabel()); |
| 6675 | if (!LD) |
| 6676 | return ExprError(); |
| 6677 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6678 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6679 | cast<LabelDecl>(LD)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6681 | |
| 6682 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6683 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6684 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6685 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6686 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 6687 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6688 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6689 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6690 | if (!getDerived().AlwaysRebuild() && |
| 6691 | SubStmt.get() == E->getSubStmt()) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6692 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6693 | |
| 6694 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6695 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6696 | E->getRParenLoc()); |
| 6697 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6698 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6699 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6700 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6701 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6702 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6703 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6704 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6705 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6706 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6707 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6708 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6709 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6710 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6711 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6712 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6714 | if (!getDerived().AlwaysRebuild() && |
| 6715 | Cond.get() == E->getCond() && |
| 6716 | LHS.get() == E->getLHS() && |
| 6717 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6718 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6719 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6720 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6721 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6722 | E->getRParenLoc()); |
| 6723 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6724 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6725 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6726 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6727 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6728 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6729 | } |
| 6730 | |
| 6731 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6732 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6733 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6734 | switch (E->getOperator()) { |
| 6735 | case OO_New: |
| 6736 | case OO_Delete: |
| 6737 | case OO_Array_New: |
| 6738 | case OO_Array_Delete: |
| 6739 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6740 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6741 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6742 | case OO_Call: { |
| 6743 | // This is a call to an object's operator(). |
| 6744 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6745 | |
| 6746 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6747 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6748 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6749 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6750 | |
| 6751 | // FIXME: Poor location information |
| 6752 | SourceLocation FakeLParenLoc |
| 6753 | = SemaRef.PP.getLocForEndOfToken( |
| 6754 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6755 | |
| 6756 | // Transform the call arguments. |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6757 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6758 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 6759 | Args)) |
| 6760 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6761 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6762 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6763 | move_arg(Args), |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6764 | E->getLocEnd()); |
| 6765 | } |
| 6766 | |
| 6767 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6768 | case OO_##Name: |
| 6769 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6770 | #include "clang/Basic/OperatorKinds.def" |
| 6771 | case OO_Subscript: |
| 6772 | // Handled below. |
| 6773 | break; |
| 6774 | |
| 6775 | case OO_Conditional: |
| 6776 | llvm_unreachable("conditional operator is not actually overloadable"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6777 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6778 | |
| 6779 | case OO_None: |
| 6780 | case NUM_OVERLOADED_OPERATORS: |
| 6781 | llvm_unreachable("not an overloaded operator?"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6782 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6783 | } |
| 6784 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6785 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6786 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6787 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6788 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6789 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6790 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6791 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6792 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6793 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6794 | if (E->getNumArgs() == 2) { |
| 6795 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6796 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6797 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6798 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6799 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6800 | if (!getDerived().AlwaysRebuild() && |
| 6801 | Callee.get() == E->getCallee() && |
| 6802 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6803 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6804 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6805 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6806 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 6807 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6808 | Callee.get(), |
| 6809 | First.get(), |
| 6810 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6811 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6812 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6813 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6814 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6815 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6816 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6817 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6818 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6819 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6820 | ExprResult |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6821 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 6822 | // Transform the callee. |
| 6823 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 6824 | if (Callee.isInvalid()) |
| 6825 | return ExprError(); |
| 6826 | |
| 6827 | // Transform exec config. |
| 6828 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 6829 | if (EC.isInvalid()) |
| 6830 | return ExprError(); |
| 6831 | |
| 6832 | // Transform arguments. |
| 6833 | bool ArgChanged = false; |
| 6834 | ASTOwningVector<Expr*> Args(SemaRef); |
| 6835 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6836 | &ArgChanged)) |
| 6837 | return ExprError(); |
| 6838 | |
| 6839 | if (!getDerived().AlwaysRebuild() && |
| 6840 | Callee.get() == E->getCallee() && |
| 6841 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6842 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6843 | |
| 6844 | // FIXME: Wrong source location information for the '('. |
| 6845 | SourceLocation FakeLParenLoc |
| 6846 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 6847 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 6848 | move_arg(Args), |
| 6849 | E->getRParenLoc(), EC.get()); |
| 6850 | } |
| 6851 | |
| 6852 | template<typename Derived> |
| 6853 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6854 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6855 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6856 | if (!Type) |
| 6857 | return ExprError(); |
| 6858 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6859 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6860 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6861 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6862 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6863 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6864 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6865 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6866 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6867 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6868 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6869 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6870 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6871 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 6872 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 6873 | SourceLocation FakeRParenLoc |
| 6874 | = SemaRef.PP.getLocForEndOfToken( |
| 6875 | E->getSubExpr()->getSourceRange().getEnd()); |
| 6876 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6877 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6878 | FakeLAngleLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6879 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6880 | FakeRAngleLoc, |
| 6881 | FakeRAngleLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6882 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6883 | FakeRParenLoc); |
| 6884 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6885 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6886 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6887 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6888 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 6889 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6890 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6891 | |
| 6892 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6893 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6894 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 6895 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6896 | } |
| 6897 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6898 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6899 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6900 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6901 | CXXReinterpretCastExpr *E) { |
| 6902 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6903 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6904 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6905 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6906 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6907 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 6908 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6909 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6910 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6911 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6912 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6913 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6914 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6915 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6916 | if (!Type) |
| 6917 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6918 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6919 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6920 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6921 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6922 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6923 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6924 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6925 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6926 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6927 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6928 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6929 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6930 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6931 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6932 | E->getRParenLoc()); |
| 6933 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6934 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6935 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6936 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6937 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6938 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6939 | TypeSourceInfo *TInfo |
| 6940 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6941 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6942 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6943 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6944 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6945 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6946 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6947 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6948 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6949 | E->getLocStart(), |
| 6950 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6951 | E->getLocEnd()); |
| 6952 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6953 | |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 6954 | // We don't know whether the subexpression is potentially evaluated until |
| 6955 | // after we perform semantic analysis. We speculatively assume it is |
| 6956 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6957 | // potentially evaluated. |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 6958 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6959 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6960 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6961 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6962 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6963 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6964 | if (!getDerived().AlwaysRebuild() && |
| 6965 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6966 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6967 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6968 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6969 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6970 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6971 | E->getLocEnd()); |
| 6972 | } |
| 6973 | |
| 6974 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6975 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6976 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 6977 | if (E->isTypeOperand()) { |
| 6978 | TypeSourceInfo *TInfo |
| 6979 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6980 | if (!TInfo) |
| 6981 | return ExprError(); |
| 6982 | |
| 6983 | if (!getDerived().AlwaysRebuild() && |
| 6984 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6985 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6986 | |
Douglas Gregor | 3c52a21 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 6987 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6988 | E->getLocStart(), |
| 6989 | TInfo, |
| 6990 | E->getLocEnd()); |
| 6991 | } |
| 6992 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6993 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 6994 | |
| 6995 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 6996 | if (SubExpr.isInvalid()) |
| 6997 | return ExprError(); |
| 6998 | |
| 6999 | if (!getDerived().AlwaysRebuild() && |
| 7000 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7001 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7002 | |
| 7003 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7004 | E->getLocStart(), |
| 7005 | SubExpr.get(), |
| 7006 | E->getLocEnd()); |
| 7007 | } |
| 7008 | |
| 7009 | template<typename Derived> |
| 7010 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7011 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7012 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7013 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7015 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7016 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7017 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7018 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7019 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7020 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7021 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7022 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7023 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7024 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7025 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 7026 | QualType T; |
| 7027 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) |
| 7028 | T = MD->getThisType(getSema().Context); |
| 7029 | else |
| 7030 | T = getSema().Context.getPointerType( |
| 7031 | getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7032 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7033 | if (!getDerived().AlwaysRebuild() && T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7034 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7035 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7036 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7037 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7038 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7039 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7040 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7041 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7042 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7043 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7044 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7045 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7046 | if (!getDerived().AlwaysRebuild() && |
| 7047 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7048 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7049 | |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7050 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7051 | E->isThrownVariableInScope()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7052 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7053 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7054 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7055 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7056 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7057 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7058 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7059 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7060 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7061 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7062 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7063 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7064 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7065 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7066 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7067 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7069 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7070 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7071 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7072 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 7073 | CXXScalarValueInitExpr *E) { |
| 7074 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7075 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7076 | return ExprError(); |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7077 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7078 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7079 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7080 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7081 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7082 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 7083 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 7084 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7085 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7086 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7087 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7088 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7089 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7090 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7091 | TypeSourceInfo *AllocTypeInfo |
| 7092 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 7093 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7094 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7095 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7096 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7097 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7098 | if (ArraySize.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7099 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7100 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7101 | // Transform the placement arguments (if any). |
| 7102 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7103 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7104 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 7105 | E->getNumPlacementArgs(), true, |
| 7106 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7107 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7108 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7109 | // Transform the initializer (if any). |
| 7110 | Expr *OldInit = E->getInitializer(); |
| 7111 | ExprResult NewInit; |
| 7112 | if (OldInit) |
| 7113 | NewInit = getDerived().TransformExpr(OldInit); |
| 7114 | if (NewInit.isInvalid()) |
| 7115 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7116 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7117 | // Transform new operator and delete operator. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7118 | FunctionDecl *OperatorNew = 0; |
| 7119 | if (E->getOperatorNew()) { |
| 7120 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7121 | getDerived().TransformDecl(E->getLocStart(), |
| 7122 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7123 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7124 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7125 | } |
| 7126 | |
| 7127 | FunctionDecl *OperatorDelete = 0; |
| 7128 | if (E->getOperatorDelete()) { |
| 7129 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7130 | getDerived().TransformDecl(E->getLocStart(), |
| 7131 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7132 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7133 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7134 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7135 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7136 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7137 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7138 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7139 | NewInit.get() == OldInit && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7140 | OperatorNew == E->getOperatorNew() && |
| 7141 | OperatorDelete == E->getOperatorDelete() && |
| 7142 | !ArgumentChanged) { |
| 7143 | // Mark any declarations we need as referenced. |
| 7144 | // FIXME: instantiation-specific. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7145 | if (OperatorNew) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7146 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7147 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7148 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7149 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7150 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7151 | QualType ElementType |
| 7152 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 7153 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 7154 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 7155 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7156 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7157 | } |
| 7158 | } |
| 7159 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7160 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7161 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7162 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7163 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7164 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7165 | if (!ArraySize.get()) { |
| 7166 | // If no array size was specified, but the new expression was |
| 7167 | // instantiated with an array type (e.g., "new T" where T is |
| 7168 | // instantiated with "int[4]"), extract the outer bound from the |
| 7169 | // array type as our array size. We do this with constant and |
| 7170 | // dependently-sized array types. |
| 7171 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 7172 | if (!ArrayT) { |
| 7173 | // Do nothing |
| 7174 | } else if (const ConstantArrayType *ConsArrayT |
| 7175 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7176 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7177 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 7178 | ConsArrayT->getSize(), |
| 7179 | SemaRef.Context.getSizeType(), |
| 7180 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7181 | AllocType = ConsArrayT->getElementType(); |
| 7182 | } else if (const DependentSizedArrayType *DepArrayT |
| 7183 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 7184 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7185 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7186 | AllocType = DepArrayT->getElementType(); |
| 7187 | } |
| 7188 | } |
| 7189 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7190 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7191 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 7192 | E->isGlobalNew(), |
| 7193 | /*FIXME:*/E->getLocStart(), |
| 7194 | move_arg(PlacementArgs), |
| 7195 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 7196 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7197 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7198 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7199 | ArraySize.get(), |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7200 | E->getDirectInitRange(), |
| 7201 | NewInit.take()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7202 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7203 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7204 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7205 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7206 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7207 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7208 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7209 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7210 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7211 | // Transform the delete operator, if known. |
| 7212 | FunctionDecl *OperatorDelete = 0; |
| 7213 | if (E->getOperatorDelete()) { |
| 7214 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7215 | getDerived().TransformDecl(E->getLocStart(), |
| 7216 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7217 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7218 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7219 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7220 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7221 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7222 | Operand.get() == E->getArgument() && |
| 7223 | OperatorDelete == E->getOperatorDelete()) { |
| 7224 | // Mark any declarations we need as referenced. |
| 7225 | // FIXME: instantiation-specific. |
| 7226 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7227 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7228 | |
| 7229 | if (!E->getArgument()->isTypeDependent()) { |
| 7230 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7231 | E->getDestroyedType()); |
| 7232 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7233 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7234 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
| 7235 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7236 | } |
| 7237 | } |
| 7238 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7239 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7240 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7241 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7242 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7243 | E->isGlobalDelete(), |
| 7244 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7245 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7246 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7247 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7248 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7249 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7250 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7251 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7252 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7253 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7254 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7255 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7256 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7257 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7258 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7259 | E->getOperatorLoc(), |
| 7260 | E->isArrow()? tok::arrow : tok::period, |
| 7261 | ObjectTypePtr, |
| 7262 | MayBePseudoDestructor); |
| 7263 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7264 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7265 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7266 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7267 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7268 | if (QualifierLoc) { |
| 7269 | QualifierLoc |
| 7270 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7271 | if (!QualifierLoc) |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7272 | return ExprError(); |
| 7273 | } |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7274 | CXXScopeSpec SS; |
| 7275 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7276 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7277 | PseudoDestructorTypeStorage Destroyed; |
| 7278 | if (E->getDestroyedTypeInfo()) { |
| 7279 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7280 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7281 | ObjectType, 0, SS); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7282 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7283 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7284 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 7285 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7286 | // We aren't likely to be able to resolve the identifier down to a type |
| 7287 | // now anyway, so just retain the identifier. |
| 7288 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7289 | E->getDestroyedTypeLoc()); |
| 7290 | } else { |
| 7291 | // Look for a destructor known with the given name. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7292 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7293 | *E->getDestroyedTypeIdentifier(), |
| 7294 | E->getDestroyedTypeLoc(), |
| 7295 | /*Scope=*/0, |
| 7296 | SS, ObjectTypePtr, |
| 7297 | false); |
| 7298 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7299 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7300 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7301 | Destroyed |
| 7302 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7303 | E->getDestroyedTypeLoc()); |
| 7304 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7305 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7306 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7307 | if (E->getScopeTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7308 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7309 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7310 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7311 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7312 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7313 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7314 | E->getOperatorLoc(), |
| 7315 | E->isArrow(), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7316 | SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7317 | ScopeTypeInfo, |
| 7318 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7319 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7320 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7322 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7323 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7324 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7325 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7326 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7327 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7328 | Sema::LookupOrdinaryName); |
| 7329 | |
| 7330 | // Transform all the decls. |
| 7331 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7332 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7333 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7334 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7335 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7336 | if (!InstD) { |
| 7337 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7338 | // This can happen because of dependent hiding. |
| 7339 | if (isa<UsingShadowDecl>(*I)) |
| 7340 | continue; |
| 7341 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7342 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7343 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7344 | |
| 7345 | // Expand using declarations. |
| 7346 | if (isa<UsingDecl>(InstD)) { |
| 7347 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7348 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7349 | E = UD->shadow_end(); I != E; ++I) |
| 7350 | R.addDecl(*I); |
| 7351 | continue; |
| 7352 | } |
| 7353 | |
| 7354 | R.addDecl(InstD); |
| 7355 | } |
| 7356 | |
| 7357 | // Resolve a kind, but don't do any further analysis. If it's |
| 7358 | // ambiguous, the callee needs to deal with it. |
| 7359 | R.resolveKind(); |
| 7360 | |
| 7361 | // Rebuild the nested-name qualifier, if present. |
| 7362 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7363 | if (Old->getQualifierLoc()) { |
| 7364 | NestedNameSpecifierLoc QualifierLoc |
| 7365 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7366 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7367 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7368 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7369 | SS.Adopt(QualifierLoc); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7370 | } |
| 7371 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7372 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7373 | CXXRecordDecl *NamingClass |
| 7374 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7375 | Old->getNameLoc(), |
| 7376 | Old->getNamingClass())); |
| 7377 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7378 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7379 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7380 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7381 | } |
| 7382 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7383 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7384 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7385 | // If we have neither explicit template arguments, nor the template keyword, |
| 7386 | // it's a normal declaration name. |
| 7387 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7388 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7389 | |
| 7390 | // If we have template arguments, rebuild them, then rebuild the |
| 7391 | // templateid expression. |
| 7392 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7393 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7394 | Old->getNumTemplateArgs(), |
| 7395 | TransArgs)) |
| 7396 | return ExprError(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7397 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7398 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7399 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7400 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7401 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7402 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7403 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7404 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7405 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7406 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7407 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7408 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7409 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7410 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7411 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7412 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7413 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7414 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7415 | T, |
| 7416 | E->getLocEnd()); |
| 7417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7418 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7419 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7420 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7421 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7422 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7423 | if (!LhsT) |
| 7424 | return ExprError(); |
| 7425 | |
| 7426 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7427 | if (!RhsT) |
| 7428 | return ExprError(); |
| 7429 | |
| 7430 | if (!getDerived().AlwaysRebuild() && |
| 7431 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7432 | return SemaRef.Owned(E); |
| 7433 | |
| 7434 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7435 | E->getLocStart(), |
| 7436 | LhsT, RhsT, |
| 7437 | E->getLocEnd()); |
| 7438 | } |
| 7439 | |
| 7440 | template<typename Derived> |
| 7441 | ExprResult |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 7442 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 7443 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7444 | if (!T) |
| 7445 | return ExprError(); |
| 7446 | |
| 7447 | if (!getDerived().AlwaysRebuild() && |
| 7448 | T == E->getQueriedTypeSourceInfo()) |
| 7449 | return SemaRef.Owned(E); |
| 7450 | |
| 7451 | ExprResult SubExpr; |
| 7452 | { |
| 7453 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7454 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 7455 | if (SubExpr.isInvalid()) |
| 7456 | return ExprError(); |
| 7457 | |
| 7458 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 7459 | return SemaRef.Owned(E); |
| 7460 | } |
| 7461 | |
| 7462 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 7463 | E->getLocStart(), |
| 7464 | T, |
| 7465 | SubExpr.get(), |
| 7466 | E->getLocEnd()); |
| 7467 | } |
| 7468 | |
| 7469 | template<typename Derived> |
| 7470 | ExprResult |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 7471 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 7472 | ExprResult SubExpr; |
| 7473 | { |
| 7474 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7475 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 7476 | if (SubExpr.isInvalid()) |
| 7477 | return ExprError(); |
| 7478 | |
| 7479 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 7480 | return SemaRef.Owned(E); |
| 7481 | } |
| 7482 | |
| 7483 | return getDerived().RebuildExpressionTrait( |
| 7484 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 7485 | } |
| 7486 | |
| 7487 | template<typename Derived> |
| 7488 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7489 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7490 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7491 | NestedNameSpecifierLoc QualifierLoc |
| 7492 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7493 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7494 | return ExprError(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7495 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7496 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7497 | // TODO: If this is a conversion-function-id, verify that the |
| 7498 | // destination type name (if present) resolves the same way after |
| 7499 | // instantiation as it did in the local scope. |
| 7500 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7501 | DeclarationNameInfo NameInfo |
| 7502 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 7503 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7504 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7505 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7506 | if (!E->hasExplicitTemplateArgs()) { |
| 7507 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7508 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7509 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 7510 | // if name has not changed, DNLoc has not changed either. |
| 7511 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7512 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7513 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7514 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7515 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7516 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7517 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 7518 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7519 | |
| 7520 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7521 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7522 | E->getNumTemplateArgs(), |
| 7523 | TransArgs)) |
| 7524 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7525 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7526 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7527 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7528 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7529 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7530 | } |
| 7531 | |
| 7532 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7533 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7534 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 7535 | // CXXConstructExprs are always implicit, so when we have a |
| 7536 | // 1-argument construction we just transform that argument. |
| 7537 | if (E->getNumArgs() == 1 || |
| 7538 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 7539 | return getDerived().TransformExpr(E->getArg(0)); |
| 7540 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7541 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 7542 | |
| 7543 | QualType T = getDerived().TransformType(E->getType()); |
| 7544 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7545 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7546 | |
| 7547 | CXXConstructorDecl *Constructor |
| 7548 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7549 | getDerived().TransformDecl(E->getLocStart(), |
| 7550 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7551 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7552 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7553 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7554 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7555 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7556 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7557 | &ArgumentChanged)) |
| 7558 | return ExprError(); |
| 7559 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7560 | if (!getDerived().AlwaysRebuild() && |
| 7561 | T == E->getType() && |
| 7562 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7563 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7564 | // Mark the constructor as referenced. |
| 7565 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7566 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7567 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7568 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7569 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 7570 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 7571 | Constructor, E->isElidable(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7572 | move_arg(Args), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 7573 | E->hadMultipleCandidates(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7574 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 7575 | E->getConstructionKind(), |
| 7576 | E->getParenRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7577 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7578 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7579 | /// \brief Transform a C++ temporary-binding expression. |
| 7580 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7581 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 7582 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7583 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7584 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7585 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7586 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7587 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7588 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7589 | /// \brief Transform a C++ expression that contains cleanups that should |
| 7590 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7591 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7592 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7593 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7594 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7595 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7596 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7597 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7598 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7599 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7600 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7601 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7602 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7603 | CXXTemporaryObjectExpr *E) { |
| 7604 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7605 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7606 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7607 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7608 | CXXConstructorDecl *Constructor |
| 7609 | = cast_or_null<CXXConstructorDecl>( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7610 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7611 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7612 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7613 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7614 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7615 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7616 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7617 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7618 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7619 | &ArgumentChanged)) |
| 7620 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7622 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7623 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7624 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7625 | !ArgumentChanged) { |
| 7626 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7627 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7628 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7629 | } |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7630 | |
| 7631 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 7632 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7633 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7634 | E->getLocEnd()); |
| 7635 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7636 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7637 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7638 | ExprResult |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 7639 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7640 | // Create the local class that will describe the lambda. |
| 7641 | CXXRecordDecl *Class |
| 7642 | = getSema().createLambdaClosureType(E->getIntroducerRange()); |
| 7643 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 7644 | |
| 7645 | // Transform the type of the lambda parameters and start the definition of |
| 7646 | // the lambda itself. |
| 7647 | TypeSourceInfo *MethodTy |
| 7648 | = TransformType(E->getCallOperator()->getTypeSourceInfo()); |
| 7649 | if (!MethodTy) |
| 7650 | return ExprError(); |
| 7651 | |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 7652 | // Transform lambda parameters. |
| 7653 | bool Invalid = false; |
| 7654 | llvm::SmallVector<QualType, 4> ParamTypes; |
| 7655 | llvm::SmallVector<ParmVarDecl *, 4> Params; |
| 7656 | if (getDerived().TransformFunctionTypeParams(E->getLocStart(), |
| 7657 | E->getCallOperator()->param_begin(), |
| 7658 | E->getCallOperator()->param_size(), |
| 7659 | 0, ParamTypes, &Params)) |
| 7660 | Invalid = true; |
| 7661 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7662 | // Build the call operator. |
| 7663 | CXXMethodDecl *CallOperator |
| 7664 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
| 7665 | MethodTy, |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 7666 | E->getCallOperator()->getLocEnd(), |
| 7667 | Params); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7668 | getDerived().transformAttrs(E->getCallOperator(), CallOperator); |
| 7669 | |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 7670 | // FIXME: Instantiation-specific. |
| 7671 | CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(), |
| 7672 | TSK_ImplicitInstantiation); |
| 7673 | |
| 7674 | // Introduce the context of the call operator. |
| 7675 | Sema::ContextRAII SavedContext(getSema(), CallOperator); |
| 7676 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7677 | // Enter the scope of the lambda. |
| 7678 | sema::LambdaScopeInfo *LSI |
| 7679 | = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(), |
| 7680 | E->getCaptureDefault(), |
| 7681 | E->hasExplicitParameters(), |
| 7682 | E->hasExplicitResultType(), |
| 7683 | E->isMutable()); |
| 7684 | |
| 7685 | // Transform captures. |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7686 | bool FinishedExplicitCaptures = false; |
| 7687 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 7688 | CEnd = E->capture_end(); |
| 7689 | C != CEnd; ++C) { |
| 7690 | // When we hit the first implicit capture, tell Sema that we've finished |
| 7691 | // the list of explicit captures. |
| 7692 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 7693 | getSema().finishLambdaExplicitCaptures(LSI); |
| 7694 | FinishedExplicitCaptures = true; |
| 7695 | } |
| 7696 | |
| 7697 | // Capturing 'this' is trivial. |
| 7698 | if (C->capturesThis()) { |
| 7699 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 7700 | continue; |
| 7701 | } |
| 7702 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7703 | // Determine the capture kind for Sema. |
| 7704 | Sema::TryCaptureKind Kind |
| 7705 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 7706 | : C->getCaptureKind() == LCK_ByCopy |
| 7707 | ? Sema::TryCapture_ExplicitByVal |
| 7708 | : Sema::TryCapture_ExplicitByRef; |
| 7709 | SourceLocation EllipsisLoc; |
| 7710 | if (C->isPackExpansion()) { |
| 7711 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 7712 | bool ShouldExpand = false; |
| 7713 | bool RetainExpansion = false; |
| 7714 | llvm::Optional<unsigned> NumExpansions; |
| 7715 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 7716 | C->getLocation(), |
| 7717 | Unexpanded, |
| 7718 | ShouldExpand, RetainExpansion, |
| 7719 | NumExpansions)) |
| 7720 | return ExprError(); |
| 7721 | |
| 7722 | if (ShouldExpand) { |
| 7723 | // The transform has determined that we should perform an expansion; |
| 7724 | // transform and capture each of the arguments. |
| 7725 | // expansion of the pattern. Do so. |
| 7726 | VarDecl *Pack = C->getCapturedVar(); |
| 7727 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7728 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 7729 | VarDecl *CapturedVar |
| 7730 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| 7731 | Pack)); |
| 7732 | if (!CapturedVar) { |
| 7733 | Invalid = true; |
| 7734 | continue; |
| 7735 | } |
| 7736 | |
| 7737 | // Capture the transformed variable. |
| 7738 | getSema().TryCaptureVar(CapturedVar, C->getLocation(), Kind); |
| 7739 | } |
| 7740 | continue; |
| 7741 | } |
| 7742 | |
| 7743 | EllipsisLoc = C->getEllipsisLoc(); |
| 7744 | } |
| 7745 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7746 | // Transform the captured variable. |
| 7747 | VarDecl *CapturedVar |
| 7748 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| 7749 | C->getCapturedVar())); |
| 7750 | if (!CapturedVar) { |
| 7751 | Invalid = true; |
| 7752 | continue; |
| 7753 | } |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7754 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7755 | // Capture the transformed variable. |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7756 | getSema().TryCaptureVar(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7757 | } |
| 7758 | if (!FinishedExplicitCaptures) |
| 7759 | getSema().finishLambdaExplicitCaptures(LSI); |
| 7760 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7761 | |
| 7762 | // Enter a new evaluation context to insulate the lambda from any |
| 7763 | // cleanups from the enclosing full-expression. |
| 7764 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
| 7765 | |
| 7766 | if (Invalid) { |
| 7767 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
| 7768 | /*IsInstantiation=*/true); |
| 7769 | return ExprError(); |
| 7770 | } |
| 7771 | |
| 7772 | // Instantiate the body of the lambda expression. |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 7773 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 7774 | if (Body.isInvalid()) { |
| 7775 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
| 7776 | /*IsInstantiation=*/true); |
| 7777 | return ExprError(); |
| 7778 | } |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7779 | |
| 7780 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), |
| 7781 | /*CurScope=*/0, |
| 7782 | /*IsInstantiation=*/true); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 7783 | } |
| 7784 | |
| 7785 | template<typename Derived> |
| 7786 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7787 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7788 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7789 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7790 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7791 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7792 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7793 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7794 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7795 | Args.reserve(E->arg_size()); |
| 7796 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 7797 | &ArgumentChanged)) |
| 7798 | return ExprError(); |
| 7799 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7800 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7801 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7802 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7803 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7804 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7805 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7806 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7807 | E->getLParenLoc(), |
| 7808 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7809 | E->getRParenLoc()); |
| 7810 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7811 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7812 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7813 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7814 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7815 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7816 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7817 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7818 | Expr *OldBase; |
| 7819 | QualType BaseType; |
| 7820 | QualType ObjectType; |
| 7821 | if (!E->isImplicitAccess()) { |
| 7822 | OldBase = E->getBase(); |
| 7823 | Base = getDerived().TransformExpr(OldBase); |
| 7824 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7825 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7826 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7827 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7828 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7829 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7830 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7831 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7832 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7833 | ObjectTy, |
| 7834 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7835 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7836 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7837 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7838 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7839 | BaseType = ((Expr*) Base.get())->getType(); |
| 7840 | } else { |
| 7841 | OldBase = 0; |
| 7842 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 7843 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 7844 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7845 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7846 | // Transform the first part of the nested-name-specifier that qualifies |
| 7847 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7848 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7849 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7850 | E->getFirstQualifierFoundInScope(), |
| 7851 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7852 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7853 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7854 | if (E->getQualifier()) { |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7855 | QualifierLoc |
| 7856 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 7857 | ObjectType, |
| 7858 | FirstQualifierInScope); |
| 7859 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7860 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7861 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7862 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7863 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 7864 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7865 | // TODO: If this is a conversion-function-id, verify that the |
| 7866 | // destination type name (if present) resolves the same way after |
| 7867 | // instantiation as it did in the local scope. |
| 7868 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7869 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7870 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7871 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7872 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7873 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7874 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7875 | // This is a reference to a member without an explicitly-specified |
| 7876 | // template argument list. Optimize for this common case. |
| 7877 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7878 | Base.get() == OldBase && |
| 7879 | BaseType == E->getBaseType() && |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7880 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7881 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7882 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7883 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7884 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7885 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7886 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7887 | E->isArrow(), |
| 7888 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7889 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7890 | TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7891 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7892 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7893 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7894 | } |
| 7895 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7896 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7897 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7898 | E->getNumTemplateArgs(), |
| 7899 | TransArgs)) |
| 7900 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7901 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7902 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7903 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7904 | E->isArrow(), |
| 7905 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7906 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7907 | TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7908 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7909 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7910 | &TransArgs); |
| 7911 | } |
| 7912 | |
| 7913 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7914 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7915 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7916 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7917 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7918 | QualType BaseType; |
| 7919 | if (!Old->isImplicitAccess()) { |
| 7920 | Base = getDerived().TransformExpr(Old->getBase()); |
| 7921 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7922 | return ExprError(); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 7923 | Base = getSema().PerformMemberExprBaseConversion(Base.take(), |
| 7924 | Old->isArrow()); |
| 7925 | if (Base.isInvalid()) |
| 7926 | return ExprError(); |
| 7927 | BaseType = Base.get()->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7928 | } else { |
| 7929 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 7930 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7931 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7932 | NestedNameSpecifierLoc QualifierLoc; |
| 7933 | if (Old->getQualifierLoc()) { |
| 7934 | QualifierLoc |
| 7935 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7936 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7937 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7938 | } |
| 7939 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7940 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7941 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7942 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7943 | Sema::LookupOrdinaryName); |
| 7944 | |
| 7945 | // Transform all the decls. |
| 7946 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 7947 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7948 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7949 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 7950 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7951 | if (!InstD) { |
| 7952 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7953 | // This can happen because of dependent hiding. |
| 7954 | if (isa<UsingShadowDecl>(*I)) |
| 7955 | continue; |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 7956 | else { |
| 7957 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7958 | return ExprError(); |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 7959 | } |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7960 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7961 | |
| 7962 | // Expand using declarations. |
| 7963 | if (isa<UsingDecl>(InstD)) { |
| 7964 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7965 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7966 | E = UD->shadow_end(); I != E; ++I) |
| 7967 | R.addDecl(*I); |
| 7968 | continue; |
| 7969 | } |
| 7970 | |
| 7971 | R.addDecl(InstD); |
| 7972 | } |
| 7973 | |
| 7974 | R.resolveKind(); |
| 7975 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7976 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 7977 | if (Old->getNamingClass()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7978 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7979 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7980 | Old->getMemberLoc(), |
| 7981 | Old->getNamingClass())); |
| 7982 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7983 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7984 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7985 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7986 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7987 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7988 | TemplateArgumentListInfo TransArgs; |
| 7989 | if (Old->hasExplicitTemplateArgs()) { |
| 7990 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 7991 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7992 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7993 | Old->getNumTemplateArgs(), |
| 7994 | TransArgs)) |
| 7995 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7996 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7997 | |
| 7998 | // FIXME: to do this check properly, we will need to preserve the |
| 7999 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8000 | // base (and therefore couldn't do the check) and a |
| 8001 | // nested-name-qualifier (and therefore could do the lookup). |
| 8002 | NamedDecl *FirstQualifierInScope = 0; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8003 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8004 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8005 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8006 | Old->getOperatorLoc(), |
| 8007 | Old->isArrow(), |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8008 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8009 | TemplateKWLoc, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8010 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8011 | R, |
| 8012 | (Old->hasExplicitTemplateArgs() |
| 8013 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8014 | } |
| 8015 | |
| 8016 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8017 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8018 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Sean Hunt | eea06c6 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 8019 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8020 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 8021 | if (SubExpr.isInvalid()) |
| 8022 | return ExprError(); |
| 8023 | |
| 8024 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8025 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8026 | |
| 8027 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 8028 | } |
| 8029 | |
| 8030 | template<typename Derived> |
| 8031 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8032 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8033 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 8034 | if (Pattern.isInvalid()) |
| 8035 | return ExprError(); |
| 8036 | |
| 8037 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 8038 | return SemaRef.Owned(E); |
| 8039 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 8040 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 8041 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8042 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8043 | |
| 8044 | template<typename Derived> |
| 8045 | ExprResult |
| 8046 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 8047 | // If E is not value-dependent, then nothing will change when we transform it. |
| 8048 | // Note: This is an instantiation-centric view. |
| 8049 | if (!E->isValueDependent()) |
| 8050 | return SemaRef.Owned(E); |
| 8051 | |
| 8052 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 8053 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 8054 | // so |
| 8055 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 8056 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8057 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 8058 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8059 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 8060 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8061 | ShouldExpand, RetainExpansion, |
| 8062 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8063 | return ExprError(); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8064 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8065 | if (RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8066 | return SemaRef.Owned(E); |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8067 | |
| 8068 | NamedDecl *Pack = E->getPack(); |
| 8069 | if (!ShouldExpand) { |
| 8070 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
| 8071 | Pack)); |
| 8072 | if (!Pack) |
| 8073 | return ExprError(); |
| 8074 | } |
| 8075 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8076 | |
| 8077 | // We now know the length of the parameter pack, so build a new expression |
| 8078 | // that stores that length. |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8079 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8080 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8081 | NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8082 | } |
| 8083 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8084 | template<typename Derived> |
| 8085 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 8086 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 8087 | SubstNonTypeTemplateParmPackExpr *E) { |
| 8088 | // Default behavior is to do nothing with this transformation. |
| 8089 | return SemaRef.Owned(E); |
| 8090 | } |
| 8091 | |
| 8092 | template<typename Derived> |
| 8093 | ExprResult |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 8094 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 8095 | SubstNonTypeTemplateParmExpr *E) { |
| 8096 | // Default behavior is to do nothing with this transformation. |
| 8097 | return SemaRef.Owned(E); |
| 8098 | } |
| 8099 | |
| 8100 | template<typename Derived> |
| 8101 | ExprResult |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8102 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 8103 | MaterializeTemporaryExpr *E) { |
| 8104 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 8105 | } |
| 8106 | |
| 8107 | template<typename Derived> |
| 8108 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8109 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8110 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8111 | } |
| 8112 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8113 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8114 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8115 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8116 | TypeSourceInfo *EncodedTypeInfo |
| 8117 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 8118 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8119 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8121 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8122 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8123 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8124 | |
| 8125 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8126 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8127 | E->getRParenLoc()); |
| 8128 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8129 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8130 | template<typename Derived> |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8131 | ExprResult TreeTransform<Derived>:: |
| 8132 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| 8133 | ExprResult result = getDerived().TransformExpr(E->getSubExpr()); |
| 8134 | if (result.isInvalid()) return ExprError(); |
| 8135 | Expr *subExpr = result.take(); |
| 8136 | |
| 8137 | if (!getDerived().AlwaysRebuild() && |
| 8138 | subExpr == E->getSubExpr()) |
| 8139 | return SemaRef.Owned(E); |
| 8140 | |
| 8141 | return SemaRef.Owned(new(SemaRef.Context) |
| 8142 | ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); |
| 8143 | } |
| 8144 | |
| 8145 | template<typename Derived> |
| 8146 | ExprResult TreeTransform<Derived>:: |
| 8147 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| 8148 | TypeSourceInfo *TSInfo |
| 8149 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8150 | if (!TSInfo) |
| 8151 | return ExprError(); |
| 8152 | |
| 8153 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
| 8154 | if (Result.isInvalid()) |
| 8155 | return ExprError(); |
| 8156 | |
| 8157 | if (!getDerived().AlwaysRebuild() && |
| 8158 | TSInfo == E->getTypeInfoAsWritten() && |
| 8159 | Result.get() == E->getSubExpr()) |
| 8160 | return SemaRef.Owned(E); |
| 8161 | |
| 8162 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
| 8163 | E->getBridgeKeywordLoc(), TSInfo, |
| 8164 | Result.get()); |
| 8165 | } |
| 8166 | |
| 8167 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8168 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8169 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8170 | // Transform arguments. |
| 8171 | bool ArgChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 8172 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8173 | Args.reserve(E->getNumArgs()); |
| 8174 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 8175 | &ArgChanged)) |
| 8176 | return ExprError(); |
| 8177 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8178 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 8179 | // Class message: transform the receiver type. |
| 8180 | TypeSourceInfo *ReceiverTypeInfo |
| 8181 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 8182 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8183 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8184 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8185 | // If nothing changed, just retain the existing message send. |
| 8186 | if (!getDerived().AlwaysRebuild() && |
| 8187 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8188 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8189 | |
| 8190 | // Build a new class message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8191 | SmallVector<SourceLocation, 16> SelLocs; |
| 8192 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8193 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 8194 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8195 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8196 | E->getMethodDecl(), |
| 8197 | E->getLeftLoc(), |
| 8198 | move_arg(Args), |
| 8199 | E->getRightLoc()); |
| 8200 | } |
| 8201 | |
| 8202 | // Instance message: transform the receiver |
| 8203 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 8204 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8205 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8206 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 8207 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8208 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8209 | |
| 8210 | // If nothing changed, just retain the existing message send. |
| 8211 | if (!getDerived().AlwaysRebuild() && |
| 8212 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8213 | return SemaRef.MaybeBindToTemporary(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8214 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8215 | // Build a new instance message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8216 | SmallVector<SourceLocation, 16> SelLocs; |
| 8217 | E->getSelectorLocs(SelLocs); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8218 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8219 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8220 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8221 | E->getMethodDecl(), |
| 8222 | E->getLeftLoc(), |
| 8223 | move_arg(Args), |
| 8224 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8225 | } |
| 8226 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8227 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8228 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8229 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8230 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8231 | } |
| 8232 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8233 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8234 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8235 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8236 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8237 | } |
| 8238 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8239 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8240 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8241 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8242 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8243 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8244 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8245 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8246 | |
| 8247 | // We don't need to transform the ivar; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8248 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8249 | // If nothing changed, just retain the existing expression. |
| 8250 | if (!getDerived().AlwaysRebuild() && |
| 8251 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8252 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8253 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8254 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8255 | E->getLocation(), |
| 8256 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8257 | } |
| 8258 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8259 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8260 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8261 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8262 | // 'super' and types never change. Property never changes. Just |
| 8263 | // retain the existing expression. |
| 8264 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8265 | return SemaRef.Owned(E); |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 8266 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8267 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8268 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8269 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8270 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8271 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8272 | // We don't need to transform the property; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8273 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8274 | // If nothing changed, just retain the existing expression. |
| 8275 | if (!getDerived().AlwaysRebuild() && |
| 8276 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8277 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8278 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8279 | if (E->isExplicitProperty()) |
| 8280 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 8281 | E->getExplicitProperty(), |
| 8282 | E->getLocation()); |
| 8283 | |
| 8284 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 8285 | SemaRef.Context.PseudoObjectTy, |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8286 | E->getImplicitPropertyGetter(), |
| 8287 | E->getImplicitPropertySetter(), |
| 8288 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8289 | } |
| 8290 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8291 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8292 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8293 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8294 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8295 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8296 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8297 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8298 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8299 | // If nothing changed, just retain the existing expression. |
| 8300 | if (!getDerived().AlwaysRebuild() && |
| 8301 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8302 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8303 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8304 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8305 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8306 | } |
| 8307 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8308 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8309 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8310 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8311 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 8312 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8313 | SubExprs.reserve(E->getNumSubExprs()); |
| 8314 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 8315 | SubExprs, &ArgumentChanged)) |
| 8316 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8317 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8318 | if (!getDerived().AlwaysRebuild() && |
| 8319 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8320 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8321 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8322 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 8323 | move_arg(SubExprs), |
| 8324 | E->getRParenLoc()); |
| 8325 | } |
| 8326 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8327 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8328 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8329 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8330 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8331 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8332 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 8333 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 8334 | |
| 8335 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 0586520 | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 8336 | blockScope->TheDecl->setBlockMissingReturnType( |
| 8337 | oldBlock->blockMissingReturnType()); |
Fariborz Jahanian | ff36559 | 2011-05-05 17:18:12 +0000 | [diff] [blame] | 8338 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 8339 | SmallVector<ParmVarDecl*, 4> params; |
| 8340 | SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8341 | |
| 8342 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8343 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 8344 | oldBlock->param_begin(), |
| 8345 | oldBlock->param_size(), |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8346 | 0, paramTypes, ¶ms)) { |
| 8347 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8348 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8349 | } |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8350 | |
| 8351 | const FunctionType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8352 | QualType exprResultType = |
| 8353 | getDerived().TransformType(exprFunctionType->getResultType()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8354 | |
| 8355 | // Don't allow returning a objc interface by value. |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8356 | if (exprResultType->isObjCObjectType()) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8357 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8358 | diag::err_object_cannot_be_passed_returned_by_value) |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8359 | << 0 << exprResultType; |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8360 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8361 | return ExprError(); |
| 8362 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8363 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8364 | QualType functionType = getDerived().RebuildFunctionProtoType( |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8365 | exprResultType, |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8366 | paramTypes.data(), |
| 8367 | paramTypes.size(), |
| 8368 | oldBlock->isVariadic(), |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 8369 | false, 0, RQ_None, |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8370 | exprFunctionType->getExtInfo()); |
| 8371 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8372 | |
| 8373 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8374 | if (!params.empty()) |
David Blaikie | 4278c65 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 8375 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8376 | |
| 8377 | if (!oldBlock->blockMissingReturnType()) { |
| 8378 | blockScope->HasImplicitReturnType = false; |
| 8379 | blockScope->ReturnType = exprResultType; |
| 8380 | } |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8381 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8382 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8383 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8384 | if (body.isInvalid()) { |
| 8385 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8386 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8387 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8388 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8389 | #ifndef NDEBUG |
| 8390 | // In builds with assertions, make sure that we captured everything we |
| 8391 | // captured before. |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8392 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 8393 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 8394 | e = oldBlock->capture_end(); i != e; ++i) { |
| 8395 | VarDecl *oldCapture = i->getVariable(); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8396 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8397 | // Ignore parameter packs. |
| 8398 | if (isa<ParmVarDecl>(oldCapture) && |
| 8399 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 8400 | continue; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8401 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8402 | VarDecl *newCapture = |
| 8403 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 8404 | oldCapture)); |
| 8405 | assert(blockScope->CaptureMap.count(newCapture)); |
| 8406 | } |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8407 | } |
| 8408 | #endif |
| 8409 | |
| 8410 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 8411 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8412 | } |
| 8413 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8414 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8415 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8416 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8417 | ValueDecl *ND |
| 8418 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 8419 | E->getDecl())); |
| 8420 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8421 | return ExprError(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8422 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8423 | if (!getDerived().AlwaysRebuild() && |
| 8424 | ND == E->getDecl()) { |
| 8425 | // Mark it referenced in the new context regardless. |
| 8426 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8427 | SemaRef.MarkBlockDeclRefReferenced(E); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8428 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8429 | return SemaRef.Owned(E); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8430 | } |
| 8431 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8432 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8433 | return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8434 | ND, NameInfo, 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8435 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8436 | |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8437 | template<typename Derived> |
| 8438 | ExprResult |
| 8439 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 8440 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8441 | } |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 8442 | |
| 8443 | template<typename Derived> |
| 8444 | ExprResult |
| 8445 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 8446 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 8447 | bool ArgumentChanged = false; |
| 8448 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
| 8449 | SubExprs.reserve(E->getNumSubExprs()); |
| 8450 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 8451 | SubExprs, &ArgumentChanged)) |
| 8452 | return ExprError(); |
| 8453 | |
| 8454 | if (!getDerived().AlwaysRebuild() && |
| 8455 | !ArgumentChanged) |
| 8456 | return SemaRef.Owned(E); |
| 8457 | |
| 8458 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs), |
| 8459 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 8460 | } |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8461 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8462 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8463 | // Type reconstruction |
| 8464 | //===----------------------------------------------------------------------===// |
| 8465 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8466 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8467 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 8468 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8469 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8470 | getDerived().getBaseEntity()); |
| 8471 | } |
| 8472 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8473 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8474 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 8475 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8476 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8477 | getDerived().getBaseEntity()); |
| 8478 | } |
| 8479 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8480 | template<typename Derived> |
| 8481 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8482 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 8483 | bool WrittenAsLValue, |
| 8484 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8485 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8486 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8487 | } |
| 8488 | |
| 8489 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8490 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8491 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 8492 | QualType ClassType, |
| 8493 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8494 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8495 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8496 | } |
| 8497 | |
| 8498 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8499 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8500 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 8501 | ArrayType::ArraySizeModifier SizeMod, |
| 8502 | const llvm::APInt *Size, |
| 8503 | Expr *SizeExpr, |
| 8504 | unsigned IndexTypeQuals, |
| 8505 | SourceRange BracketsRange) { |
| 8506 | if (SizeExpr || !Size) |
| 8507 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 8508 | IndexTypeQuals, BracketsRange, |
| 8509 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8510 | |
| 8511 | QualType Types[] = { |
| 8512 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 8513 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 8514 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8515 | }; |
| 8516 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 8517 | QualType SizeType; |
| 8518 | for (unsigned I = 0; I != NumTypes; ++I) |
| 8519 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 8520 | SizeType = Types[I]; |
| 8521 | break; |
| 8522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8523 | |
Eli Friedman | 01f276d | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 8524 | // Note that we can return a VariableArrayType here in the case where |
| 8525 | // the element type was a dependent VariableArrayType. |
| 8526 | IntegerLiteral *ArraySize |
| 8527 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 8528 | /*FIXME*/BracketsRange.getBegin()); |
| 8529 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8530 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8531 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8533 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8534 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8535 | QualType |
| 8536 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8537 | ArrayType::ArraySizeModifier SizeMod, |
| 8538 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8539 | unsigned IndexTypeQuals, |
| 8540 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8541 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8542 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8543 | } |
| 8544 | |
| 8545 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8546 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8547 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8548 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8549 | unsigned IndexTypeQuals, |
| 8550 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8551 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8552 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8554 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8555 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8556 | QualType |
| 8557 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8558 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8559 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8560 | unsigned IndexTypeQuals, |
| 8561 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8562 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8563 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8564 | IndexTypeQuals, BracketsRange); |
| 8565 | } |
| 8566 | |
| 8567 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8568 | QualType |
| 8569 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8570 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8571 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8572 | unsigned IndexTypeQuals, |
| 8573 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8574 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8575 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8576 | IndexTypeQuals, BracketsRange); |
| 8577 | } |
| 8578 | |
| 8579 | template<typename Derived> |
| 8580 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 8581 | unsigned NumElements, |
| 8582 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8583 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 8584 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8585 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8586 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8587 | template<typename Derived> |
| 8588 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 8589 | unsigned NumElements, |
| 8590 | SourceLocation AttributeLoc) { |
| 8591 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 8592 | NumElements, true); |
| 8593 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 8594 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 8595 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8596 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8597 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8598 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8599 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8600 | QualType |
| 8601 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8602 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8603 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8604 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8605 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8606 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8607 | template<typename Derived> |
| 8608 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8609 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8610 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8611 | bool Variadic, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 8612 | bool HasTrailingReturn, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 8613 | unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 8614 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 8615 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8616 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 8617 | HasTrailingReturn, Quals, RefQualifier, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8618 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 8619 | getDerived().getBaseEntity(), |
| 8620 | Info); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8621 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8622 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8623 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 8624 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 8625 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 8626 | } |
| 8627 | |
| 8628 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8629 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 8630 | assert(D && "no decl found"); |
| 8631 | if (D->isInvalidDecl()) return QualType(); |
| 8632 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8633 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8634 | TypeDecl *Ty; |
| 8635 | if (isa<UsingDecl>(D)) { |
| 8636 | UsingDecl *Using = cast<UsingDecl>(D); |
| 8637 | assert(Using->isTypeName() && |
| 8638 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 8639 | |
| 8640 | // A valid resolved using typename decl points to exactly one type decl. |
| 8641 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 8642 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8643 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8644 | } else { |
| 8645 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 8646 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 8647 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 8648 | } |
| 8649 | |
| 8650 | return SemaRef.Context.getTypeDeclType(Ty); |
| 8651 | } |
| 8652 | |
| 8653 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 8654 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 8655 | SourceLocation Loc) { |
| 8656 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8657 | } |
| 8658 | |
| 8659 | template<typename Derived> |
| 8660 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 8661 | return SemaRef.Context.getTypeOfType(Underlying); |
| 8662 | } |
| 8663 | |
| 8664 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 8665 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 8666 | SourceLocation Loc) { |
| 8667 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8668 | } |
| 8669 | |
| 8670 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 8671 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 8672 | UnaryTransformType::UTTKind UKind, |
| 8673 | SourceLocation Loc) { |
| 8674 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 8675 | } |
| 8676 | |
| 8677 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8678 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 8679 | TemplateName Template, |
| 8680 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 8681 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8682 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8683 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8684 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 8685 | template<typename Derived> |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 8686 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 8687 | SourceLocation KWLoc) { |
| 8688 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 8689 | } |
| 8690 | |
| 8691 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8692 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8693 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8694 | bool TemplateKW, |
| 8695 | TemplateDecl *Template) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8696 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8697 | Template); |
| 8698 | } |
| 8699 | |
| 8700 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8701 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8702 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 8703 | const IdentifierInfo &Name, |
| 8704 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8705 | QualType ObjectType, |
| 8706 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8707 | UnqualifiedId TemplateName; |
| 8708 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8709 | Sema::TemplateTy Template; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8710 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8711 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8712 | SS, TemplateKWLoc, TemplateName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8713 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8714 | /*EnteringContext=*/false, |
| 8715 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8716 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8718 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8719 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8720 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8721 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8722 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8723 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8724 | QualType ObjectType) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8725 | UnqualifiedId Name; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8726 | // FIXME: Bogus location information. |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8727 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8728 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8729 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8730 | Sema::TemplateTy Template; |
| 8731 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8732 | SS, TemplateKWLoc, Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8733 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8734 | /*EnteringContext=*/false, |
| 8735 | Template); |
| 8736 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8737 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8738 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8739 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8740 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8741 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 8742 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8743 | Expr *OrigCallee, |
| 8744 | Expr *First, |
| 8745 | Expr *Second) { |
| 8746 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 8747 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8749 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8750 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8751 | if (!First->getType()->isOverloadableType() && |
| 8752 | !Second->getType()->isOverloadableType()) |
| 8753 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 8754 | Callee->getLocStart(), |
| 8755 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 8756 | } else if (Op == OO_Arrow) { |
| 8757 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8758 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 8759 | } else if (Second == 0 || isPostIncDec) { |
| 8760 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8761 | // The argument is not of overloadable type, so try to create a |
| 8762 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8763 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8764 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8765 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8766 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8767 | } |
| 8768 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8769 | if (!First->getType()->isOverloadableType() && |
| 8770 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8771 | // Neither of the arguments is an overloadable type, so try to |
| 8772 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8773 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8774 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8775 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8776 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8777 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8779 | return move(Result); |
| 8780 | } |
| 8781 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8782 | |
| 8783 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8784 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 8785 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8786 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8787 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8788 | assert(ULE->requiresADL()); |
| 8789 | |
| 8790 | // FIXME: Do we have to check |
| 8791 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 8792 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8793 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8794 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8795 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8796 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8797 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8798 | Expr *Args[2] = { First, Second }; |
| 8799 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8800 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8801 | // Create the overloaded operator invocation for unary operators. |
| 8802 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8803 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8804 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8805 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8807 | |
Douglas Gregor | 5b8968c | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 8808 | if (Op == OO_Subscript) { |
| 8809 | SourceLocation LBrace; |
| 8810 | SourceLocation RBrace; |
| 8811 | |
| 8812 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 8813 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 8814 | LBrace = SourceLocation::getFromRawEncoding( |
| 8815 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 8816 | RBrace = SourceLocation::getFromRawEncoding( |
| 8817 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 8818 | } else { |
| 8819 | LBrace = Callee->getLocStart(); |
| 8820 | RBrace = OpLoc; |
| 8821 | } |
| 8822 | |
| 8823 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 8824 | First, Second); |
| 8825 | } |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8826 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8827 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8828 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8829 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8830 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 8831 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8832 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8833 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8834 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8835 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8836 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8837 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8838 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8839 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8840 | SourceLocation OperatorLoc, |
| 8841 | bool isArrow, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8842 | CXXScopeSpec &SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8843 | TypeSourceInfo *ScopeType, |
| 8844 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8845 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8846 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8847 | QualType BaseType = Base->getType(); |
| 8848 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8849 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8850 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 8851 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 8852 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8853 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8854 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8855 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8856 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8857 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8858 | /*FIXME?*/true); |
| 8859 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8860 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8861 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8862 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 8863 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 8864 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 8865 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 8866 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8867 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8868 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8869 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8870 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8871 | OperatorLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8872 | SS, TemplateKWLoc, |
| 8873 | /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8874 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8875 | /*TemplateArgs*/ 0); |
| 8876 | } |
| 8877 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8878 | } // end namespace clang |
| 8879 | |
| 8880 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |