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 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 227 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 228 | /// expand the corresponding pack expansions into separate arguments. When |
| 229 | /// set, \c NumExpansions must also be set. |
| 230 | /// |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 231 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 232 | /// pack expansion after all of the expanded arguments. This is used |
| 233 | /// when extending explicitly-specified template argument packs per |
| 234 | /// C++0x [temp.arg.explicit]p9. |
| 235 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 236 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 237 | /// the expanded form of the corresponding pack expansion. This is both an |
| 238 | /// input and an output parameter, which can be set by the caller if the |
| 239 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 240 | /// and will be set by the callee when the number of expansions is known. |
| 241 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 242 | /// set this value in other cases. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 243 | /// |
| 244 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 245 | /// are to be instantiated with arguments of different lengths), false |
| 246 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 247 | /// must be set. |
| 248 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 249 | SourceRange PatternRange, |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 250 | llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 251 | bool &ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 252 | bool &RetainExpansion, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 253 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 254 | ShouldExpand = false; |
| 255 | return false; |
| 256 | } |
| 257 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 258 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 259 | /// when performing an instantiation that must preserve the parameter pack |
| 260 | /// use. |
| 261 | /// |
| 262 | /// This routine is meant to be overridden by the template instantiator. |
| 263 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 264 | return TemplateArgument(); |
| 265 | } |
| 266 | |
| 267 | /// \brief "Remember" the partially-substituted pack template argument |
| 268 | /// after performing an instantiation that must preserve the parameter pack |
| 269 | /// use. |
| 270 | /// |
| 271 | /// This routine is meant to be overridden by the template instantiator. |
| 272 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 273 | |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 274 | /// \brief Note to the derived class when a function parameter pack is |
| 275 | /// being expanded. |
| 276 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 277 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 278 | /// \brief Transforms the given type into another type. |
| 279 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 280 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 281 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 282 | /// function. This is expensive, but we don't mind, because |
| 283 | /// this method is deprecated anyway; all users should be |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 284 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 285 | /// |
| 286 | /// \returns the transformed type. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 287 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 288 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 289 | /// \brief Transforms the given type-with-location into a new |
| 290 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 292 | /// By default, this routine transforms a type by delegating to the |
| 293 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 294 | /// may override this function (to take over all type |
| 295 | /// transformations) or some set of the TransformXXXType functions |
| 296 | /// to alter the transformation. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 297 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 298 | |
| 299 | /// \brief Transform the given type-with-location into a new |
| 300 | /// type, collecting location information in the given builder |
| 301 | /// as necessary. |
| 302 | /// |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 303 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 305 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 306 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 308 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 309 | /// statement or the TransformExpr() function to transform an expression. |
| 310 | /// Subclasses may override this function to transform statements using some |
| 311 | /// other mechanism. |
| 312 | /// |
| 313 | /// \returns the transformed statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 314 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 316 | /// \brief Transform the given expression. |
| 317 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 318 | /// By default, this routine transforms an expression by delegating to the |
| 319 | /// appropriate TransformXXXExpr function to build a new expression. |
| 320 | /// Subclasses may override this function to transform expressions using some |
| 321 | /// other mechanism. |
| 322 | /// |
| 323 | /// \returns the transformed expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 324 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 326 | /// \brief Transform the given list of expressions. |
| 327 | /// |
| 328 | /// This routine transforms a list of expressions by invoking |
| 329 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 330 | /// support for variadic templates by expanding any pack expansions (if the |
| 331 | /// derived class permits such expansion) along the way. When pack expansions |
| 332 | /// are present, the number of outputs may not equal the number of inputs. |
| 333 | /// |
| 334 | /// \param Inputs The set of expressions to be transformed. |
| 335 | /// |
| 336 | /// \param NumInputs The number of expressions in \c Inputs. |
| 337 | /// |
| 338 | /// \param IsCall If \c true, then this transform is being performed on |
| 339 | /// function-call arguments, and any arguments that should be dropped, will |
| 340 | /// be. |
| 341 | /// |
| 342 | /// \param Outputs The transformed input expressions will be added to this |
| 343 | /// vector. |
| 344 | /// |
| 345 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 346 | /// due to transformation. |
| 347 | /// |
| 348 | /// \returns true if an error occurred, false otherwise. |
| 349 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 350 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 351 | bool *ArgChanged = 0); |
| 352 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 353 | /// \brief Transform the given declaration, which is referenced from a type |
| 354 | /// or expression. |
| 355 | /// |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 356 | /// By default, acts as the identity function on declarations, unless the |
| 357 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 358 | /// may override this function to provide alternate behavior. |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 359 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
| 360 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 361 | = TransformedLocalDecls.find(D); |
| 362 | if (Known != TransformedLocalDecls.end()) |
| 363 | return Known->second; |
| 364 | |
| 365 | return D; |
| 366 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 367 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 368 | /// \brief Transform the attributes associated with the given declaration and |
| 369 | /// place them on the new declaration. |
| 370 | /// |
| 371 | /// By default, this operation does nothing. Subclasses may override this |
| 372 | /// behavior to transform attributes. |
| 373 | void transformAttrs(Decl *Old, Decl *New) { } |
| 374 | |
| 375 | /// \brief Note that a local declaration has been transformed by this |
| 376 | /// transformer. |
| 377 | /// |
| 378 | /// Local declarations are typically transformed via a call to |
| 379 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 380 | /// the transformer itself has to transform the declarations. This routine |
| 381 | /// can be overridden by a subclass that keeps track of such mappings. |
| 382 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 383 | TransformedLocalDecls[Old] = New; |
| 384 | } |
| 385 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 386 | /// \brief Transform the definition of the given declaration. |
| 387 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 389 | /// Subclasses may override this function to provide alternate behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 390 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 391 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 394 | /// \brief Transform the given declaration, which was the first part of a |
| 395 | /// nested-name-specifier in a member access expression. |
| 396 | /// |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 397 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 398 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 399 | /// the \c T in \c x->T::member |
| 400 | /// |
| 401 | /// By default, invokes TransformDecl() to transform the declaration. |
| 402 | /// Subclasses may override this function to provide alternate behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 403 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 404 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 405 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 407 | /// \brief Transform the given nested-name-specifier with source-location |
| 408 | /// information. |
| 409 | /// |
| 410 | /// By default, transforms all of the types and declarations within the |
| 411 | /// nested-name-specifier. Subclasses may override this function to provide |
| 412 | /// alternate behavior. |
| 413 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 414 | NestedNameSpecifierLoc NNS, |
| 415 | QualType ObjectType = QualType(), |
| 416 | NamedDecl *FirstQualifierInScope = 0); |
| 417 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 418 | /// \brief Transform the given declaration name. |
| 419 | /// |
| 420 | /// By default, transforms the types of conversion function, constructor, |
| 421 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 422 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 423 | /// override this function to provide alternate behavior. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 424 | DeclarationNameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 425 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 426 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 427 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 429 | /// \param SS The nested-name-specifier that qualifies the template |
| 430 | /// name. This nested-name-specifier must already have been transformed. |
| 431 | /// |
| 432 | /// \param Name The template name to transform. |
| 433 | /// |
| 434 | /// \param NameLoc The source location of the template name. |
| 435 | /// |
| 436 | /// \param ObjectType If we're translating a template name within a member |
| 437 | /// access expression, this is the type of the object whose member template |
| 438 | /// is being referenced. |
| 439 | /// |
| 440 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 441 | /// also refers to a name within the current (lexical) scope, this is the |
| 442 | /// declaration it refers to. |
| 443 | /// |
| 444 | /// By default, transforms the template name by transforming the declarations |
| 445 | /// and nested-name-specifiers that occur within the template name. |
| 446 | /// Subclasses may override this function to provide alternate behavior. |
| 447 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 448 | TemplateName Name, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 449 | SourceLocation NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 450 | QualType ObjectType = QualType(), |
| 451 | NamedDecl *FirstQualifierInScope = 0); |
| 452 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 453 | /// \brief Transform the given template argument. |
| 454 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | /// By default, this operation transforms the type, expression, or |
| 456 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 457 | /// new template argument from the transformed result. Subclasses may |
| 458 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 459 | /// |
| 460 | /// Returns true if there was an error. |
| 461 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 462 | TemplateArgumentLoc &Output); |
| 463 | |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 464 | /// \brief Transform the given set of template arguments. |
| 465 | /// |
| 466 | /// By default, this operation transforms all of the template arguments |
| 467 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 468 | /// the transformed arguments to the output list. |
| 469 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 470 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 471 | /// a convenience function. Subclasses that wish to override this behavior |
| 472 | /// should override the iterator-based member template version. |
| 473 | /// |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 474 | /// \param Inputs The set of template arguments to be transformed. |
| 475 | /// |
| 476 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 477 | /// |
| 478 | /// \param Outputs The set of transformed template arguments output by this |
| 479 | /// routine. |
| 480 | /// |
| 481 | /// Returns true if an error occurred. |
| 482 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 483 | unsigned NumInputs, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 484 | TemplateArgumentListInfo &Outputs) { |
| 485 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 486 | } |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 487 | |
| 488 | /// \brief Transform the given set of template arguments. |
| 489 | /// |
| 490 | /// By default, this operation transforms all of the template arguments |
| 491 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 492 | /// the transformed arguments to the output list. |
| 493 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 494 | /// \param First An iterator to the first template argument. |
| 495 | /// |
| 496 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 497 | /// |
| 498 | /// \param Outputs The set of transformed template arguments output by this |
| 499 | /// routine. |
| 500 | /// |
| 501 | /// Returns true if an error occurred. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 502 | template<typename InputIterator> |
| 503 | bool TransformTemplateArguments(InputIterator First, |
| 504 | InputIterator Last, |
| 505 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 506 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 507 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 508 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 509 | TemplateArgumentLoc &ArgLoc); |
| 510 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 511 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 512 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 513 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 514 | getDerived().getBaseLocation()); |
| 515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 517 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 518 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 519 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 520 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 522 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 523 | FunctionProtoTypeLoc TL, |
| 524 | CXXRecordDecl *ThisContext, |
| 525 | unsigned ThisTypeQuals); |
| 526 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 527 | StmtResult |
| 528 | TransformSEHHandler(Stmt *Handler); |
| 529 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 530 | QualType |
| 531 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 532 | TemplateSpecializationTypeLoc TL, |
| 533 | TemplateName Template); |
| 534 | |
| 535 | QualType |
| 536 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 537 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 538 | TemplateName Template, |
| 539 | CXXScopeSpec &SS); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 540 | |
| 541 | QualType |
| 542 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 543 | DependentTemplateSpecializationTypeLoc TL, |
| 544 | NestedNameSpecifierLoc QualifierLoc); |
| 545 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 546 | /// \brief Transforms the parameters of a function type into the |
| 547 | /// given vectors. |
| 548 | /// |
| 549 | /// The result vectors should be kept in sync; null entries in the |
| 550 | /// variables vector are acceptable. |
| 551 | /// |
| 552 | /// Return true on error. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 553 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 554 | ParmVarDecl **Params, unsigned NumParams, |
| 555 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 556 | SmallVectorImpl<QualType> &PTypes, |
| 557 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 558 | |
| 559 | /// \brief Transforms a single function-type parameter. Return null |
| 560 | /// on error. |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 561 | /// |
| 562 | /// \param indexAdjustment - A number to add to the parameter's |
| 563 | /// scope index; can be negative |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 564 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 565 | int indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 566 | llvm::Optional<unsigned> NumExpansions, |
| 567 | bool ExpectParameterPack); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 568 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 569 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 570 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 571 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 572 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 574 | #define STMT(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 575 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 576 | #define EXPR(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 577 | ExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 578 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 579 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 580 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 581 | /// \brief Build a new pointer type given its pointee type. |
| 582 | /// |
| 583 | /// By default, performs semantic analysis when building the pointer type. |
| 584 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 585 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 586 | |
| 587 | /// \brief Build a new block pointer type given its pointee type. |
| 588 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 589 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 590 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 591 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
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 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 594 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 595 | /// By default, performs semantic analysis when building the |
| 596 | /// reference type. Subclasses may override this routine to provide |
| 597 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 598 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 599 | /// \param LValue whether the type was written with an lvalue sigil |
| 600 | /// or an rvalue sigil. |
| 601 | QualType RebuildReferenceType(QualType ReferentType, |
| 602 | bool LValue, |
| 603 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 604 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 605 | /// \brief Build a new member pointer type given the pointee type and the |
| 606 | /// class type it refers into. |
| 607 | /// |
| 608 | /// By default, performs semantic analysis when building the member pointer |
| 609 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 610 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 611 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 612 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 613 | /// \brief Build a new array type given the element type, size |
| 614 | /// modifier, size of the array (if known), size expression, and index type |
| 615 | /// qualifiers. |
| 616 | /// |
| 617 | /// By default, performs semantic analysis when building the array type. |
| 618 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 620 | QualType RebuildArrayType(QualType ElementType, |
| 621 | ArrayType::ArraySizeModifier SizeMod, |
| 622 | const llvm::APInt *Size, |
| 623 | Expr *SizeExpr, |
| 624 | unsigned IndexTypeQuals, |
| 625 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 627 | /// \brief Build a new constant array type given the element type, size |
| 628 | /// modifier, (known) size of the array, and index type qualifiers. |
| 629 | /// |
| 630 | /// By default, performs semantic analysis when building the array type. |
| 631 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 632 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 633 | ArrayType::ArraySizeModifier SizeMod, |
| 634 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 635 | unsigned IndexTypeQuals, |
| 636 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 637 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 638 | /// \brief Build a new incomplete array type given the element type, size |
| 639 | /// modifier, and index type qualifiers. |
| 640 | /// |
| 641 | /// By default, performs semantic analysis when building the array type. |
| 642 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 644 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 645 | unsigned IndexTypeQuals, |
| 646 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 647 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 648 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 649 | /// size modifier, size expression, and index type qualifiers. |
| 650 | /// |
| 651 | /// By default, performs semantic analysis when building the array type. |
| 652 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 653 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 654 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 655 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 656 | unsigned IndexTypeQuals, |
| 657 | SourceRange BracketsRange); |
| 658 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 659 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 660 | /// size modifier, size expression, and index type qualifiers. |
| 661 | /// |
| 662 | /// By default, performs semantic analysis when building the array type. |
| 663 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 665 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 666 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 667 | unsigned IndexTypeQuals, |
| 668 | SourceRange BracketsRange); |
| 669 | |
| 670 | /// \brief Build a new vector type given the element type and |
| 671 | /// number of elements. |
| 672 | /// |
| 673 | /// By default, performs semantic analysis when building the vector type. |
| 674 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 675 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 676 | VectorType::VectorKind VecKind); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 678 | /// \brief Build a new extended vector type given the element type and |
| 679 | /// number of elements. |
| 680 | /// |
| 681 | /// By default, performs semantic analysis when building the vector type. |
| 682 | /// Subclasses may override this routine to provide different behavior. |
| 683 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 684 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 685 | |
| 686 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 687 | /// given the element type and number of elements. |
| 688 | /// |
| 689 | /// By default, performs semantic analysis when building the vector type. |
| 690 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 691 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 692 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 693 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 695 | /// \brief Build a new function type. |
| 696 | /// |
| 697 | /// By default, performs semantic analysis when building the function type. |
| 698 | /// Subclasses may override this routine to provide different behavior. |
| 699 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 701 | unsigned NumParamTypes, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 702 | bool Variadic, bool HasTrailingReturn, |
| 703 | unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 704 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 705 | const FunctionType::ExtInfo &Info); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 707 | /// \brief Build a new unprototyped function type. |
| 708 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 709 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 710 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 711 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 712 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 713 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 714 | /// \brief Build a new typedef type. |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 715 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 716 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 717 | } |
| 718 | |
| 719 | /// \brief Build a new class/struct/union type. |
| 720 | QualType RebuildRecordType(RecordDecl *Record) { |
| 721 | return SemaRef.Context.getTypeDeclType(Record); |
| 722 | } |
| 723 | |
| 724 | /// \brief Build a new Enum type. |
| 725 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 726 | return SemaRef.Context.getTypeDeclType(Enum); |
| 727 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 728 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 730 | /// |
| 731 | /// By default, performs semantic analysis when building the typeof type. |
| 732 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 733 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 734 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 736 | /// |
| 737 | /// By default, builds a new TypeOfType with the given underlying type. |
| 738 | QualType RebuildTypeOfType(QualType Underlying); |
| 739 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 740 | /// \brief Build a new unary transform type. |
| 741 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 742 | UnaryTransformType::UTTKind UKind, |
| 743 | SourceLocation Loc); |
| 744 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 746 | /// |
| 747 | /// By default, performs semantic analysis when building the decltype type. |
| 748 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 749 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 751 | /// \brief Build a new C++0x auto type. |
| 752 | /// |
| 753 | /// By default, builds a new AutoType with the given deduced type. |
| 754 | QualType RebuildAutoType(QualType Deduced) { |
| 755 | return SemaRef.Context.getAutoType(Deduced); |
| 756 | } |
| 757 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 758 | /// \brief Build a new template specialization type. |
| 759 | /// |
| 760 | /// By default, performs semantic analysis when building the template |
| 761 | /// specialization type. Subclasses may override this routine to provide |
| 762 | /// different behavior. |
| 763 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 764 | SourceLocation TemplateLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 765 | TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 767 | /// \brief Build a new parenthesized type. |
| 768 | /// |
| 769 | /// By default, builds a new ParenType type from the inner type. |
| 770 | /// Subclasses may override this routine to provide different behavior. |
| 771 | QualType RebuildParenType(QualType InnerType) { |
| 772 | return SemaRef.Context.getParenType(InnerType); |
| 773 | } |
| 774 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 775 | /// \brief Build a new qualified name type. |
| 776 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 777 | /// By default, builds a new ElaboratedType type from the keyword, |
| 778 | /// the nested-name-specifier and the named type. |
| 779 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 780 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 781 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 782 | NestedNameSpecifierLoc QualifierLoc, |
| 783 | QualType Named) { |
| 784 | return SemaRef.Context.getElaboratedType(Keyword, |
| 785 | QualifierLoc.getNestedNameSpecifier(), |
| 786 | Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 787 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 788 | |
| 789 | /// \brief Build a new typename type that refers to a template-id. |
| 790 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 791 | /// By default, builds a new DependentNameType type from the |
| 792 | /// nested-name-specifier and the given type. Subclasses may override |
| 793 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 794 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 795 | ElaboratedTypeKeyword Keyword, |
| 796 | NestedNameSpecifierLoc QualifierLoc, |
| 797 | const IdentifierInfo *Name, |
| 798 | SourceLocation NameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 799 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 800 | // Rebuild the template name. |
| 801 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 802 | CXXScopeSpec SS; |
| 803 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 804 | TemplateName InstName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 805 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 806 | |
| 807 | if (InstName.isNull()) |
| 808 | return QualType(); |
| 809 | |
| 810 | // If it's still dependent, make a dependent specialization. |
| 811 | if (InstName.getAsDependentTemplateName()) |
| 812 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 813 | QualifierLoc.getNestedNameSpecifier(), |
| 814 | Name, |
| 815 | Args); |
| 816 | |
| 817 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 818 | // specialization. |
| 819 | QualType T = |
| 820 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 821 | if (T.isNull()) return QualType(); |
| 822 | |
| 823 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 824 | return T; |
| 825 | |
| 826 | return SemaRef.Context.getElaboratedType(Keyword, |
| 827 | QualifierLoc.getNestedNameSpecifier(), |
| 828 | T); |
| 829 | } |
| 830 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 831 | /// \brief Build a new typename type that refers to an identifier. |
| 832 | /// |
| 833 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 834 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 835 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 836 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 837 | SourceLocation KeywordLoc, |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 838 | NestedNameSpecifierLoc QualifierLoc, |
| 839 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 840 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 841 | CXXScopeSpec SS; |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 842 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 843 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 844 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 845 | // If the name is still dependent, just build a new dependent name type. |
| 846 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 847 | return SemaRef.Context.getDependentNameType(Keyword, |
| 848 | QualifierLoc.getNestedNameSpecifier(), |
| 849 | Id); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 852 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 853 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | e29425b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 854 | *Id, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 855 | |
| 856 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 857 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 858 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 859 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 860 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 861 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 862 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 863 | if (!DC) |
| 864 | return QualType(); |
| 865 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 866 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 867 | return QualType(); |
| 868 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 869 | TagDecl *Tag = 0; |
| 870 | SemaRef.LookupQualifiedName(Result, DC); |
| 871 | switch (Result.getResultKind()) { |
| 872 | case LookupResult::NotFound: |
| 873 | case LookupResult::NotFoundInCurrentInstantiation: |
| 874 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 875 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 876 | case LookupResult::Found: |
| 877 | Tag = Result.getAsSingle<TagDecl>(); |
| 878 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 879 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 880 | case LookupResult::FoundOverloaded: |
| 881 | case LookupResult::FoundUnresolvedValue: |
| 882 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 883 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 884 | case LookupResult::Ambiguous: |
| 885 | // Let the LookupResult structure handle ambiguities. |
| 886 | return QualType(); |
| 887 | } |
| 888 | |
| 889 | if (!Tag) { |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 890 | // Check where the name exists but isn't a tag type and use that to emit |
| 891 | // better diagnostics. |
| 892 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 893 | SemaRef.LookupQualifiedName(Result, DC); |
| 894 | switch (Result.getResultKind()) { |
| 895 | case LookupResult::Found: |
| 896 | case LookupResult::FoundOverloaded: |
| 897 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 898 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 899 | unsigned Kind = 0; |
| 900 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 901 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 902 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 903 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 904 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 905 | break; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 906 | } |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 907 | default: |
| 908 | // FIXME: Would be nice to highlight just the source range. |
| 909 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 910 | << Kind << Id << DC; |
| 911 | break; |
| 912 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 913 | return QualType(); |
| 914 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 915 | |
Richard Trieu | bbf34c0 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 916 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 917 | IdLoc, *Id)) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 918 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 919 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 920 | return QualType(); |
| 921 | } |
| 922 | |
| 923 | // Build the elaborated-type-specifier type. |
| 924 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 925 | return SemaRef.Context.getElaboratedType(Keyword, |
| 926 | QualifierLoc.getNestedNameSpecifier(), |
| 927 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 930 | /// \brief Build a new pack expansion type. |
| 931 | /// |
| 932 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 933 | /// Subclasses may override this routine to provide different behavior. |
| 934 | QualType RebuildPackExpansionType(QualType Pattern, |
| 935 | SourceRange PatternRange, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 936 | SourceLocation EllipsisLoc, |
| 937 | llvm::Optional<unsigned> NumExpansions) { |
| 938 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 939 | NumExpansions); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 942 | /// \brief Build a new atomic type given its value type. |
| 943 | /// |
| 944 | /// By default, performs semantic analysis when building the atomic type. |
| 945 | /// Subclasses may override this routine to provide different behavior. |
| 946 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 947 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 948 | /// \brief Build a new template name given a nested name specifier, a flag |
| 949 | /// indicating whether the "template" keyword was provided, and the template |
| 950 | /// that the template name refers to. |
| 951 | /// |
| 952 | /// By default, builds the new template name directly. Subclasses may override |
| 953 | /// this routine to provide different behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 954 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 955 | bool TemplateKW, |
| 956 | TemplateDecl *Template); |
| 957 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 958 | /// \brief Build a new template name given a nested name specifier and the |
| 959 | /// name that is referred to as a template. |
| 960 | /// |
| 961 | /// By default, performs semantic analysis to determine whether the name can |
| 962 | /// be resolved to a specific template, then builds the appropriate kind of |
| 963 | /// template name. Subclasses may override this routine to provide different |
| 964 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 965 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 966 | const IdentifierInfo &Name, |
| 967 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 968 | QualType ObjectType, |
| 969 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 970 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 971 | /// \brief Build a new template name given a nested name specifier and the |
| 972 | /// overloaded operator name that is referred to as a template. |
| 973 | /// |
| 974 | /// By default, performs semantic analysis to determine whether the name can |
| 975 | /// be resolved to a specific template, then builds the appropriate kind of |
| 976 | /// template name. Subclasses may override this routine to provide different |
| 977 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 978 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 979 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 980 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 981 | QualType ObjectType); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 982 | |
| 983 | /// \brief Build a new template name given a template template parameter pack |
| 984 | /// and the |
| 985 | /// |
| 986 | /// By default, performs semantic analysis to determine whether the name can |
| 987 | /// be resolved to a specific template, then builds the appropriate kind of |
| 988 | /// template name. Subclasses may override this routine to provide different |
| 989 | /// behavior. |
| 990 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 991 | const TemplateArgument &ArgPack) { |
| 992 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 993 | } |
| 994 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 995 | /// \brief Build a new compound statement. |
| 996 | /// |
| 997 | /// By default, performs semantic analysis to build the new statement. |
| 998 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 999 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1000 | MultiStmtArg Statements, |
| 1001 | SourceLocation RBraceLoc, |
| 1002 | bool IsStmtExpr) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1003 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1004 | IsStmtExpr); |
| 1005 | } |
| 1006 | |
| 1007 | /// \brief Build a new case statement. |
| 1008 | /// |
| 1009 | /// By default, performs semantic analysis to build the new statement. |
| 1010 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1011 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1012 | Expr *LHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1013 | SourceLocation EllipsisLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1014 | Expr *RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1015 | SourceLocation ColonLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1016 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1017 | ColonLoc); |
| 1018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1019 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1020 | /// \brief Attach the body to a new case statement. |
| 1021 | /// |
| 1022 | /// By default, performs semantic analysis to build the new statement. |
| 1023 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1024 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1025 | getSema().ActOnCaseStmtBody(S, Body); |
| 1026 | return S; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1027 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1029 | /// \brief Build a new default statement. |
| 1030 | /// |
| 1031 | /// By default, performs semantic analysis to build the new statement. |
| 1032 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1033 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1034 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1035 | Stmt *SubStmt) { |
| 1036 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1037 | /*CurScope=*/0); |
| 1038 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1039 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1040 | /// \brief Build a new label statement. |
| 1041 | /// |
| 1042 | /// By default, performs semantic analysis to build the new statement. |
| 1043 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1044 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1045 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1046 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1047 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1049 | /// \brief Build a new label statement. |
| 1050 | /// |
| 1051 | /// By default, performs semantic analysis to build the new statement. |
| 1052 | /// Subclasses may override this routine to provide different behavior. |
| 1053 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs, |
| 1054 | Stmt *SubStmt) { |
| 1055 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1056 | } |
| 1057 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1058 | /// \brief Build a new "if" 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 RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1063 | VarDecl *CondVar, Stmt *Then, |
| 1064 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1065 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
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 Start building a new 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 RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1073 | Expr *Cond, VarDecl *CondVar) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1074 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1075 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1076 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1078 | /// \brief Attach the body to the switch statement. |
| 1079 | /// |
| 1080 | /// By default, performs semantic analysis to build the new statement. |
| 1081 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1082 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1083 | Stmt *Switch, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1084 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | /// \brief Build a new while statement. |
| 1088 | /// |
| 1089 | /// By default, performs semantic analysis to build the new statement. |
| 1090 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1091 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1092 | VarDecl *CondVar, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1093 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1094 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1096 | /// \brief Build a new do-while statement. |
| 1097 | /// |
| 1098 | /// By default, performs semantic analysis to build the new statement. |
| 1099 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1100 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1101 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1102 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1103 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1104 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /// \brief Build a new for statement. |
| 1108 | /// |
| 1109 | /// By default, performs semantic analysis to build the new statement. |
| 1110 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1111 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1112 | Stmt *Init, Sema::FullExprArg Cond, |
| 1113 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1114 | SourceLocation RParenLoc, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1115 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1116 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1117 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1119 | /// \brief Build a new goto statement. |
| 1120 | /// |
| 1121 | /// By default, performs semantic analysis to build the new statement. |
| 1122 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1123 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1124 | LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1125 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | /// \brief Build a new indirect goto statement. |
| 1129 | /// |
| 1130 | /// By default, performs semantic analysis to build the new statement. |
| 1131 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1132 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1133 | SourceLocation StarLoc, |
| 1134 | Expr *Target) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1135 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1138 | /// \brief Build a new return statement. |
| 1139 | /// |
| 1140 | /// By default, performs semantic analysis to build the new statement. |
| 1141 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1142 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1143 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1144 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1146 | /// \brief Build a new declaration statement. |
| 1147 | /// |
| 1148 | /// By default, performs semantic analysis to build the new statement. |
| 1149 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1150 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1152 | SourceLocation EndLoc) { |
Richard Smith | 406c38e | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1153 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1154 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1156 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1157 | /// \brief Build a new inline asm statement. |
| 1158 | /// |
| 1159 | /// By default, performs semantic analysis to build the new statement. |
| 1160 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1161 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1162 | bool IsSimple, |
| 1163 | bool IsVolatile, |
| 1164 | unsigned NumOutputs, |
| 1165 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1166 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1167 | MultiExprArg Constraints, |
| 1168 | MultiExprArg Exprs, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1169 | Expr *AsmString, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1170 | MultiExprArg Clobbers, |
| 1171 | SourceLocation RParenLoc, |
| 1172 | bool MSAsm) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1173 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1174 | NumInputs, Names, move(Constraints), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1175 | Exprs, AsmString, Clobbers, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1176 | RParenLoc, MSAsm); |
| 1177 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1178 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1179 | /// \brief Build a new MS style inline asm statement. |
| 1180 | /// |
| 1181 | /// By default, performs semantic analysis to build the new statement. |
| 1182 | /// Subclasses may override this routine to provide different behavior. |
| 1183 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, |
| 1184 | std::string &AsmString, |
| 1185 | SourceLocation EndLoc) { |
| 1186 | return getSema().ActOnMSAsmStmt(AsmLoc, AsmString, EndLoc); |
| 1187 | } |
| 1188 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1189 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1190 | /// |
| 1191 | /// By default, performs semantic analysis to build the new statement. |
| 1192 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1193 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1194 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1195 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1196 | Stmt *Finally) { |
| 1197 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1198 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1201 | /// \brief Rebuild an Objective-C exception declaration. |
| 1202 | /// |
| 1203 | /// By default, performs semantic analysis to build the new declaration. |
| 1204 | /// Subclasses may override this routine to provide different behavior. |
| 1205 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1206 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1207 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1208 | ExceptionDecl->getInnerLocStart(), |
| 1209 | ExceptionDecl->getLocation(), |
| 1210 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1211 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1212 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1213 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1214 | /// |
| 1215 | /// By default, performs semantic analysis to build the new statement. |
| 1216 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1217 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1218 | SourceLocation RParenLoc, |
| 1219 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1220 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1221 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1222 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1223 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1224 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1225 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1226 | /// |
| 1227 | /// By default, performs semantic analysis to build the new statement. |
| 1228 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1229 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1230 | Stmt *Body) { |
| 1231 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1232 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1233 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1234 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1235 | /// |
| 1236 | /// By default, performs semantic analysis to build the new statement. |
| 1237 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1238 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1239 | Expr *Operand) { |
| 1240 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1241 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1242 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1243 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1244 | /// |
| 1245 | /// By default, performs semantic analysis to build the new statement. |
| 1246 | /// Subclasses may override this routine to provide different behavior. |
| 1247 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1248 | Expr *object) { |
| 1249 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1250 | } |
| 1251 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1252 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1253 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1254 | /// By default, performs semantic analysis to build the new statement. |
| 1255 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1256 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1257 | Expr *Object, Stmt *Body) { |
| 1258 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1259 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1260 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1261 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1262 | /// |
| 1263 | /// By default, performs semantic analysis to build the new statement. |
| 1264 | /// Subclasses may override this routine to provide different behavior. |
| 1265 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1266 | Stmt *Body) { |
| 1267 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1268 | } |
John McCall | 990567c | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1269 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1270 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1271 | /// |
| 1272 | /// By default, performs semantic analysis to build the new statement. |
| 1273 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1274 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1275 | SourceLocation LParenLoc, |
| 1276 | Stmt *Element, |
| 1277 | Expr *Collection, |
| 1278 | SourceLocation RParenLoc, |
| 1279 | Stmt *Body) { |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1280 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
| 1281 | Element, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1282 | Collection, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1283 | RParenLoc); |
| 1284 | if (ForEachStmt.isInvalid()) |
| 1285 | return StmtError(); |
| 1286 | |
| 1287 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1288 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1289 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1290 | /// \brief Build a new C++ exception declaration. |
| 1291 | /// |
| 1292 | /// By default, performs semantic analysis to build the new decaration. |
| 1293 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1294 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1295 | TypeSourceInfo *Declarator, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1296 | SourceLocation StartLoc, |
| 1297 | SourceLocation IdLoc, |
| 1298 | IdentifierInfo *Id) { |
Douglas Gregor | efdf988 | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1299 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1300 | StartLoc, IdLoc, Id); |
| 1301 | if (Var) |
| 1302 | getSema().CurContext->addDecl(Var); |
| 1303 | return Var; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /// \brief Build a new C++ catch statement. |
| 1307 | /// |
| 1308 | /// By default, performs semantic analysis to build the new statement. |
| 1309 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1310 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1311 | VarDecl *ExceptionDecl, |
| 1312 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1313 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1314 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1316 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1317 | /// \brief Build a new C++ try statement. |
| 1318 | /// |
| 1319 | /// By default, performs semantic analysis to build the new statement. |
| 1320 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1321 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1322 | Stmt *TryBlock, |
| 1323 | MultiStmtArg Handlers) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1324 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1325 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1327 | /// \brief Build a new C++0x range-based for statement. |
| 1328 | /// |
| 1329 | /// By default, performs semantic analysis to build the new statement. |
| 1330 | /// Subclasses may override this routine to provide different behavior. |
| 1331 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1332 | SourceLocation ColonLoc, |
| 1333 | Stmt *Range, Stmt *BeginEnd, |
| 1334 | Expr *Cond, Expr *Inc, |
| 1335 | Stmt *LoopVar, |
| 1336 | SourceLocation RParenLoc) { |
| 1337 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
| 1338 | Cond, Inc, LoopVar, RParenLoc); |
| 1339 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1340 | |
| 1341 | /// \brief Build a new C++0x range-based for statement. |
| 1342 | /// |
| 1343 | /// By default, performs semantic analysis to build the new statement. |
| 1344 | /// Subclasses may override this routine to provide different behavior. |
| 1345 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
| 1346 | bool IsIfExists, |
| 1347 | NestedNameSpecifierLoc QualifierLoc, |
| 1348 | DeclarationNameInfo NameInfo, |
| 1349 | Stmt *Nested) { |
| 1350 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1351 | QualifierLoc, NameInfo, Nested); |
| 1352 | } |
| 1353 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1354 | /// \brief Attach body to a C++0x range-based for statement. |
| 1355 | /// |
| 1356 | /// By default, performs semantic analysis to finish the new statement. |
| 1357 | /// Subclasses may override this routine to provide different behavior. |
| 1358 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1359 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1360 | } |
| 1361 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1362 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, |
| 1363 | SourceLocation TryLoc, |
| 1364 | Stmt *TryBlock, |
| 1365 | Stmt *Handler) { |
| 1366 | return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1367 | } |
| 1368 | |
| 1369 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, |
| 1370 | Expr *FilterExpr, |
| 1371 | Stmt *Block) { |
| 1372 | return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); |
| 1373 | } |
| 1374 | |
| 1375 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, |
| 1376 | Stmt *Block) { |
| 1377 | return getSema().ActOnSEHFinallyBlock(Loc,Block); |
| 1378 | } |
| 1379 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | /// \brief Build a new expression that references a declaration. |
| 1381 | /// |
| 1382 | /// By default, performs semantic analysis to build the new expression. |
| 1383 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1384 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1385 | LookupResult &R, |
| 1386 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1387 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | /// \brief Build a new expression that references a declaration. |
| 1392 | /// |
| 1393 | /// By default, performs semantic analysis to build the new expression. |
| 1394 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1395 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1396 | ValueDecl *VD, |
| 1397 | const DeclarationNameInfo &NameInfo, |
| 1398 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1399 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1400 | SS.Adopt(QualifierLoc); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1401 | |
| 1402 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1403 | |
| 1404 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1406 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1407 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | /// By default, performs semantic analysis to build the new expression. |
| 1410 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1411 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1413 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1416 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +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 RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1421 | SourceLocation OperatorLoc, |
| 1422 | bool isArrow, |
| 1423 | CXXScopeSpec &SS, |
| 1424 | TypeSourceInfo *ScopeType, |
| 1425 | SourceLocation CCLoc, |
| 1426 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1427 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1429 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1431 | /// By default, performs semantic analysis to build the new expression. |
| 1432 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1433 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1434 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1435 | Expr *SubExpr) { |
| 1436 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1437 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1438 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1439 | /// \brief Build a new builtin offsetof expression. |
| 1440 | /// |
| 1441 | /// By default, performs semantic analysis to build the new expression. |
| 1442 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1443 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1444 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1445 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1446 | unsigned NumComponents, |
| 1447 | SourceLocation RParenLoc) { |
| 1448 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1449 | NumComponents, RParenLoc); |
| 1450 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1451 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1452 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
| 1453 | /// type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1454 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1455 | /// By default, performs semantic analysis to build the new expression. |
| 1456 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1457 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1458 | SourceLocation OpLoc, |
| 1459 | UnaryExprOrTypeTrait ExprKind, |
| 1460 | SourceRange R) { |
| 1461 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1464 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1465 | /// expression argument. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1468 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1469 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1470 | UnaryExprOrTypeTrait ExprKind, |
| 1471 | SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1472 | ExprResult Result |
Chandler Carruth | e72c55b | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1473 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1474 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1475 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1476 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | return move(Result); |
| 1478 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1479 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | /// \brief Build a new array subscript 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 RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1486 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1487 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1488 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1489 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1490 | RBracketLoc); |
| 1491 | } |
| 1492 | |
| 1493 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | /// By default, performs semantic analysis to build the new expression. |
| 1496 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1497 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | MultiExprArg Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1499 | SourceLocation RParenLoc, |
| 1500 | Expr *ExecConfig = 0) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1501 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1502 | move(Args), RParenLoc, ExecConfig); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1506 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | /// By default, performs semantic analysis to build the new expression. |
| 1508 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1509 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1510 | bool isArrow, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1511 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1512 | SourceLocation TemplateKWLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1513 | const DeclarationNameInfo &MemberNameInfo, |
| 1514 | ValueDecl *Member, |
| 1515 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1516 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1517 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1518 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1519 | isArrow); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1520 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1521 | // We have a reference to an unnamed field. This is always the |
| 1522 | // base of an anonymous struct/union member access, i.e. the |
| 1523 | // field is always of record type. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1524 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1525 | assert(Member->getType()->isRecordType() && |
| 1526 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1527 | |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1528 | BaseResult = |
| 1529 | getSema().PerformObjectMemberConversion(BaseResult.take(), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1530 | QualifierLoc.getNestedNameSpecifier(), |
| 1531 | FoundDecl, Member); |
| 1532 | if (BaseResult.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1533 | return ExprError(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1534 | Base = BaseResult.take(); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1535 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1536 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1537 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1538 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1539 | cast<FieldDecl>(Member)->getType(), |
| 1540 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1541 | return getSema().Owned(ME); |
| 1542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1543 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1544 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1545 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1546 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1547 | Base = BaseResult.take(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1548 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1549 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1550 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1551 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1552 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1553 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1554 | R.resolveKind(); |
| 1555 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1556 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1557 | SS, TemplateKWLoc, |
| 1558 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1559 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1561 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1562 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1564 | /// By default, performs semantic analysis to build the new expression. |
| 1565 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1566 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1567 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1568 | Expr *LHS, Expr *RHS) { |
| 1569 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | /// \brief Build a new conditional operator 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 RebuildConditionalOperator(Expr *Cond, |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1577 | SourceLocation QuestionLoc, |
| 1578 | Expr *LHS, |
| 1579 | SourceLocation ColonLoc, |
| 1580 | Expr *RHS) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1581 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1582 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1585 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1586 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | /// By default, performs semantic analysis to build the new expression. |
| 1588 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1589 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1590 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1592 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1593 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1594 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1595 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1596 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1597 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1598 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1599 | /// By default, performs semantic analysis to build the new expression. |
| 1600 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1601 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1602 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1603 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1604 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1605 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1606 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1608 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1609 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1611 | /// By default, performs semantic analysis to build the new expression. |
| 1612 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1613 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | SourceLocation OpLoc, |
| 1615 | SourceLocation AccessorLoc, |
| 1616 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1617 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1618 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1619 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1620 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1621 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1622 | SS, SourceLocation(), |
| 1623 | /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1624 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1625 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1628 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | /// By default, performs semantic analysis to build the new expression. |
| 1631 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1632 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1633 | MultiExprArg Inits, |
| 1634 | SourceLocation RBraceLoc, |
| 1635 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1636 | ExprResult Result |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1637 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1638 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1639 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1640 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1641 | // Patch in the result type we were given, which may have been computed |
| 1642 | // when the initial InitListExpr was built. |
| 1643 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1644 | ILE->setType(ResultTy); |
| 1645 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | /// \brief Build a new designated initializer expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1651 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1652 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1653 | MultiExprArg ArrayExprs, |
| 1654 | SourceLocation EqualOrColonLoc, |
| 1655 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1656 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1657 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1659 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1661 | return ExprError(); |
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 | ArrayExprs.release(); |
| 1664 | return move(Result); |
| 1665 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1667 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | /// By default, builds the implicit value initialization without performing |
| 1670 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1671 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1672 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1674 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1676 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1677 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1678 | /// By default, performs semantic analysis to build the new expression. |
| 1679 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1680 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1681 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1682 | SourceLocation RParenLoc) { |
| 1683 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1684 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1685 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1689 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1690 | /// By default, performs semantic analysis to build the new expression. |
| 1691 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1692 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1693 | MultiExprArg SubExprs, |
| 1694 | SourceLocation RParenLoc) { |
| 1695 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1697 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1699 | /// |
| 1700 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1701 | /// rather than attempting to map the label statement itself. |
| 1702 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1703 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1704 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1705 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1706 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1707 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1708 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1709 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | /// By default, performs semantic analysis to build the new expression. |
| 1711 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1712 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1713 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1715 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1716 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1717 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | /// \brief Build a new __builtin_choose_expr expression. |
| 1719 | /// |
| 1720 | /// By default, performs semantic analysis to build the new expression. |
| 1721 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1722 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1723 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1724 | SourceLocation RParenLoc) { |
| 1725 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1726 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1727 | RParenLoc); |
| 1728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1730 | /// \brief Build a new generic selection expression. |
| 1731 | /// |
| 1732 | /// By default, performs semantic analysis to build the new expression. |
| 1733 | /// Subclasses may override this routine to provide different behavior. |
| 1734 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1735 | SourceLocation DefaultLoc, |
| 1736 | SourceLocation RParenLoc, |
| 1737 | Expr *ControllingExpr, |
| 1738 | TypeSourceInfo **Types, |
| 1739 | Expr **Exprs, |
| 1740 | unsigned NumAssocs) { |
| 1741 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 1742 | ControllingExpr, Types, Exprs, |
| 1743 | NumAssocs); |
| 1744 | } |
| 1745 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1746 | /// \brief Build a new overloaded operator call expression. |
| 1747 | /// |
| 1748 | /// By default, performs semantic analysis to build the new expression. |
| 1749 | /// The semantic analysis provides the behavior of template instantiation, |
| 1750 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1752 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1753 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1754 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1755 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1756 | Expr *Callee, |
| 1757 | Expr *First, |
| 1758 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1759 | |
| 1760 | /// \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] | 1761 | /// reinterpret_cast. |
| 1762 | /// |
| 1763 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1764 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1765 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1766 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1767 | Stmt::StmtClass Class, |
| 1768 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1769 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1770 | SourceLocation RAngleLoc, |
| 1771 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1772 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1773 | SourceLocation RParenLoc) { |
| 1774 | switch (Class) { |
| 1775 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1776 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1778 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1779 | |
| 1780 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1781 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1783 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1785 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1786 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1787 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1788 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1789 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1791 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1792 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1793 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1794 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1795 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1796 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1797 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1798 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1799 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1800 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1801 | /// \brief Build a new C++ static_cast expression. |
| 1802 | /// |
| 1803 | /// By default, performs semantic analysis to build the new expression. |
| 1804 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1805 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1806 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1807 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1808 | SourceLocation RAngleLoc, |
| 1809 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1810 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1811 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1812 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1813 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1814 | SourceRange(LAngleLoc, RAngleLoc), |
| 1815 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | /// \brief Build a new C++ dynamic_cast expression. |
| 1819 | /// |
| 1820 | /// By default, performs semantic analysis to build the new expression. |
| 1821 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1822 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1823 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1824 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1825 | SourceLocation RAngleLoc, |
| 1826 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1827 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1828 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1829 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1830 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1831 | SourceRange(LAngleLoc, RAngleLoc), |
| 1832 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1836 | /// |
| 1837 | /// By default, performs semantic analysis to build the new expression. |
| 1838 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1839 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1840 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1841 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1842 | SourceLocation RAngleLoc, |
| 1843 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1844 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1845 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1846 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1847 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1848 | SourceRange(LAngleLoc, RAngleLoc), |
| 1849 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | /// \brief Build a new C++ const_cast expression. |
| 1853 | /// |
| 1854 | /// By default, performs semantic analysis to build the new expression. |
| 1855 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1856 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1857 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1858 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1859 | SourceLocation RAngleLoc, |
| 1860 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1861 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1862 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1863 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1864 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1865 | SourceRange(LAngleLoc, RAngleLoc), |
| 1866 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1867 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1869 | /// \brief Build a new C++ functional-style cast expression. |
| 1870 | /// |
| 1871 | /// By default, performs semantic analysis to build the new expression. |
| 1872 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1873 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1874 | SourceLocation LParenLoc, |
| 1875 | Expr *Sub, |
| 1876 | SourceLocation RParenLoc) { |
| 1877 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1878 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1879 | RParenLoc); |
| 1880 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1881 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1882 | /// \brief Build a new C++ typeid(type) expression. |
| 1883 | /// |
| 1884 | /// By default, performs semantic analysis to build the new expression. |
| 1885 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1886 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1887 | SourceLocation TypeidLoc, |
| 1888 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1889 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1890 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1891 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1892 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1893 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1894 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1895 | /// \brief Build a new C++ typeid(expr) expression. |
| 1896 | /// |
| 1897 | /// By default, performs semantic analysis to build the new expression. |
| 1898 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1899 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1900 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1901 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1902 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1903 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1904 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1907 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1908 | /// |
| 1909 | /// By default, performs semantic analysis to build the new expression. |
| 1910 | /// Subclasses may override this routine to provide different behavior. |
| 1911 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1912 | SourceLocation TypeidLoc, |
| 1913 | TypeSourceInfo *Operand, |
| 1914 | SourceLocation RParenLoc) { |
| 1915 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1916 | RParenLoc); |
| 1917 | } |
| 1918 | |
| 1919 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1920 | /// |
| 1921 | /// By default, performs semantic analysis to build the new expression. |
| 1922 | /// Subclasses may override this routine to provide different behavior. |
| 1923 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1924 | SourceLocation TypeidLoc, |
| 1925 | Expr *Operand, |
| 1926 | SourceLocation RParenLoc) { |
| 1927 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1928 | RParenLoc); |
| 1929 | } |
| 1930 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1931 | /// \brief Build a new C++ "this" expression. |
| 1932 | /// |
| 1933 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1934 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1935 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1936 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1937 | QualType ThisType, |
| 1938 | bool isImplicit) { |
Eli Friedman | b69b42c | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 1939 | getSema().CheckCXXThisCapture(ThisLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1940 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1941 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1942 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | /// \brief Build a new C++ throw expression. |
| 1946 | /// |
| 1947 | /// By default, performs semantic analysis to build the new expression. |
| 1948 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 1949 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 1950 | bool IsThrownVariableInScope) { |
| 1951 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | /// \brief Build a new C++ default-argument expression. |
| 1955 | /// |
| 1956 | /// By default, builds a new default-argument expression, which does not |
| 1957 | /// require any semantic analysis. Subclasses may override this routine to |
| 1958 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1959 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1960 | ParmVarDecl *Param) { |
| 1961 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1962 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /// \brief Build a new C++ zero-initialization expression. |
| 1966 | /// |
| 1967 | /// By default, performs semantic analysis to build the new expression. |
| 1968 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1969 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1970 | SourceLocation LParenLoc, |
| 1971 | SourceLocation RParenLoc) { |
| 1972 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1973 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1974 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1975 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1976 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1977 | /// \brief Build a new C++ "new" expression. |
| 1978 | /// |
| 1979 | /// By default, performs semantic analysis to build the new expression. |
| 1980 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1981 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1982 | bool UseGlobal, |
| 1983 | SourceLocation PlacementLParen, |
| 1984 | MultiExprArg PlacementArgs, |
| 1985 | SourceLocation PlacementRParen, |
| 1986 | SourceRange TypeIdParens, |
| 1987 | QualType AllocatedType, |
| 1988 | TypeSourceInfo *AllocatedTypeInfo, |
| 1989 | Expr *ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 1990 | SourceRange DirectInitRange, |
| 1991 | Expr *Initializer) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | PlacementLParen, |
| 1994 | move(PlacementArgs), |
| 1995 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1996 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1997 | AllocatedType, |
| 1998 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1999 | ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2000 | DirectInitRange, |
| 2001 | Initializer); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2002 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2004 | /// \brief Build a new C++ "delete" expression. |
| 2005 | /// |
| 2006 | /// By default, performs semantic analysis to build the new expression. |
| 2007 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2008 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2009 | bool IsGlobalDelete, |
| 2010 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2011 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2012 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2013 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2015 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2016 | /// \brief Build a new unary 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. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2020 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 2021 | SourceLocation StartLoc, |
| 2022 | TypeSourceInfo *T, |
| 2023 | SourceLocation RParenLoc) { |
| 2024 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2027 | /// \brief Build a new binary type trait expression. |
| 2028 | /// |
| 2029 | /// By default, performs semantic analysis to build the new expression. |
| 2030 | /// Subclasses may override this routine to provide different behavior. |
| 2031 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 2032 | SourceLocation StartLoc, |
| 2033 | TypeSourceInfo *LhsT, |
| 2034 | TypeSourceInfo *RhsT, |
| 2035 | SourceLocation RParenLoc) { |
| 2036 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 2037 | } |
| 2038 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2039 | /// \brief Build a new type trait expression. |
| 2040 | /// |
| 2041 | /// By default, performs semantic analysis to build the new expression. |
| 2042 | /// Subclasses may override this routine to provide different behavior. |
| 2043 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2044 | SourceLocation StartLoc, |
| 2045 | ArrayRef<TypeSourceInfo *> Args, |
| 2046 | SourceLocation RParenLoc) { |
| 2047 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2048 | } |
| 2049 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2050 | /// \brief Build a new array type trait expression. |
| 2051 | /// |
| 2052 | /// By default, performs semantic analysis to build the new expression. |
| 2053 | /// Subclasses may override this routine to provide different behavior. |
| 2054 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2055 | SourceLocation StartLoc, |
| 2056 | TypeSourceInfo *TSInfo, |
| 2057 | Expr *DimExpr, |
| 2058 | SourceLocation RParenLoc) { |
| 2059 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2060 | } |
| 2061 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2062 | /// \brief Build a new expression trait expression. |
| 2063 | /// |
| 2064 | /// By default, performs semantic analysis to build the new expression. |
| 2065 | /// Subclasses may override this routine to provide different behavior. |
| 2066 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2067 | SourceLocation StartLoc, |
| 2068 | Expr *Queried, |
| 2069 | SourceLocation RParenLoc) { |
| 2070 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2071 | } |
| 2072 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2073 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2074 | /// expression. |
| 2075 | /// |
| 2076 | /// By default, performs semantic analysis to build the new expression. |
| 2077 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2078 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2079 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2080 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2081 | const DeclarationNameInfo &NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2082 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2083 | CXXScopeSpec SS; |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2084 | SS.Adopt(QualifierLoc); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2085 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2086 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2087 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2088 | NameInfo, TemplateArgs); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2089 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2090 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | /// \brief Build a new template-id expression. |
| 2094 | /// |
| 2095 | /// By default, performs semantic analysis to build the new expression. |
| 2096 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2097 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2098 | SourceLocation TemplateKWLoc, |
| 2099 | LookupResult &R, |
| 2100 | bool RequiresADL, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2101 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2102 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2103 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | /// \brief Build a new object-construction expression. |
| 2107 | /// |
| 2108 | /// By default, performs semantic analysis to build the new expression. |
| 2109 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2110 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2111 | SourceLocation Loc, |
| 2112 | CXXConstructorDecl *Constructor, |
| 2113 | bool IsElidable, |
| 2114 | MultiExprArg Args, |
| 2115 | bool HadMultipleCandidates, |
| 2116 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2117 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2118 | SourceRange ParenRange) { |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 2119 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2120 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2121 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2122 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2123 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2124 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 2125 | move_arg(ConvertedArgs), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2126 | HadMultipleCandidates, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2127 | RequiresZeroInit, ConstructKind, |
| 2128 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | /// \brief Build a new object-construction expression. |
| 2132 | /// |
| 2133 | /// By default, performs semantic analysis to build the new expression. |
| 2134 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2135 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2136 | SourceLocation LParenLoc, |
| 2137 | MultiExprArg Args, |
| 2138 | SourceLocation RParenLoc) { |
| 2139 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2140 | LParenLoc, |
| 2141 | move(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2142 | RParenLoc); |
| 2143 | } |
| 2144 | |
| 2145 | /// \brief Build a new object-construction expression. |
| 2146 | /// |
| 2147 | /// By default, performs semantic analysis to build the new expression. |
| 2148 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2149 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2150 | SourceLocation LParenLoc, |
| 2151 | MultiExprArg Args, |
| 2152 | SourceLocation RParenLoc) { |
| 2153 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2154 | LParenLoc, |
| 2155 | move(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2156 | RParenLoc); |
| 2157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2159 | /// \brief Build a new member reference expression. |
| 2160 | /// |
| 2161 | /// By default, performs semantic analysis to build the new expression. |
| 2162 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2163 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2164 | QualType BaseType, |
| 2165 | bool IsArrow, |
| 2166 | SourceLocation OperatorLoc, |
| 2167 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2168 | SourceLocation TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2169 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2170 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2171 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2172 | CXXScopeSpec SS; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2173 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2174 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2175 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2176 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2177 | SS, TemplateKWLoc, |
| 2178 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2179 | MemberNameInfo, |
| 2180 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2183 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2184 | /// |
| 2185 | /// By default, performs semantic analysis to build the new expression. |
| 2186 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2187 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2188 | SourceLocation OperatorLoc, |
| 2189 | bool IsArrow, |
| 2190 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2191 | SourceLocation TemplateKWLoc, |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2192 | NamedDecl *FirstQualifierInScope, |
| 2193 | LookupResult &R, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2194 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2195 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2196 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2197 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2198 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2199 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2200 | SS, TemplateKWLoc, |
| 2201 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2202 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2203 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2204 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2205 | /// \brief Build a new noexcept expression. |
| 2206 | /// |
| 2207 | /// By default, performs semantic analysis to build the new expression. |
| 2208 | /// Subclasses may override this routine to provide different behavior. |
| 2209 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2210 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2211 | } |
| 2212 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2213 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2214 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2215 | SourceLocation PackLoc, |
| 2216 | SourceLocation RParenLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2217 | llvm::Optional<unsigned> Length) { |
| 2218 | if (Length) |
| 2219 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2220 | OperatorLoc, Pack, PackLoc, |
| 2221 | RParenLoc, *Length); |
| 2222 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2223 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2224 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2225 | RParenLoc); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2226 | } |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2227 | |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2228 | /// \brief Build a new Objective-C boxed expression. |
| 2229 | /// |
| 2230 | /// By default, performs semantic analysis to build the new expression. |
| 2231 | /// Subclasses may override this routine to provide different behavior. |
| 2232 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2233 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2234 | } |
| 2235 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2236 | /// \brief Build a new Objective-C array literal. |
| 2237 | /// |
| 2238 | /// By default, performs semantic analysis to build the new expression. |
| 2239 | /// Subclasses may override this routine to provide different behavior. |
| 2240 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2241 | Expr **Elements, unsigned NumElements) { |
| 2242 | return getSema().BuildObjCArrayLiteral(Range, |
| 2243 | MultiExprArg(Elements, NumElements)); |
| 2244 | } |
| 2245 | |
| 2246 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
| 2247 | Expr *Base, Expr *Key, |
| 2248 | ObjCMethodDecl *getterMethod, |
| 2249 | ObjCMethodDecl *setterMethod) { |
| 2250 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2251 | getterMethod, setterMethod); |
| 2252 | } |
| 2253 | |
| 2254 | /// \brief Build a new Objective-C dictionary literal. |
| 2255 | /// |
| 2256 | /// By default, performs semantic analysis to build the new expression. |
| 2257 | /// Subclasses may override this routine to provide different behavior. |
| 2258 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2259 | ObjCDictionaryElement *Elements, |
| 2260 | unsigned NumElements) { |
| 2261 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2262 | } |
| 2263 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2264 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2265 | /// |
| 2266 | /// By default, performs semantic analysis to build the new expression. |
| 2267 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2268 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2269 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2270 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2271 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2272 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2273 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2275 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2276 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2277 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2278 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2279 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2280 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2281 | MultiExprArg Args, |
| 2282 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2283 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2284 | ReceiverTypeInfo->getType(), |
| 2285 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2286 | Sel, Method, LBracLoc, SelectorLocs, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2287 | RBracLoc, move(Args)); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2291 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2292 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2293 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2294 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2295 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2296 | MultiExprArg Args, |
| 2297 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2298 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2299 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2300 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2301 | Sel, Method, LBracLoc, SelectorLocs, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2302 | RBracLoc, move(Args)); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2305 | /// \brief Build a new Objective-C ivar reference expression. |
| 2306 | /// |
| 2307 | /// By default, performs semantic analysis to build the new expression. |
| 2308 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2309 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2310 | SourceLocation IvarLoc, |
| 2311 | bool IsArrow, bool IsFreeIvar) { |
| 2312 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2313 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2314 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2315 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2316 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2317 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2318 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2319 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2320 | false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2321 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2322 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2323 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2324 | if (Result.get()) |
| 2325 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2326 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2327 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2328 | /*FIXME:*/IvarLoc, IsArrow, |
| 2329 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2330 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2331 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2332 | /*TemplateArgs=*/0); |
| 2333 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2334 | |
| 2335 | /// \brief Build a new Objective-C property reference expression. |
| 2336 | /// |
| 2337 | /// By default, performs semantic analysis to build the new expression. |
| 2338 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2339 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2340 | ObjCPropertyDecl *Property, |
| 2341 | SourceLocation PropertyLoc) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2342 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2343 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2344 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2345 | Sema::LookupMemberName); |
| 2346 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2347 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2348 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2349 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2350 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2351 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2352 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2353 | if (Result.get()) |
| 2354 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2355 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2356 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2357 | /*FIXME:*/PropertyLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2358 | SS, SourceLocation(), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2359 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2360 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2361 | /*TemplateArgs=*/0); |
| 2362 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2363 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2364 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2365 | /// |
| 2366 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2367 | /// Subclasses may override this routine to provide different behavior. |
| 2368 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2369 | ObjCMethodDecl *Getter, |
| 2370 | ObjCMethodDecl *Setter, |
| 2371 | SourceLocation PropertyLoc) { |
| 2372 | // Since these expressions can only be value-dependent, we do not |
| 2373 | // need to perform semantic analysis again. |
| 2374 | return Owned( |
| 2375 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2376 | VK_LValue, OK_ObjCProperty, |
| 2377 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2380 | /// \brief Build a new Objective-C "isa" expression. |
| 2381 | /// |
| 2382 | /// By default, performs semantic analysis to build the new expression. |
| 2383 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2384 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2385 | bool IsArrow) { |
| 2386 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2387 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2388 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2389 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2390 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2391 | /*FIME:*/IsaLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2392 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2393 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2394 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2395 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2396 | if (Result.get()) |
| 2397 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2398 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2399 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2400 | /*FIXME:*/IsaLoc, IsArrow, |
| 2401 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2402 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2403 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2404 | /*TemplateArgs=*/0); |
| 2405 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2406 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2407 | /// \brief Build a new shuffle vector expression. |
| 2408 | /// |
| 2409 | /// By default, performs semantic analysis to build the new expression. |
| 2410 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2411 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2412 | MultiExprArg SubExprs, |
| 2413 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2414 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2415 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2416 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2417 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2418 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2419 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2420 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2421 | // Build a reference to the __builtin_shufflevector builtin |
| 2422 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2423 | ExprResult Callee |
John McCall | f4b88a4 | 2012-03-10 09:33:50 +0000 | [diff] [blame] | 2424 | = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2425 | Builtin->getType(), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2426 | VK_LValue, BuiltinLoc)); |
| 2427 | Callee = SemaRef.UsualUnaryConversions(Callee.take()); |
| 2428 | if (Callee.isInvalid()) |
| 2429 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2430 | |
| 2431 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2432 | unsigned NumSubExprs = SubExprs.size(); |
| 2433 | Expr **Subs = (Expr **)SubExprs.release(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2434 | ExprResult TheCall = SemaRef.Owned( |
| 2435 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2436 | Subs, NumSubExprs, |
Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2437 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2438 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2439 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2440 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2441 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2442 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2443 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2444 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2445 | /// \brief Build a new template argument pack expansion. |
| 2446 | /// |
| 2447 | /// By default, performs semantic analysis to build a new pack expansion |
| 2448 | /// for a template argument. Subclasses may override this routine to provide |
| 2449 | /// different behavior. |
| 2450 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2451 | SourceLocation EllipsisLoc, |
| 2452 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2453 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2454 | case TemplateArgument::Expression: { |
| 2455 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2456 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2457 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2458 | if (Result.isInvalid()) |
| 2459 | return TemplateArgumentLoc(); |
| 2460 | |
| 2461 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2462 | } |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2463 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2464 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2465 | return TemplateArgumentLoc(TemplateArgument( |
| 2466 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2467 | NumExpansions), |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2468 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2469 | Pattern.getTemplateNameLoc(), |
| 2470 | EllipsisLoc); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2471 | |
| 2472 | case TemplateArgument::Null: |
| 2473 | case TemplateArgument::Integral: |
| 2474 | case TemplateArgument::Declaration: |
| 2475 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2476 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2477 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2478 | |
| 2479 | case TemplateArgument::Type: |
| 2480 | if (TypeSourceInfo *Expansion |
| 2481 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2482 | EllipsisLoc, |
| 2483 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2484 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2485 | Expansion); |
| 2486 | break; |
| 2487 | } |
| 2488 | |
| 2489 | return TemplateArgumentLoc(); |
| 2490 | } |
| 2491 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2492 | /// \brief Build a new expression pack expansion. |
| 2493 | /// |
| 2494 | /// By default, performs semantic analysis to build a new pack expansion |
| 2495 | /// for an expression. Subclasses may override this routine to provide |
| 2496 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2497 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2498 | llvm::Optional<unsigned> NumExpansions) { |
| 2499 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2500 | } |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2501 | |
| 2502 | /// \brief Build a new atomic operation expression. |
| 2503 | /// |
| 2504 | /// By default, performs semantic analysis to build the new expression. |
| 2505 | /// Subclasses may override this routine to provide different behavior. |
| 2506 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2507 | MultiExprArg SubExprs, |
| 2508 | QualType RetTy, |
| 2509 | AtomicExpr::AtomicOp Op, |
| 2510 | SourceLocation RParenLoc) { |
| 2511 | // Just create the expression; there is not any interesting semantic |
| 2512 | // analysis here because we can't actually build an AtomicExpr until |
| 2513 | // we are sure it is semantically sound. |
| 2514 | unsigned NumSubExprs = SubExprs.size(); |
| 2515 | Expr **Subs = (Expr **)SubExprs.release(); |
| 2516 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs, |
| 2517 | NumSubExprs, RetTy, Op, |
| 2518 | RParenLoc); |
| 2519 | } |
| 2520 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2521 | private: |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2522 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2523 | QualType ObjectType, |
| 2524 | NamedDecl *FirstQualifierInScope, |
| 2525 | CXXScopeSpec &SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2526 | |
| 2527 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2528 | QualType ObjectType, |
| 2529 | NamedDecl *FirstQualifierInScope, |
| 2530 | CXXScopeSpec &SS); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2531 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2532 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2533 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2534 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2535 | if (!S) |
| 2536 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2537 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2538 | switch (S->getStmtClass()) { |
| 2539 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2540 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2541 | // Transform individual statement nodes |
| 2542 | #define STMT(Node, Parent) \ |
| 2543 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2544 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2545 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2546 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2547 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2548 | // Transform expressions by calling TransformExpr. |
| 2549 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2550 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2551 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2552 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2553 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2554 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2555 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2556 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2557 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2558 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2559 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2562 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2563 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2564 | |
| 2565 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2566 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2567 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2568 | if (!E) |
| 2569 | return SemaRef.Owned(E); |
| 2570 | |
| 2571 | switch (E->getStmtClass()) { |
| 2572 | case Stmt::NoStmtClass: break; |
| 2573 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2574 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2575 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2576 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2577 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2580 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | template<typename Derived> |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2584 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2585 | unsigned NumInputs, |
| 2586 | bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2587 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2588 | bool *ArgChanged) { |
| 2589 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2590 | // If requested, drop call arguments that need to be dropped. |
| 2591 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2592 | if (ArgChanged) |
| 2593 | *ArgChanged = true; |
| 2594 | |
| 2595 | break; |
| 2596 | } |
| 2597 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2598 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2599 | Expr *Pattern = Expansion->getPattern(); |
| 2600 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2601 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2602 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2603 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2604 | |
| 2605 | // Determine whether the set of unexpanded parameter packs can and should |
| 2606 | // be expanded. |
| 2607 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2608 | bool RetainExpansion = false; |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2609 | llvm::Optional<unsigned> OrigNumExpansions |
| 2610 | = Expansion->getNumExpansions(); |
| 2611 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2612 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2613 | Pattern->getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2614 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2615 | Expand, RetainExpansion, |
| 2616 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2617 | return true; |
| 2618 | |
| 2619 | if (!Expand) { |
| 2620 | // The transform has determined that we should perform a simple |
| 2621 | // transformation on the pack expansion, producing another pack |
| 2622 | // expansion. |
| 2623 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2624 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2625 | if (OutPattern.isInvalid()) |
| 2626 | return true; |
| 2627 | |
| 2628 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2629 | Expansion->getEllipsisLoc(), |
| 2630 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2631 | if (Out.isInvalid()) |
| 2632 | return true; |
| 2633 | |
| 2634 | if (ArgChanged) |
| 2635 | *ArgChanged = true; |
| 2636 | Outputs.push_back(Out.get()); |
| 2637 | continue; |
| 2638 | } |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2639 | |
| 2640 | // Record right away that the argument was changed. This needs |
| 2641 | // to happen even if the array expands to nothing. |
| 2642 | if (ArgChanged) *ArgChanged = true; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2643 | |
| 2644 | // The transform has determined that we should perform an elementwise |
| 2645 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2646 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2647 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2648 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2649 | if (Out.isInvalid()) |
| 2650 | return true; |
| 2651 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2652 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2653 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2654 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2655 | if (Out.isInvalid()) |
| 2656 | return true; |
| 2657 | } |
| 2658 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2659 | Outputs.push_back(Out.get()); |
| 2660 | } |
| 2661 | |
| 2662 | continue; |
| 2663 | } |
| 2664 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2665 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2666 | if (Result.isInvalid()) |
| 2667 | return true; |
| 2668 | |
| 2669 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2670 | *ArgChanged = true; |
| 2671 | |
| 2672 | Outputs.push_back(Result.get()); |
| 2673 | } |
| 2674 | |
| 2675 | return false; |
| 2676 | } |
| 2677 | |
| 2678 | template<typename Derived> |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2679 | NestedNameSpecifierLoc |
| 2680 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2681 | NestedNameSpecifierLoc NNS, |
| 2682 | QualType ObjectType, |
| 2683 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2684 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2685 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 2686 | Qualifier = Qualifier.getPrefix()) |
| 2687 | Qualifiers.push_back(Qualifier); |
| 2688 | |
| 2689 | CXXScopeSpec SS; |
| 2690 | while (!Qualifiers.empty()) { |
| 2691 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2692 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| 2693 | |
| 2694 | switch (QNNS->getKind()) { |
| 2695 | case NestedNameSpecifier::Identifier: |
| 2696 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
| 2697 | *QNNS->getAsIdentifier(), |
| 2698 | Q.getLocalBeginLoc(), |
| 2699 | Q.getLocalEndLoc(), |
| 2700 | ObjectType, false, SS, |
| 2701 | FirstQualifierInScope, false)) |
| 2702 | return NestedNameSpecifierLoc(); |
| 2703 | |
| 2704 | break; |
| 2705 | |
| 2706 | case NestedNameSpecifier::Namespace: { |
| 2707 | NamespaceDecl *NS |
| 2708 | = cast_or_null<NamespaceDecl>( |
| 2709 | getDerived().TransformDecl( |
| 2710 | Q.getLocalBeginLoc(), |
| 2711 | QNNS->getAsNamespace())); |
| 2712 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2713 | break; |
| 2714 | } |
| 2715 | |
| 2716 | case NestedNameSpecifier::NamespaceAlias: { |
| 2717 | NamespaceAliasDecl *Alias |
| 2718 | = cast_or_null<NamespaceAliasDecl>( |
| 2719 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2720 | QNNS->getAsNamespaceAlias())); |
| 2721 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| 2722 | Q.getLocalEndLoc()); |
| 2723 | break; |
| 2724 | } |
| 2725 | |
| 2726 | case NestedNameSpecifier::Global: |
| 2727 | // There is no meaningful transformation that one could perform on the |
| 2728 | // global scope. |
| 2729 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2730 | break; |
| 2731 | |
| 2732 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2733 | case NestedNameSpecifier::TypeSpec: { |
| 2734 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2735 | FirstQualifierInScope, SS); |
| 2736 | |
| 2737 | if (!TL) |
| 2738 | return NestedNameSpecifierLoc(); |
| 2739 | |
| 2740 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2741 | (SemaRef.getLangOpts().CPlusPlus0x && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2742 | TL.getType()->isEnumeralType())) { |
| 2743 | assert(!TL.getType().hasLocalQualifiers() && |
| 2744 | "Can't get cv-qualifiers here"); |
Richard Smith | 95aafb2 | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 2745 | if (TL.getType()->isEnumeralType()) |
| 2746 | SemaRef.Diag(TL.getBeginLoc(), |
| 2747 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2748 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2749 | Q.getLocalEndLoc()); |
| 2750 | break; |
| 2751 | } |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2752 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2753 | // error because a previous error should have already been emitted. |
| 2754 | TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); |
| 2755 | if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { |
| 2756 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 2757 | << TL.getType() << SS.getRange(); |
| 2758 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2759 | return NestedNameSpecifierLoc(); |
| 2760 | } |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2761 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2762 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2763 | // 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] | 2764 | FirstQualifierInScope = 0; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2765 | ObjectType = QualType(); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | // Don't rebuild the nested-name-specifier if we don't have to. |
| 2769 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 2770 | !getDerived().AlwaysRebuild()) |
| 2771 | return NNS; |
| 2772 | |
| 2773 | // If we can re-use the source-location data from the original |
| 2774 | // nested-name-specifier, do so. |
| 2775 | if (SS.location_size() == NNS.getDataLength() && |
| 2776 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2777 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2778 | |
| 2779 | // Allocate new nested-name-specifier location information. |
| 2780 | return SS.getWithLocInContext(SemaRef.Context); |
| 2781 | } |
| 2782 | |
| 2783 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2784 | DeclarationNameInfo |
| 2785 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2786 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2787 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2788 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2789 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2790 | |
| 2791 | switch (Name.getNameKind()) { |
| 2792 | case DeclarationName::Identifier: |
| 2793 | case DeclarationName::ObjCZeroArgSelector: |
| 2794 | case DeclarationName::ObjCOneArgSelector: |
| 2795 | case DeclarationName::ObjCMultiArgSelector: |
| 2796 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2797 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2798 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2799 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2800 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2801 | case DeclarationName::CXXConstructorName: |
| 2802 | case DeclarationName::CXXDestructorName: |
| 2803 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2804 | TypeSourceInfo *NewTInfo; |
| 2805 | CanQualType NewCanTy; |
| 2806 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2807 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2808 | if (!NewTInfo) |
| 2809 | return DeclarationNameInfo(); |
| 2810 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2811 | } |
| 2812 | else { |
| 2813 | NewTInfo = 0; |
| 2814 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2815 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2816 | if (NewT.isNull()) |
| 2817 | return DeclarationNameInfo(); |
| 2818 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2819 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2820 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2821 | DeclarationName NewName |
| 2822 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2823 | NewCanTy); |
| 2824 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2825 | NewNameInfo.setName(NewName); |
| 2826 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2827 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2831 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2835 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2836 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 2837 | TemplateName Name, |
| 2838 | SourceLocation NameLoc, |
| 2839 | QualType ObjectType, |
| 2840 | NamedDecl *FirstQualifierInScope) { |
| 2841 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 2842 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 2843 | assert(Template && "qualified template name must refer to a template"); |
| 2844 | |
| 2845 | TemplateDecl *TransTemplate |
| 2846 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2847 | Template)); |
| 2848 | if (!TransTemplate) |
| 2849 | return TemplateName(); |
| 2850 | |
| 2851 | if (!getDerived().AlwaysRebuild() && |
| 2852 | SS.getScopeRep() == QTN->getQualifier() && |
| 2853 | TransTemplate == Template) |
| 2854 | return Name; |
| 2855 | |
| 2856 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 2857 | TransTemplate); |
| 2858 | } |
| 2859 | |
| 2860 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 2861 | if (SS.getScopeRep()) { |
| 2862 | // These apply to the scope specifier, not the template. |
| 2863 | ObjectType = QualType(); |
| 2864 | FirstQualifierInScope = 0; |
| 2865 | } |
| 2866 | |
| 2867 | if (!getDerived().AlwaysRebuild() && |
| 2868 | SS.getScopeRep() == DTN->getQualifier() && |
| 2869 | ObjectType.isNull()) |
| 2870 | return Name; |
| 2871 | |
| 2872 | if (DTN->isIdentifier()) { |
| 2873 | return getDerived().RebuildTemplateName(SS, |
| 2874 | *DTN->getIdentifier(), |
| 2875 | NameLoc, |
| 2876 | ObjectType, |
| 2877 | FirstQualifierInScope); |
| 2878 | } |
| 2879 | |
| 2880 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 2881 | ObjectType); |
| 2882 | } |
| 2883 | |
| 2884 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 2885 | TemplateDecl *TransTemplate |
| 2886 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2887 | Template)); |
| 2888 | if (!TransTemplate) |
| 2889 | return TemplateName(); |
| 2890 | |
| 2891 | if (!getDerived().AlwaysRebuild() && |
| 2892 | TransTemplate == Template) |
| 2893 | return Name; |
| 2894 | |
| 2895 | return TemplateName(TransTemplate); |
| 2896 | } |
| 2897 | |
| 2898 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2899 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2900 | TemplateTemplateParmDecl *TransParam |
| 2901 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2902 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 2903 | if (!TransParam) |
| 2904 | return TemplateName(); |
| 2905 | |
| 2906 | if (!getDerived().AlwaysRebuild() && |
| 2907 | TransParam == SubstPack->getParameterPack()) |
| 2908 | return Name; |
| 2909 | |
| 2910 | return getDerived().RebuildTemplateName(TransParam, |
| 2911 | SubstPack->getArgumentPack()); |
| 2912 | } |
| 2913 | |
| 2914 | // These should be getting filtered out before they reach the AST. |
| 2915 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2919 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2920 | const TemplateArgument &Arg, |
| 2921 | TemplateArgumentLoc &Output) { |
| 2922 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2923 | switch (Arg.getKind()) { |
| 2924 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2925 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2926 | break; |
| 2927 | |
| 2928 | case TemplateArgument::Type: |
| 2929 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2930 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2931 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2932 | break; |
| 2933 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2934 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2935 | case TemplateArgument::TemplateExpansion: { |
| 2936 | NestedNameSpecifierLocBuilder Builder; |
| 2937 | TemplateName Template = Arg.getAsTemplate(); |
| 2938 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 2939 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 2940 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 2941 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
| 2942 | |
| 2943 | if (Arg.getKind() == TemplateArgument::Template) |
| 2944 | Output = TemplateArgumentLoc(Arg, |
| 2945 | Builder.getWithLocInContext(SemaRef.Context), |
| 2946 | Loc); |
| 2947 | else |
| 2948 | Output = TemplateArgumentLoc(Arg, |
| 2949 | Builder.getWithLocInContext(SemaRef.Context), |
| 2950 | Loc, Loc); |
| 2951 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2952 | break; |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2953 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2954 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2955 | case TemplateArgument::Expression: |
| 2956 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2957 | break; |
| 2958 | |
| 2959 | case TemplateArgument::Declaration: |
| 2960 | case TemplateArgument::Integral: |
| 2961 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2962 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2963 | break; |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | template<typename Derived> |
| 2968 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2969 | const TemplateArgumentLoc &Input, |
| 2970 | TemplateArgumentLoc &Output) { |
| 2971 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2972 | switch (Arg.getKind()) { |
| 2973 | case TemplateArgument::Null: |
| 2974 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2975 | Output = Input; |
| 2976 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2977 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2978 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2979 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2980 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2981 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2982 | |
| 2983 | DI = getDerived().TransformType(DI); |
| 2984 | if (!DI) return true; |
| 2985 | |
| 2986 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2987 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2988 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2989 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2990 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2991 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2992 | DeclarationName Name; |
| 2993 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2994 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2995 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2996 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2997 | if (!D) return true; |
| 2998 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2999 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 3000 | if (SourceExpr) { |
| 3001 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3002 | Sema::ConstantEvaluated); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3003 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3004 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3005 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3009 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3010 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3012 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3013 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3014 | if (QualifierLoc) { |
| 3015 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3016 | if (!QualifierLoc) |
| 3017 | return true; |
| 3018 | } |
| 3019 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3020 | CXXScopeSpec SS; |
| 3021 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3022 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3023 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3024 | Input.getTemplateNameLoc()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3025 | if (Template.isNull()) |
| 3026 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3027 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3028 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3029 | Input.getTemplateNameLoc()); |
| 3030 | return false; |
| 3031 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3032 | |
| 3033 | case TemplateArgument::TemplateExpansion: |
| 3034 | llvm_unreachable("Caller should expand pack expansions"); |
| 3035 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3036 | case TemplateArgument::Expression: { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3037 | // Template argument expressions are constant expressions. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3038 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3039 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3040 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3041 | Expr *InputExpr = Input.getSourceExpression(); |
| 3042 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3043 | |
Chris Lattner | 223de24 | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3044 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3045 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3046 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3047 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3048 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3049 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3050 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3051 | case TemplateArgument::Pack: { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3052 | SmallVector<TemplateArgument, 4> TransformedArgs; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3053 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3054 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3055 | AEnd = Arg.pack_end(); |
| 3056 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3058 | // FIXME: preserve source information here when we start |
| 3059 | // caring about parameter packs. |
| 3060 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3061 | TemplateArgumentLoc InputArg; |
| 3062 | TemplateArgumentLoc OutputArg; |
| 3063 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 3064 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3065 | return true; |
| 3066 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3067 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3068 | } |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 3069 | |
| 3070 | TemplateArgument *TransformedArgsPtr |
| 3071 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 3072 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 3073 | TransformedArgsPtr); |
| 3074 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 3075 | TransformedArgs.size()), |
| 3076 | Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3077 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3078 | } |
| 3079 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3080 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3081 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3082 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3083 | } |
| 3084 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3085 | /// \brief Iterator adaptor that invents template argument location information |
| 3086 | /// for each of the template arguments in its underlying iterator. |
| 3087 | template<typename Derived, typename InputIterator> |
| 3088 | class TemplateArgumentLocInventIterator { |
| 3089 | TreeTransform<Derived> &Self; |
| 3090 | InputIterator Iter; |
| 3091 | |
| 3092 | public: |
| 3093 | typedef TemplateArgumentLoc value_type; |
| 3094 | typedef TemplateArgumentLoc reference; |
| 3095 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3096 | difference_type; |
| 3097 | typedef std::input_iterator_tag iterator_category; |
| 3098 | |
| 3099 | class pointer { |
| 3100 | TemplateArgumentLoc Arg; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3101 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3102 | public: |
| 3103 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 3104 | |
| 3105 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3106 | }; |
| 3107 | |
| 3108 | TemplateArgumentLocInventIterator() { } |
| 3109 | |
| 3110 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3111 | InputIterator Iter) |
| 3112 | : Self(Self), Iter(Iter) { } |
| 3113 | |
| 3114 | TemplateArgumentLocInventIterator &operator++() { |
| 3115 | ++Iter; |
| 3116 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3119 | TemplateArgumentLocInventIterator operator++(int) { |
| 3120 | TemplateArgumentLocInventIterator Old(*this); |
| 3121 | ++(*this); |
| 3122 | return Old; |
| 3123 | } |
| 3124 | |
| 3125 | reference operator*() const { |
| 3126 | TemplateArgumentLoc Result; |
| 3127 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3128 | return Result; |
| 3129 | } |
| 3130 | |
| 3131 | pointer operator->() const { return pointer(**this); } |
| 3132 | |
| 3133 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3134 | const TemplateArgumentLocInventIterator &Y) { |
| 3135 | return X.Iter == Y.Iter; |
| 3136 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3138 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3139 | const TemplateArgumentLocInventIterator &Y) { |
| 3140 | return X.Iter != Y.Iter; |
| 3141 | } |
| 3142 | }; |
| 3143 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3144 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3145 | template<typename InputIterator> |
| 3146 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3147 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3148 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3149 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3150 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3151 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3152 | |
| 3153 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3154 | // Unpack argument packs, which we translate them into separate |
| 3155 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3156 | // FIXME: We could do much better if we could guarantee that the |
| 3157 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3158 | // all of the template arguments in the argument pack. |
| 3159 | typedef TemplateArgumentLocInventIterator<Derived, |
| 3160 | TemplateArgument::pack_iterator> |
| 3161 | PackLocIterator; |
| 3162 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 3163 | In.getArgument().pack_begin()), |
| 3164 | PackLocIterator(*this, |
| 3165 | In.getArgument().pack_end()), |
| 3166 | Outputs)) |
| 3167 | return true; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3168 | |
| 3169 | continue; |
| 3170 | } |
| 3171 | |
| 3172 | if (In.getArgument().isPackExpansion()) { |
| 3173 | // We have a pack expansion, for which we will be substituting into |
| 3174 | // the pattern. |
| 3175 | SourceLocation Ellipsis; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3176 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3177 | TemplateArgumentLoc Pattern |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3178 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 3179 | getSema().Context); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3180 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3181 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3182 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3183 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 3184 | |
| 3185 | // Determine whether the set of unexpanded parameter packs can and should |
| 3186 | // be expanded. |
| 3187 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3188 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3189 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3190 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3191 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3192 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3193 | Expand, |
| 3194 | RetainExpansion, |
| 3195 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3196 | return true; |
| 3197 | |
| 3198 | if (!Expand) { |
| 3199 | // The transform has determined that we should perform a simple |
| 3200 | // transformation on the pack expansion, producing another pack |
| 3201 | // expansion. |
| 3202 | TemplateArgumentLoc OutPattern; |
| 3203 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3204 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3205 | return true; |
| 3206 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3207 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3208 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3209 | if (Out.getArgument().isNull()) |
| 3210 | return true; |
| 3211 | |
| 3212 | Outputs.addArgument(Out); |
| 3213 | continue; |
| 3214 | } |
| 3215 | |
| 3216 | // The transform has determined that we should perform an elementwise |
| 3217 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3218 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3219 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3220 | |
| 3221 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3222 | return true; |
| 3223 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3224 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3225 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3226 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3227 | if (Out.getArgument().isNull()) |
| 3228 | return true; |
| 3229 | } |
| 3230 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3231 | Outputs.addArgument(Out); |
| 3232 | } |
| 3233 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3234 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3235 | // forgetting the partially-substituted parameter pack. |
| 3236 | if (RetainExpansion) { |
| 3237 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3238 | |
| 3239 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3240 | return true; |
| 3241 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3242 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3243 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3244 | if (Out.getArgument().isNull()) |
| 3245 | return true; |
| 3246 | |
| 3247 | Outputs.addArgument(Out); |
| 3248 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3249 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3250 | continue; |
| 3251 | } |
| 3252 | |
| 3253 | // The simple case: |
| 3254 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3255 | return true; |
| 3256 | |
| 3257 | Outputs.addArgument(Out); |
| 3258 | } |
| 3259 | |
| 3260 | return false; |
| 3261 | |
| 3262 | } |
| 3263 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3264 | //===----------------------------------------------------------------------===// |
| 3265 | // Type transformation |
| 3266 | //===----------------------------------------------------------------------===// |
| 3267 | |
| 3268 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3269 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3270 | if (getDerived().AlreadyTransformed(T)) |
| 3271 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3272 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3273 | // Temporary workaround. All of these transformations should |
| 3274 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3275 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3276 | getDerived().getBaseLocation()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3277 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3278 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3279 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3280 | if (!NewDI) |
| 3281 | return QualType(); |
| 3282 | |
| 3283 | return NewDI->getType(); |
| 3284 | } |
| 3285 | |
| 3286 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3287 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3288 | // Refine the base location to the type's location. |
| 3289 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3290 | getDerived().getBaseEntity()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3291 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3292 | return DI; |
| 3293 | |
| 3294 | TypeLocBuilder TLB; |
| 3295 | |
| 3296 | TypeLoc TL = DI->getTypeLoc(); |
| 3297 | TLB.reserve(TL.getFullDataSize()); |
| 3298 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3299 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3300 | if (Result.isNull()) |
| 3301 | return 0; |
| 3302 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3303 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | template<typename Derived> |
| 3307 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3308 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3309 | switch (T.getTypeLocClass()) { |
| 3310 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3311 | #define TYPELOC(CLASS, PARENT) \ |
| 3312 | case TypeLoc::CLASS: \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3313 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3314 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3317 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3321 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3322 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3323 | /// types). This is the right thing for template instantiation, but |
| 3324 | /// probably not for other clients. |
| 3325 | template<typename Derived> |
| 3326 | QualType |
| 3327 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3328 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3329 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3330 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3331 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3332 | if (Result.isNull()) |
| 3333 | return QualType(); |
| 3334 | |
| 3335 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3336 | // FIXME: this is the right thing for template instantiation, but |
| 3337 | // probably not for other clients. |
| 3338 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3339 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3340 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3341 | // 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] | 3342 | // resulting type. |
| 3343 | if (Quals.hasObjCLifetime()) { |
| 3344 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3345 | Quals.removeObjCLifetime(); |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3346 | else if (Result.getObjCLifetime()) { |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3347 | // Objective-C ARC: |
| 3348 | // A lifetime qualifier applied to a substituted template parameter |
| 3349 | // overrides the lifetime qualifier from the template argument. |
| 3350 | if (const SubstTemplateTypeParmType *SubstTypeParam |
| 3351 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3352 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3353 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3354 | Qs.removeObjCLifetime(); |
| 3355 | Replacement |
| 3356 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3357 | Qs); |
| 3358 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
| 3359 | SubstTypeParam->getReplacedParameter(), |
| 3360 | Replacement); |
| 3361 | TLB.TypeWasModifiedSafely(Result); |
| 3362 | } else { |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3363 | // Otherwise, complain about the addition of a qualifier to an |
| 3364 | // already-qualified type. |
| 3365 | SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3366 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3367 | << Result << R; |
| 3368 | |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3369 | Quals.removeObjCLifetime(); |
| 3370 | } |
| 3371 | } |
| 3372 | } |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3373 | if (!Quals.empty()) { |
| 3374 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3375 | TLB.push<QualifiedTypeLoc>(Result); |
| 3376 | // No location information to preserve. |
| 3377 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3378 | |
| 3379 | return Result; |
| 3380 | } |
| 3381 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3382 | template<typename Derived> |
| 3383 | TypeLoc |
| 3384 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3385 | QualType ObjectType, |
| 3386 | NamedDecl *UnqualLookup, |
| 3387 | CXXScopeSpec &SS) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3388 | QualType T = TL.getType(); |
| 3389 | if (getDerived().AlreadyTransformed(T)) |
| 3390 | return TL; |
| 3391 | |
| 3392 | TypeLocBuilder TLB; |
| 3393 | QualType Result; |
| 3394 | |
| 3395 | if (isa<TemplateSpecializationType>(T)) { |
| 3396 | TemplateSpecializationTypeLoc SpecTL |
| 3397 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3398 | |
| 3399 | TemplateName Template = |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3400 | getDerived().TransformTemplateName(SS, |
| 3401 | SpecTL.getTypePtr()->getTemplateName(), |
| 3402 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3403 | ObjectType, UnqualLookup); |
| 3404 | if (Template.isNull()) |
| 3405 | return TypeLoc(); |
| 3406 | |
| 3407 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3408 | Template); |
| 3409 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3410 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3411 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3412 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3413 | TemplateName Template |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3414 | = getDerived().RebuildTemplateName(SS, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3415 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3416 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3417 | ObjectType, UnqualLookup); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3418 | if (Template.isNull()) |
| 3419 | return TypeLoc(); |
| 3420 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3421 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3422 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3423 | Template, |
| 3424 | SS); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3425 | } else { |
| 3426 | // Nothing special needs to be done for these. |
| 3427 | Result = getDerived().TransformType(TLB, TL); |
| 3428 | } |
| 3429 | |
| 3430 | if (Result.isNull()) |
| 3431 | return TypeLoc(); |
| 3432 | |
| 3433 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3434 | } |
| 3435 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3436 | template<typename Derived> |
| 3437 | TypeSourceInfo * |
| 3438 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3439 | QualType ObjectType, |
| 3440 | NamedDecl *UnqualLookup, |
| 3441 | CXXScopeSpec &SS) { |
| 3442 | // FIXME: Painfully copy-paste from the above! |
| 3443 | |
| 3444 | QualType T = TSInfo->getType(); |
| 3445 | if (getDerived().AlreadyTransformed(T)) |
| 3446 | return TSInfo; |
| 3447 | |
| 3448 | TypeLocBuilder TLB; |
| 3449 | QualType Result; |
| 3450 | |
| 3451 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3452 | if (isa<TemplateSpecializationType>(T)) { |
| 3453 | TemplateSpecializationTypeLoc SpecTL |
| 3454 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3455 | |
| 3456 | TemplateName Template |
| 3457 | = getDerived().TransformTemplateName(SS, |
| 3458 | SpecTL.getTypePtr()->getTemplateName(), |
| 3459 | SpecTL.getTemplateNameLoc(), |
| 3460 | ObjectType, UnqualLookup); |
| 3461 | if (Template.isNull()) |
| 3462 | return 0; |
| 3463 | |
| 3464 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3465 | Template); |
| 3466 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3467 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3468 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3469 | |
| 3470 | TemplateName Template |
| 3471 | = getDerived().RebuildTemplateName(SS, |
| 3472 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3473 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3474 | ObjectType, UnqualLookup); |
| 3475 | if (Template.isNull()) |
| 3476 | return 0; |
| 3477 | |
| 3478 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| 3479 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3480 | Template, |
| 3481 | SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3482 | } else { |
| 3483 | // Nothing special needs to be done for these. |
| 3484 | Result = getDerived().TransformType(TLB, TL); |
| 3485 | } |
| 3486 | |
| 3487 | if (Result.isNull()) |
| 3488 | return 0; |
| 3489 | |
| 3490 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3491 | } |
| 3492 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3493 | template <class TyLoc> static inline |
| 3494 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3495 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3496 | NewT.setNameLoc(T.getNameLoc()); |
| 3497 | return T.getType(); |
| 3498 | } |
| 3499 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3500 | template<typename Derived> |
| 3501 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3502 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3503 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3504 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3505 | if (T.needsExtraLocalData()) |
| 3506 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3507 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3508 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3509 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3510 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3511 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3512 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3513 | // FIXME: recurse? |
| 3514 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3516 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3517 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3518 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3519 | PointerTypeLoc TL) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3520 | QualType PointeeType |
| 3521 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3522 | if (PointeeType.isNull()) |
| 3523 | return QualType(); |
| 3524 | |
| 3525 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3526 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3527 | // A dependent pointer type 'T *' has is being transformed such |
| 3528 | // that an Objective-C class type is being replaced for 'T'. The |
| 3529 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3530 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3531 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3532 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3533 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3534 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3535 | return Result; |
| 3536 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3537 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3538 | if (getDerived().AlwaysRebuild() || |
| 3539 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3540 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3541 | if (Result.isNull()) |
| 3542 | return QualType(); |
| 3543 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3544 | |
| 3545 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3546 | // pointing to. |
| 3547 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
| 3548 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3549 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3550 | NewT.setSigilLoc(TL.getSigilLoc()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3551 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3552 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | |
| 3554 | template<typename Derived> |
| 3555 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3556 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3557 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3558 | QualType PointeeType |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3559 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3560 | if (PointeeType.isNull()) |
| 3561 | return QualType(); |
| 3562 | |
| 3563 | QualType Result = TL.getType(); |
| 3564 | if (getDerived().AlwaysRebuild() || |
| 3565 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3566 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3567 | TL.getSigilLoc()); |
| 3568 | if (Result.isNull()) |
| 3569 | return QualType(); |
| 3570 | } |
| 3571 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3572 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3573 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3574 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3575 | } |
| 3576 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3577 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3578 | /// don't care whether the type itself is an l-value type or an r-value |
| 3579 | /// type; we only care if the type was *written* as an l-value type |
| 3580 | /// or an r-value type. |
| 3581 | template<typename Derived> |
| 3582 | QualType |
| 3583 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3584 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3585 | const ReferenceType *T = TL.getTypePtr(); |
| 3586 | |
| 3587 | // Note that this works with the pointee-as-written. |
| 3588 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3589 | if (PointeeType.isNull()) |
| 3590 | return QualType(); |
| 3591 | |
| 3592 | QualType Result = TL.getType(); |
| 3593 | if (getDerived().AlwaysRebuild() || |
| 3594 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3595 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3596 | T->isSpelledAsLValue(), |
| 3597 | TL.getSigilLoc()); |
| 3598 | if (Result.isNull()) |
| 3599 | return QualType(); |
| 3600 | } |
| 3601 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3602 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3603 | // referring to. |
| 3604 | TLB.TypeWasModifiedSafely( |
| 3605 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3606 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3607 | // r-value references can be rebuilt as l-value references. |
| 3608 | ReferenceTypeLoc NewTL; |
| 3609 | if (isa<LValueReferenceType>(Result)) |
| 3610 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3611 | else |
| 3612 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3613 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3614 | |
| 3615 | return Result; |
| 3616 | } |
| 3617 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3618 | template<typename Derived> |
| 3619 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3620 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3621 | LValueReferenceTypeLoc TL) { |
| 3622 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3623 | } |
| 3624 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3625 | template<typename Derived> |
| 3626 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3627 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3628 | RValueReferenceTypeLoc TL) { |
| 3629 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3630 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3632 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3633 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3634 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3635 | MemberPointerTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3636 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3637 | if (PointeeType.isNull()) |
| 3638 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3639 | |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3640 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3641 | TypeSourceInfo* NewClsTInfo = 0; |
| 3642 | if (OldClsTInfo) { |
| 3643 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3644 | if (!NewClsTInfo) |
| 3645 | return QualType(); |
| 3646 | } |
| 3647 | |
| 3648 | const MemberPointerType *T = TL.getTypePtr(); |
| 3649 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3650 | QualType NewClsType; |
| 3651 | if (NewClsTInfo) |
| 3652 | NewClsType = NewClsTInfo->getType(); |
| 3653 | else { |
| 3654 | NewClsType = getDerived().TransformType(OldClsType); |
| 3655 | if (NewClsType.isNull()) |
| 3656 | return QualType(); |
| 3657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3658 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3659 | QualType Result = TL.getType(); |
| 3660 | if (getDerived().AlwaysRebuild() || |
| 3661 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3662 | NewClsType != OldClsType) { |
| 3663 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3664 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3665 | if (Result.isNull()) |
| 3666 | return QualType(); |
| 3667 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3668 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3669 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3670 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3671 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3672 | |
| 3673 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3676 | template<typename Derived> |
| 3677 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3678 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3679 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3680 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3681 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3682 | if (ElementType.isNull()) |
| 3683 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3684 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3685 | QualType Result = TL.getType(); |
| 3686 | if (getDerived().AlwaysRebuild() || |
| 3687 | ElementType != T->getElementType()) { |
| 3688 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3689 | T->getSizeModifier(), |
| 3690 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3691 | T->getIndexTypeCVRQualifiers(), |
| 3692 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3693 | if (Result.isNull()) |
| 3694 | return QualType(); |
| 3695 | } |
Eli Friedman | 457a377 | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 3696 | |
| 3697 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 3698 | // a ConstantArrayType is allowed to have an element type which is a |
| 3699 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 3700 | // types have the same location layout. |
| 3701 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3702 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3703 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3704 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3705 | Expr *Size = TL.getSizeExpr(); |
| 3706 | if (Size) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3707 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3708 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3709 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3710 | Size = SemaRef.ActOnConstantExpression(Size).take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3711 | } |
| 3712 | NewTL.setSizeExpr(Size); |
| 3713 | |
| 3714 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3715 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3716 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3717 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3718 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3719 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3720 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3721 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3722 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3723 | if (ElementType.isNull()) |
| 3724 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3725 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3726 | QualType Result = TL.getType(); |
| 3727 | if (getDerived().AlwaysRebuild() || |
| 3728 | ElementType != T->getElementType()) { |
| 3729 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3730 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3731 | T->getIndexTypeCVRQualifiers(), |
| 3732 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3733 | if (Result.isNull()) |
| 3734 | return QualType(); |
| 3735 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3736 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3737 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3738 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3739 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3740 | NewTL.setSizeExpr(0); |
| 3741 | |
| 3742 | return Result; |
| 3743 | } |
| 3744 | |
| 3745 | template<typename Derived> |
| 3746 | QualType |
| 3747 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3748 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3749 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3750 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3751 | if (ElementType.isNull()) |
| 3752 | return QualType(); |
| 3753 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3754 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3755 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3756 | if (SizeResult.isInvalid()) |
| 3757 | return QualType(); |
| 3758 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3759 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3760 | |
| 3761 | QualType Result = TL.getType(); |
| 3762 | if (getDerived().AlwaysRebuild() || |
| 3763 | ElementType != T->getElementType() || |
| 3764 | Size != T->getSizeExpr()) { |
| 3765 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3766 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3767 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3768 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3769 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3770 | if (Result.isNull()) |
| 3771 | return QualType(); |
| 3772 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3773 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3774 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3775 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3776 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3777 | NewTL.setSizeExpr(Size); |
| 3778 | |
| 3779 | return Result; |
| 3780 | } |
| 3781 | |
| 3782 | template<typename Derived> |
| 3783 | QualType |
| 3784 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3785 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3786 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3787 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3788 | if (ElementType.isNull()) |
| 3789 | return QualType(); |
| 3790 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3791 | // Array bounds are constant expressions. |
| 3792 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3793 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3794 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3795 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3796 | Expr *origSize = TL.getSizeExpr(); |
| 3797 | if (!origSize) origSize = T->getSizeExpr(); |
| 3798 | |
| 3799 | ExprResult sizeResult |
| 3800 | = getDerived().TransformExpr(origSize); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3801 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3802 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3803 | return QualType(); |
| 3804 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3805 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3806 | |
| 3807 | QualType Result = TL.getType(); |
| 3808 | if (getDerived().AlwaysRebuild() || |
| 3809 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3810 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3811 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3812 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3813 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3814 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3815 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3816 | if (Result.isNull()) |
| 3817 | return QualType(); |
| 3818 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3819 | |
| 3820 | // We might have any sort of array type now, but fortunately they |
| 3821 | // all have the same location layout. |
| 3822 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3823 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3824 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3825 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3826 | |
| 3827 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3829 | |
| 3830 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3831 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3832 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3833 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3834 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3835 | |
| 3836 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3837 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3838 | if (ElementType.isNull()) |
| 3839 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3840 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3841 | // Vector sizes are constant expressions. |
| 3842 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3843 | Sema::ConstantEvaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3844 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3845 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3846 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3847 | if (Size.isInvalid()) |
| 3848 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3850 | QualType Result = TL.getType(); |
| 3851 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3852 | ElementType != T->getElementType() || |
| 3853 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3854 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3855 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3856 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3857 | if (Result.isNull()) |
| 3858 | return QualType(); |
| 3859 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3860 | |
| 3861 | // Result might be dependent or not. |
| 3862 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3863 | DependentSizedExtVectorTypeLoc NewTL |
| 3864 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3865 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3866 | } else { |
| 3867 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3868 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3869 | } |
| 3870 | |
| 3871 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3872 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3873 | |
| 3874 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3875 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3876 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3877 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3878 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3879 | if (ElementType.isNull()) |
| 3880 | return QualType(); |
| 3881 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3882 | QualType Result = TL.getType(); |
| 3883 | if (getDerived().AlwaysRebuild() || |
| 3884 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3885 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3886 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3887 | if (Result.isNull()) |
| 3888 | return QualType(); |
| 3889 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3890 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3891 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3892 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3894 | return Result; |
| 3895 | } |
| 3896 | |
| 3897 | template<typename Derived> |
| 3898 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3899 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3900 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3901 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3902 | if (ElementType.isNull()) |
| 3903 | return QualType(); |
| 3904 | |
| 3905 | QualType Result = TL.getType(); |
| 3906 | if (getDerived().AlwaysRebuild() || |
| 3907 | ElementType != T->getElementType()) { |
| 3908 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3909 | T->getNumElements(), |
| 3910 | /*FIXME*/ SourceLocation()); |
| 3911 | if (Result.isNull()) |
| 3912 | return QualType(); |
| 3913 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3914 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3915 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3916 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3917 | |
| 3918 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3919 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3920 | |
| 3921 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3922 | ParmVarDecl * |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3923 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3924 | int indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 3925 | llvm::Optional<unsigned> NumExpansions, |
| 3926 | bool ExpectParameterPack) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3927 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3928 | TypeSourceInfo *NewDI = 0; |
| 3929 | |
| 3930 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3931 | // 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] | 3932 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3933 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3934 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3935 | |
| 3936 | TypeLocBuilder TLB; |
| 3937 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3938 | TLB.reserve(NewTL.getFullDataSize()); |
| 3939 | |
| 3940 | QualType Result = getDerived().TransformType(TLB, |
| 3941 | OldExpansionTL.getPatternLoc()); |
| 3942 | if (Result.isNull()) |
| 3943 | return 0; |
| 3944 | |
| 3945 | Result = RebuildPackExpansionType(Result, |
| 3946 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3947 | OldExpansionTL.getEllipsisLoc(), |
| 3948 | NumExpansions); |
| 3949 | if (Result.isNull()) |
| 3950 | return 0; |
| 3951 | |
| 3952 | PackExpansionTypeLoc NewExpansionTL |
| 3953 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3954 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3955 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3956 | } else |
| 3957 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3958 | if (!NewDI) |
| 3959 | return 0; |
| 3960 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3961 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3962 | return OldParm; |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3963 | |
| 3964 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 3965 | OldParm->getDeclContext(), |
| 3966 | OldParm->getInnerLocStart(), |
| 3967 | OldParm->getLocation(), |
| 3968 | OldParm->getIdentifier(), |
| 3969 | NewDI->getType(), |
| 3970 | NewDI, |
| 3971 | OldParm->getStorageClass(), |
| 3972 | OldParm->getStorageClassAsWritten(), |
| 3973 | /* DefArg */ NULL); |
| 3974 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 3975 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 3976 | return newParm; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | template<typename Derived> |
| 3980 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3981 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3982 | ParmVarDecl **Params, unsigned NumParams, |
| 3983 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3984 | SmallVectorImpl<QualType> &OutParamTypes, |
| 3985 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3986 | int indexAdjustment = 0; |
| 3987 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3988 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3989 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3990 | assert(OldParm->getFunctionScopeIndex() == i); |
| 3991 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3992 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3993 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3994 | if (OldParm->isParameterPack()) { |
| 3995 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3996 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3997 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3998 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3999 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 4000 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 4001 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4002 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4003 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4004 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4005 | // Determine whether we should expand the parameter packs. |
| 4006 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4007 | bool RetainExpansion = false; |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4008 | llvm::Optional<unsigned> OrigNumExpansions |
| 4009 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 4010 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4011 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4012 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 4013 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4014 | ShouldExpand, |
| 4015 | RetainExpansion, |
| 4016 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4017 | return true; |
| 4018 | } |
| 4019 | |
| 4020 | if (ShouldExpand) { |
| 4021 | // Expand the function parameter pack into multiple, separate |
| 4022 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4023 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4024 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4025 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4026 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4027 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4028 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4029 | OrigNumExpansions, |
| 4030 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4031 | if (!NewParm) |
| 4032 | return true; |
| 4033 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4034 | OutParamTypes.push_back(NewParm->getType()); |
| 4035 | if (PVars) |
| 4036 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4037 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4038 | |
| 4039 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4040 | // forgetting the partially-substituted parameter pack. |
| 4041 | if (RetainExpansion) { |
| 4042 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4043 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4044 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4045 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4046 | OrigNumExpansions, |
| 4047 | /*ExpectParameterPack=*/false); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4048 | if (!NewParm) |
| 4049 | return true; |
| 4050 | |
| 4051 | OutParamTypes.push_back(NewParm->getType()); |
| 4052 | if (PVars) |
| 4053 | PVars->push_back(NewParm); |
| 4054 | } |
| 4055 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4056 | // The next parameter should have the same adjustment as the |
| 4057 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4058 | // on every push. Also, if we push nothing, the adjustment should |
| 4059 | // go down by one. |
| 4060 | indexAdjustment--; |
| 4061 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4062 | // We're done with the pack expansion. |
| 4063 | continue; |
| 4064 | } |
| 4065 | |
| 4066 | // We'll substitute the parameter now without expanding the pack |
| 4067 | // expansion. |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4068 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4069 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4070 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4071 | NumExpansions, |
| 4072 | /*ExpectParameterPack=*/true); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4073 | } else { |
| 4074 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4075 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4076 | llvm::Optional<unsigned>(), |
| 4077 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4078 | } |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4079 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4080 | if (!NewParm) |
| 4081 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4082 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4083 | OutParamTypes.push_back(NewParm->getType()); |
| 4084 | if (PVars) |
| 4085 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4086 | continue; |
| 4087 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4088 | |
| 4089 | // Deal with the possibility that we don't have a parameter |
| 4090 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4091 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4092 | bool IsPackExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4093 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4094 | QualType NewType; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4095 | if (const PackExpansionType *Expansion |
| 4096 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4097 | // We have a function parameter pack that may need to be expanded. |
| 4098 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4099 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4100 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 4101 | |
| 4102 | // Determine whether we should expand the parameter packs. |
| 4103 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4104 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4105 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 4106 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4107 | ShouldExpand, |
| 4108 | RetainExpansion, |
| 4109 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4110 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4111 | } |
| 4112 | |
| 4113 | if (ShouldExpand) { |
| 4114 | // Expand the function parameter pack into multiple, separate |
| 4115 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4116 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4117 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4118 | QualType NewType = getDerived().TransformType(Pattern); |
| 4119 | if (NewType.isNull()) |
| 4120 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4121 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4122 | OutParamTypes.push_back(NewType); |
| 4123 | if (PVars) |
| 4124 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | // We're done with the pack expansion. |
| 4128 | continue; |
| 4129 | } |
| 4130 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4131 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4132 | // forgetting the partially-substituted parameter pack. |
| 4133 | if (RetainExpansion) { |
| 4134 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4135 | QualType NewType = getDerived().TransformType(Pattern); |
| 4136 | if (NewType.isNull()) |
| 4137 | return true; |
| 4138 | |
| 4139 | OutParamTypes.push_back(NewType); |
| 4140 | if (PVars) |
| 4141 | PVars->push_back(0); |
| 4142 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4143 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4144 | // We'll substitute the parameter now without expanding the pack |
| 4145 | // expansion. |
| 4146 | OldType = Expansion->getPattern(); |
| 4147 | IsPackExpansion = true; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4148 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4149 | NewType = getDerived().TransformType(OldType); |
| 4150 | } else { |
| 4151 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4152 | } |
| 4153 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4154 | if (NewType.isNull()) |
| 4155 | return true; |
| 4156 | |
| 4157 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4158 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4159 | NumExpansions); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4160 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4161 | OutParamTypes.push_back(NewType); |
| 4162 | if (PVars) |
| 4163 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4166 | #ifndef NDEBUG |
| 4167 | if (PVars) { |
| 4168 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4169 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4170 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4171 | } |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4172 | #endif |
| 4173 | |
| 4174 | return false; |
| 4175 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4176 | |
| 4177 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4178 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4179 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4180 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4181 | return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); |
| 4182 | } |
| 4183 | |
| 4184 | template<typename Derived> |
| 4185 | QualType |
| 4186 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4187 | FunctionProtoTypeLoc TL, |
| 4188 | CXXRecordDecl *ThisContext, |
| 4189 | unsigned ThisTypeQuals) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4190 | // Transform the parameters and return type. |
| 4191 | // |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4192 | // We are required to instantiate the params and return type in source order. |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4193 | // When the function has a trailing return type, we instantiate the |
| 4194 | // parameters before the return type, since the return type can then refer |
| 4195 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4196 | // |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4197 | SmallVector<QualType, 4> ParamTypes; |
| 4198 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4199 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4200 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4201 | QualType ResultType; |
| 4202 | |
| 4203 | if (TL.getTrailingReturn()) { |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4204 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 4205 | TL.getParmArray(), |
| 4206 | TL.getNumArgs(), |
| 4207 | TL.getTypePtr()->arg_type_begin(), |
| 4208 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4209 | return QualType(); |
| 4210 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4211 | { |
| 4212 | // C++11 [expr.prim.general]p3: |
| 4213 | // If a declaration declares a member function or member function |
| 4214 | // template of a class X, the expression this is a prvalue of type |
| 4215 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
| 4216 | // and the end of the function-definition, member-declarator, or |
| 4217 | // declarator. |
| 4218 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
| 4219 | |
| 4220 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4221 | if (ResultType.isNull()) |
| 4222 | return QualType(); |
| 4223 | } |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4224 | } |
| 4225 | else { |
| 4226 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4227 | if (ResultType.isNull()) |
| 4228 | return QualType(); |
| 4229 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4230 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 4231 | TL.getParmArray(), |
| 4232 | TL.getNumArgs(), |
| 4233 | TL.getTypePtr()->arg_type_begin(), |
| 4234 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4235 | return QualType(); |
| 4236 | } |
| 4237 | |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4238 | // FIXME: Need to transform the exception-specification too. |
| 4239 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4240 | QualType Result = TL.getType(); |
| 4241 | if (getDerived().AlwaysRebuild() || |
| 4242 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4243 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4244 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 4245 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 4246 | ParamTypes.data(), |
| 4247 | ParamTypes.size(), |
| 4248 | T->isVariadic(), |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 4249 | T->hasTrailingReturn(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4250 | T->getTypeQuals(), |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 4251 | T->getRefQualifier(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4252 | T->getExtInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4253 | if (Result.isNull()) |
| 4254 | return QualType(); |
| 4255 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4256 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4257 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4258 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 4259 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4260 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4261 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4262 | NewTL.setArg(i, ParamDecls[i]); |
| 4263 | |
| 4264 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4265 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4266 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4267 | template<typename Derived> |
| 4268 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4269 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4270 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4271 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4272 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4273 | if (ResultType.isNull()) |
| 4274 | return QualType(); |
| 4275 | |
| 4276 | QualType Result = TL.getType(); |
| 4277 | if (getDerived().AlwaysRebuild() || |
| 4278 | ResultType != T->getResultType()) |
| 4279 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4280 | |
| 4281 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4282 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 4283 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4284 | NewTL.setTrailingReturn(false); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4285 | |
| 4286 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4287 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4289 | template<typename Derived> QualType |
| 4290 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4291 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4292 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4293 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4294 | if (!D) |
| 4295 | return QualType(); |
| 4296 | |
| 4297 | QualType Result = TL.getType(); |
| 4298 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4299 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4300 | if (Result.isNull()) |
| 4301 | return QualType(); |
| 4302 | } |
| 4303 | |
| 4304 | // We might get an arbitrary type spec type back. We should at |
| 4305 | // least always get a type spec type, though. |
| 4306 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4307 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4308 | |
| 4309 | return Result; |
| 4310 | } |
| 4311 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4312 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4313 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4314 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4315 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4316 | TypedefNameDecl *Typedef |
| 4317 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4318 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4319 | if (!Typedef) |
| 4320 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4321 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4322 | QualType Result = TL.getType(); |
| 4323 | if (getDerived().AlwaysRebuild() || |
| 4324 | Typedef != T->getDecl()) { |
| 4325 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4326 | if (Result.isNull()) |
| 4327 | return QualType(); |
| 4328 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4329 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4330 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4331 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4332 | |
| 4333 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4334 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4336 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4337 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4338 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4339 | // typeof expressions are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4340 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4341 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4342 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4343 | if (E.isInvalid()) |
| 4344 | return QualType(); |
| 4345 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4346 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4347 | if (E.isInvalid()) |
| 4348 | return QualType(); |
| 4349 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4350 | QualType Result = TL.getType(); |
| 4351 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4352 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4353 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4354 | if (Result.isNull()) |
| 4355 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4356 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4357 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4359 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4360 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4361 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4362 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4363 | |
| 4364 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4365 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | |
| 4367 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4368 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4369 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4370 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4371 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4372 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4373 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4375 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4376 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4377 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4378 | if (Result.isNull()) |
| 4379 | return QualType(); |
| 4380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4381 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4382 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4383 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4384 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4385 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4386 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4387 | |
| 4388 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4389 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4390 | |
| 4391 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4392 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4393 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4394 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4395 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4396 | // decltype expressions are not potentially evaluated contexts |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4397 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, |
| 4398 | /*IsDecltype=*/ true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4400 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4401 | if (E.isInvalid()) |
| 4402 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4403 | |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4404 | E = getSema().ActOnDecltypeExpression(E.take()); |
| 4405 | if (E.isInvalid()) |
| 4406 | return QualType(); |
| 4407 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4408 | QualType Result = TL.getType(); |
| 4409 | if (getDerived().AlwaysRebuild() || |
| 4410 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4411 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4412 | if (Result.isNull()) |
| 4413 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4414 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4415 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4416 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4417 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4418 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4419 | |
| 4420 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4424 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4425 | TypeLocBuilder &TLB, |
| 4426 | UnaryTransformTypeLoc TL) { |
| 4427 | QualType Result = TL.getType(); |
| 4428 | if (Result->isDependentType()) { |
| 4429 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4430 | QualType NewBase = |
| 4431 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4432 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4433 | T->getUTTKind(), |
| 4434 | TL.getKWLoc()); |
| 4435 | if (Result.isNull()) |
| 4436 | return QualType(); |
| 4437 | } |
| 4438 | |
| 4439 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4440 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4441 | NewTL.setParensRange(TL.getParensRange()); |
| 4442 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4443 | return Result; |
| 4444 | } |
| 4445 | |
| 4446 | template<typename Derived> |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4447 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4448 | AutoTypeLoc TL) { |
| 4449 | const AutoType *T = TL.getTypePtr(); |
| 4450 | QualType OldDeduced = T->getDeducedType(); |
| 4451 | QualType NewDeduced; |
| 4452 | if (!OldDeduced.isNull()) { |
| 4453 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4454 | if (NewDeduced.isNull()) |
| 4455 | return QualType(); |
| 4456 | } |
| 4457 | |
| 4458 | QualType Result = TL.getType(); |
| 4459 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4460 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4461 | if (Result.isNull()) |
| 4462 | return QualType(); |
| 4463 | } |
| 4464 | |
| 4465 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4466 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4467 | |
| 4468 | return Result; |
| 4469 | } |
| 4470 | |
| 4471 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4472 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4473 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4474 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4475 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4476 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4477 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4478 | if (!Record) |
| 4479 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4480 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4481 | QualType Result = TL.getType(); |
| 4482 | if (getDerived().AlwaysRebuild() || |
| 4483 | Record != T->getDecl()) { |
| 4484 | Result = getDerived().RebuildRecordType(Record); |
| 4485 | if (Result.isNull()) |
| 4486 | return QualType(); |
| 4487 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4488 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4489 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4490 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4491 | |
| 4492 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | |
| 4495 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4496 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4497 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4498 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4499 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4500 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4501 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4502 | if (!Enum) |
| 4503 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4504 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4505 | QualType Result = TL.getType(); |
| 4506 | if (getDerived().AlwaysRebuild() || |
| 4507 | Enum != T->getDecl()) { |
| 4508 | Result = getDerived().RebuildEnumType(Enum); |
| 4509 | if (Result.isNull()) |
| 4510 | return QualType(); |
| 4511 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4512 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4513 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4514 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4515 | |
| 4516 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4517 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4518 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4519 | template<typename Derived> |
| 4520 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4521 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4522 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4523 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4524 | TL.getTypePtr()->getDecl()); |
| 4525 | if (!D) return QualType(); |
| 4526 | |
| 4527 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4528 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4529 | return T; |
| 4530 | } |
| 4531 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4532 | template<typename Derived> |
| 4533 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4534 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4535 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4536 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4537 | } |
| 4538 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4539 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4540 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4541 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4542 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4543 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| 4544 | |
| 4545 | // Substitute into the replacement type, which itself might involve something |
| 4546 | // that needs to be transformed. This only tends to occur with default |
| 4547 | // template arguments of template template parameters. |
| 4548 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4549 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4550 | if (Replacement.isNull()) |
| 4551 | return QualType(); |
| 4552 | |
| 4553 | // Always canonicalize the replacement type. |
| 4554 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4555 | QualType Result |
| 4556 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
| 4557 | Replacement); |
| 4558 | |
| 4559 | // Propagate type-source information. |
| 4560 | SubstTemplateTypeParmTypeLoc NewTL |
| 4561 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4562 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4563 | return Result; |
| 4564 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4565 | } |
| 4566 | |
| 4567 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4568 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4569 | TypeLocBuilder &TLB, |
| 4570 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4571 | return TransformTypeSpecType(TLB, TL); |
| 4572 | } |
| 4573 | |
| 4574 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4575 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4576 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4577 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4578 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4579 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4580 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4581 | // because we can't have a dependent nested-name-specifier anyway. |
| 4582 | CXXScopeSpec SS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4583 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4584 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4585 | TL.getTemplateNameLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4586 | if (Template.isNull()) |
| 4587 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4588 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4589 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4590 | } |
| 4591 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4592 | template<typename Derived> |
| 4593 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4594 | AtomicTypeLoc TL) { |
| 4595 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4596 | if (ValueType.isNull()) |
| 4597 | return QualType(); |
| 4598 | |
| 4599 | QualType Result = TL.getType(); |
| 4600 | if (getDerived().AlwaysRebuild() || |
| 4601 | ValueType != TL.getValueLoc().getType()) { |
| 4602 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4603 | if (Result.isNull()) |
| 4604 | return QualType(); |
| 4605 | } |
| 4606 | |
| 4607 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4608 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4609 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4610 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4611 | |
| 4612 | return Result; |
| 4613 | } |
| 4614 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4615 | namespace { |
| 4616 | /// \brief Simple iterator that traverses the template arguments in a |
| 4617 | /// container that provides a \c getArgLoc() member function. |
| 4618 | /// |
| 4619 | /// This iterator is intended to be used with the iterator form of |
| 4620 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4621 | template<typename ArgLocContainer> |
| 4622 | class TemplateArgumentLocContainerIterator { |
| 4623 | ArgLocContainer *Container; |
| 4624 | unsigned Index; |
| 4625 | |
| 4626 | public: |
| 4627 | typedef TemplateArgumentLoc value_type; |
| 4628 | typedef TemplateArgumentLoc reference; |
| 4629 | typedef int difference_type; |
| 4630 | typedef std::input_iterator_tag iterator_category; |
| 4631 | |
| 4632 | class pointer { |
| 4633 | TemplateArgumentLoc Arg; |
| 4634 | |
| 4635 | public: |
| 4636 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4637 | |
| 4638 | const TemplateArgumentLoc *operator->() const { |
| 4639 | return &Arg; |
| 4640 | } |
| 4641 | }; |
| 4642 | |
| 4643 | |
| 4644 | TemplateArgumentLocContainerIterator() {} |
| 4645 | |
| 4646 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4647 | unsigned Index) |
| 4648 | : Container(&Container), Index(Index) { } |
| 4649 | |
| 4650 | TemplateArgumentLocContainerIterator &operator++() { |
| 4651 | ++Index; |
| 4652 | return *this; |
| 4653 | } |
| 4654 | |
| 4655 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4656 | TemplateArgumentLocContainerIterator Old(*this); |
| 4657 | ++(*this); |
| 4658 | return Old; |
| 4659 | } |
| 4660 | |
| 4661 | TemplateArgumentLoc operator*() const { |
| 4662 | return Container->getArgLoc(Index); |
| 4663 | } |
| 4664 | |
| 4665 | pointer operator->() const { |
| 4666 | return pointer(Container->getArgLoc(Index)); |
| 4667 | } |
| 4668 | |
| 4669 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4670 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4671 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4672 | } |
| 4673 | |
| 4674 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4675 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4676 | return !(X == Y); |
| 4677 | } |
| 4678 | }; |
| 4679 | } |
| 4680 | |
| 4681 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4682 | template <typename Derived> |
| 4683 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4684 | TypeLocBuilder &TLB, |
| 4685 | TemplateSpecializationTypeLoc TL, |
| 4686 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4687 | TemplateArgumentListInfo NewTemplateArgs; |
| 4688 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4689 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4690 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4691 | ArgIterator; |
| 4692 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4693 | ArgIterator(TL, TL.getNumArgs()), |
| 4694 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4695 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4697 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4698 | |
| 4699 | QualType Result = |
| 4700 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4701 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4702 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4703 | |
| 4704 | if (!Result.isNull()) { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4705 | // Specializations of template template parameters are represented as |
| 4706 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4707 | // within a dependent context can transform them into |
| 4708 | // DependentTemplateSpecializationTypes. |
| 4709 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4710 | DependentTemplateSpecializationTypeLoc NewTL |
| 4711 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4712 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4713 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4714 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4715 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4716 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4717 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4718 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4719 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4720 | return Result; |
| 4721 | } |
| 4722 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4723 | TemplateSpecializationTypeLoc NewTL |
| 4724 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4725 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4726 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4727 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4728 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4729 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4730 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4731 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4732 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4733 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4736 | template <typename Derived> |
| 4737 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4738 | TypeLocBuilder &TLB, |
| 4739 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4740 | TemplateName Template, |
| 4741 | CXXScopeSpec &SS) { |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4742 | TemplateArgumentListInfo NewTemplateArgs; |
| 4743 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4744 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4745 | typedef TemplateArgumentLocContainerIterator< |
| 4746 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4747 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4748 | ArgIterator(TL, TL.getNumArgs()), |
| 4749 | NewTemplateArgs)) |
| 4750 | return QualType(); |
| 4751 | |
| 4752 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4753 | |
| 4754 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4755 | QualType Result |
| 4756 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4757 | TL.getTypePtr()->getKeyword(), |
| 4758 | DTN->getQualifier(), |
| 4759 | DTN->getIdentifier(), |
| 4760 | NewTemplateArgs); |
| 4761 | |
| 4762 | DependentTemplateSpecializationTypeLoc NewTL |
| 4763 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4764 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4765 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4766 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4767 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4768 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4769 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4770 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4771 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4772 | return Result; |
| 4773 | } |
| 4774 | |
| 4775 | QualType Result |
| 4776 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4777 | TL.getTemplateNameLoc(), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4778 | NewTemplateArgs); |
| 4779 | |
| 4780 | if (!Result.isNull()) { |
| 4781 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4782 | TemplateSpecializationTypeLoc NewTL |
| 4783 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4784 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4785 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4786 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4787 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4788 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4789 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4790 | } |
| 4791 | |
| 4792 | return Result; |
| 4793 | } |
| 4794 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4795 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4796 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4797 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4798 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4799 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4800 | |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4801 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4802 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4803 | if (TL.getQualifierLoc()) { |
| 4804 | QualifierLoc |
| 4805 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4806 | if (!QualifierLoc) |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4807 | return QualType(); |
| 4808 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4809 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4810 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4811 | if (NamedT.isNull()) |
| 4812 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4813 | |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4814 | // C++0x [dcl.type.elab]p2: |
| 4815 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4816 | // resolves to an alias template specialization, the |
| 4817 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 1804174 | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 4818 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 4819 | if (const TemplateSpecializationType *TST = |
| 4820 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4821 | TemplateName Template = TST->getTemplateName(); |
| 4822 | if (TypeAliasTemplateDecl *TAT = |
| 4823 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4824 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4825 | diag::err_tag_reference_non_tag) << 4; |
| 4826 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4827 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4828 | } |
| 4829 | } |
| 4830 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4831 | QualType Result = TL.getType(); |
| 4832 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4833 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4834 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4835 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4836 | T->getKeyword(), |
| 4837 | QualifierLoc, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4838 | if (Result.isNull()) |
| 4839 | return QualType(); |
| 4840 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4841 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4842 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4843 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4844 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4845 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4846 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4847 | |
| 4848 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4849 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4850 | TypeLocBuilder &TLB, |
| 4851 | AttributedTypeLoc TL) { |
| 4852 | const AttributedType *oldType = TL.getTypePtr(); |
| 4853 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4854 | if (modifiedType.isNull()) |
| 4855 | return QualType(); |
| 4856 | |
| 4857 | QualType result = TL.getType(); |
| 4858 | |
| 4859 | // FIXME: dependent operand expressions? |
| 4860 | if (getDerived().AlwaysRebuild() || |
| 4861 | modifiedType != oldType->getModifiedType()) { |
| 4862 | // TODO: this is really lame; we should really be rebuilding the |
| 4863 | // equivalent type from first principles. |
| 4864 | QualType equivalentType |
| 4865 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4866 | if (equivalentType.isNull()) |
| 4867 | return QualType(); |
| 4868 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4869 | modifiedType, |
| 4870 | equivalentType); |
| 4871 | } |
| 4872 | |
| 4873 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4874 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4875 | if (TL.hasAttrOperand()) |
| 4876 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4877 | if (TL.hasAttrExprOperand()) |
| 4878 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4879 | else if (TL.hasAttrEnumOperand()) |
| 4880 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4881 | |
| 4882 | return result; |
| 4883 | } |
| 4884 | |
| 4885 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4886 | QualType |
| 4887 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4888 | ParenTypeLoc TL) { |
| 4889 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4890 | if (Inner.isNull()) |
| 4891 | return QualType(); |
| 4892 | |
| 4893 | QualType Result = TL.getType(); |
| 4894 | if (getDerived().AlwaysRebuild() || |
| 4895 | Inner != TL.getInnerLoc().getType()) { |
| 4896 | Result = getDerived().RebuildParenType(Inner); |
| 4897 | if (Result.isNull()) |
| 4898 | return QualType(); |
| 4899 | } |
| 4900 | |
| 4901 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4902 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4903 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4904 | return Result; |
| 4905 | } |
| 4906 | |
| 4907 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4908 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4909 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4910 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4911 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4912 | NestedNameSpecifierLoc QualifierLoc |
| 4913 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4914 | if (!QualifierLoc) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4915 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4916 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4917 | QualType Result |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4918 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4919 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4920 | QualifierLoc, |
| 4921 | T->getIdentifier(), |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4922 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4923 | if (Result.isNull()) |
| 4924 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4925 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4926 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4927 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4928 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4929 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4930 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4931 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4932 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4933 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4934 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4935 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4936 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4937 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4938 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4939 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4940 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4941 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4942 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4943 | QualType TreeTransform<Derived>:: |
| 4944 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4945 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4946 | NestedNameSpecifierLoc QualifierLoc; |
| 4947 | if (TL.getQualifierLoc()) { |
| 4948 | QualifierLoc |
| 4949 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4950 | if (!QualifierLoc) |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4951 | return QualType(); |
| 4952 | } |
| 4953 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4954 | return getDerived() |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4955 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4956 | } |
| 4957 | |
| 4958 | template<typename Derived> |
| 4959 | QualType TreeTransform<Derived>:: |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4960 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4961 | DependentTemplateSpecializationTypeLoc TL, |
| 4962 | NestedNameSpecifierLoc QualifierLoc) { |
| 4963 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 4964 | |
| 4965 | TemplateArgumentListInfo NewTemplateArgs; |
| 4966 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4967 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4968 | |
| 4969 | typedef TemplateArgumentLocContainerIterator< |
| 4970 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4971 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4972 | ArgIterator(TL, TL.getNumArgs()), |
| 4973 | NewTemplateArgs)) |
| 4974 | return QualType(); |
| 4975 | |
| 4976 | QualType Result |
| 4977 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4978 | QualifierLoc, |
| 4979 | T->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4980 | TL.getTemplateNameLoc(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4981 | NewTemplateArgs); |
| 4982 | if (Result.isNull()) |
| 4983 | return QualType(); |
| 4984 | |
| 4985 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4986 | QualType NamedT = ElabT->getNamedType(); |
| 4987 | |
| 4988 | // Copy information relevant to the template specialization. |
| 4989 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4990 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4991 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4992 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4993 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4994 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4995 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4996 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4997 | |
| 4998 | // Copy information relevant to the elaborated type. |
| 4999 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5000 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5001 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5002 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5003 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5004 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5005 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5006 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5007 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5008 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5009 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5010 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5011 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5012 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5013 | } else { |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5014 | TemplateSpecializationTypeLoc SpecTL |
| 5015 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5016 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5017 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5018 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5019 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5020 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5021 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5022 | } |
| 5023 | return Result; |
| 5024 | } |
| 5025 | |
| 5026 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5027 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5028 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5029 | QualType Pattern |
| 5030 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 5031 | if (Pattern.isNull()) |
| 5032 | return QualType(); |
| 5033 | |
| 5034 | QualType Result = TL.getType(); |
| 5035 | if (getDerived().AlwaysRebuild() || |
| 5036 | Pattern != TL.getPatternLoc().getType()) { |
| 5037 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 5038 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5039 | TL.getEllipsisLoc(), |
| 5040 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5041 | if (Result.isNull()) |
| 5042 | return QualType(); |
| 5043 | } |
| 5044 | |
| 5045 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5046 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5047 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5051 | QualType |
| 5052 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5053 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5054 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5055 | TLB.pushFullCopy(TL); |
| 5056 | return TL.getType(); |
| 5057 | } |
| 5058 | |
| 5059 | template<typename Derived> |
| 5060 | QualType |
| 5061 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5062 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5063 | // ObjCObjectType is never dependent. |
| 5064 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5065 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5066 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5067 | |
| 5068 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5069 | QualType |
| 5070 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5071 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5072 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5073 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5074 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5075 | } |
| 5076 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5077 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5078 | // Statement transformation |
| 5079 | //===----------------------------------------------------------------------===// |
| 5080 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5081 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5082 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5083 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5087 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5088 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5089 | return getDerived().TransformCompoundStmt(S, false); |
| 5090 | } |
| 5091 | |
| 5092 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5093 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5094 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5095 | bool IsStmtExpr) { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5096 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5097 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5098 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5099 | bool SubStmtChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5100 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5101 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 5102 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5103 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5104 | if (Result.isInvalid()) { |
| 5105 | // Immediately fail if this was a DeclStmt, since it's very |
| 5106 | // likely that this will cause problems for future statements. |
| 5107 | if (isa<DeclStmt>(*B)) |
| 5108 | return StmtError(); |
| 5109 | |
| 5110 | // Otherwise, just keep processing substatements and fail later. |
| 5111 | SubStmtInvalid = true; |
| 5112 | continue; |
| 5113 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5115 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 5116 | Statements.push_back(Result.takeAs<Stmt>()); |
| 5117 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5118 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5119 | if (SubStmtInvalid) |
| 5120 | return StmtError(); |
| 5121 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5122 | if (!getDerived().AlwaysRebuild() && |
| 5123 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5124 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5125 | |
| 5126 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 5127 | move_arg(Statements), |
| 5128 | S->getRBracLoc(), |
| 5129 | IsStmtExpr); |
| 5130 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5131 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5132 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5133 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5135 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5136 | { |
Eli Friedman | 6b3014b | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5137 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5138 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5139 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5140 | // Transform the left-hand case value. |
| 5141 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5142 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5143 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5144 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5145 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5146 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5147 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5148 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5149 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5150 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5151 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5152 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5153 | // Build the case statement. |
| 5154 | // Case statements are always rebuilt so that they will attached to their |
| 5155 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5156 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5157 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5158 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5159 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5160 | S->getColonLoc()); |
| 5161 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5162 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5163 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5164 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5165 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5166 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5167 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5168 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5169 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5170 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5174 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5176 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5177 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5178 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5179 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5180 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5181 | // Default statements are always rebuilt |
| 5182 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5183 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5185 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5186 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5187 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5188 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5189 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5190 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5191 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5192 | |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5193 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5194 | S->getDecl()); |
| 5195 | if (!LD) |
| 5196 | return StmtError(); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5197 | |
| 5198 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5199 | // FIXME: Pass the real colon location in. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5200 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5201 | cast<LabelDecl>(LD), SourceLocation(), |
| 5202 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5203 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5204 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5205 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5206 | StmtResult |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5207 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5208 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5209 | if (SubStmt.isInvalid()) |
| 5210 | return StmtError(); |
| 5211 | |
| 5212 | // TODO: transform attributes |
| 5213 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5214 | return S; |
| 5215 | |
| 5216 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5217 | S->getAttrs(), |
| 5218 | SubStmt.get()); |
| 5219 | } |
| 5220 | |
| 5221 | template<typename Derived> |
| 5222 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5223 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5224 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5225 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5226 | VarDecl *ConditionVar = 0; |
| 5227 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5228 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5229 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5230 | getDerived().TransformDefinition( |
| 5231 | S->getConditionVariable()->getLocation(), |
| 5232 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5233 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5234 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5235 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5236 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5237 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5238 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5239 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5240 | |
| 5241 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5242 | if (S->getCond()) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5243 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 5244 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5245 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5246 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5247 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5248 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5249 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5250 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5251 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5252 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5253 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5254 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5255 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5256 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5257 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5258 | if (Then.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5259 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5260 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5261 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5262 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5263 | if (Else.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 | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5266 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5267 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5268 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5269 | Then.get() == S->getThen() && |
| 5270 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5271 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5272 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5273 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5274 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5275 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5279 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5280 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5281 | // Transform the condition. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5282 | ExprResult Cond; |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5283 | VarDecl *ConditionVar = 0; |
| 5284 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5285 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5286 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5287 | getDerived().TransformDefinition( |
| 5288 | S->getConditionVariable()->getLocation(), |
| 5289 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5290 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5291 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5292 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5293 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5294 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5295 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5296 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5297 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5298 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5299 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5300 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5301 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5302 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5303 | if (Switch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5304 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5306 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5307 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5308 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5309 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5310 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5311 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5312 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5313 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5315 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5316 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5317 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5318 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5319 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5320 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5321 | VarDecl *ConditionVar = 0; |
| 5322 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5323 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5324 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5325 | getDerived().TransformDefinition( |
| 5326 | S->getConditionVariable()->getLocation(), |
| 5327 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5328 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5329 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5330 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5331 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5332 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5333 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5334 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5335 | |
| 5336 | if (S->getCond()) { |
| 5337 | // Convert the condition to a boolean value. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5338 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 5339 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5340 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5341 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5342 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5343 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5344 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5345 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5346 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5347 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5348 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5349 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5350 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5351 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5352 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5353 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5354 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5355 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5356 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5357 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5358 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5359 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5360 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5361 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5362 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5363 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5365 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5366 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5367 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5368 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5369 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5370 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5371 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5372 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5373 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5374 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5375 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5376 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5377 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5378 | if (!getDerived().AlwaysRebuild() && |
| 5379 | Cond.get() == S->getCond() && |
| 5380 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5381 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5382 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5383 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5384 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5385 | S->getRParenLoc()); |
| 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>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5391 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5392 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5393 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5394 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5395 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5396 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5397 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5398 | VarDecl *ConditionVar = 0; |
| 5399 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5400 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5401 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5402 | getDerived().TransformDefinition( |
| 5403 | S->getConditionVariable()->getLocation(), |
| 5404 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5405 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5406 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5407 | } else { |
| 5408 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5409 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5410 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5411 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5412 | |
| 5413 | if (S->getCond()) { |
| 5414 | // Convert the condition to a boolean value. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5415 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 5416 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5417 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5418 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5419 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5420 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5421 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5422 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5423 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5424 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5425 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5426 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5427 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5428 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5429 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5430 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5431 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5432 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5433 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 5434 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5435 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5436 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5437 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5438 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5439 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5440 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5441 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5442 | if (!getDerived().AlwaysRebuild() && |
| 5443 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5444 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5445 | Inc.get() == S->getInc() && |
| 5446 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5447 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5448 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5449 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5450 | Init.get(), FullCond, ConditionVar, |
| 5451 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5455 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5457 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5458 | S->getLabel()); |
| 5459 | if (!LD) |
| 5460 | return StmtError(); |
| 5461 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5462 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5463 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5464 | cast<LabelDecl>(LD)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5468 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5469 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5470 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5471 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5472 | return StmtError(); |
Eli Friedman | d29975f | 2012-01-31 22:47:07 +0000 | [diff] [blame] | 5473 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5474 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5475 | if (!getDerived().AlwaysRebuild() && |
| 5476 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5477 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5478 | |
| 5479 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5480 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5484 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5485 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5486 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5487 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5488 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5489 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5490 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5491 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5492 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5494 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5495 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5496 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5497 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5498 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5499 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5500 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5501 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5502 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5503 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5504 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5505 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5507 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5508 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5509 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5510 | bool DeclChanged = false; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5511 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5512 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5513 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5514 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5515 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5516 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5517 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5518 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5519 | if (Transformed != *D) |
| 5520 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5521 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5522 | Decls.push_back(Transformed); |
| 5523 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5524 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5525 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5526 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5527 | |
| 5528 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5529 | S->getStartLoc(), S->getEndLoc()); |
| 5530 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5531 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5532 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5533 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5534 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5535 | |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5536 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 5537 | ASTOwningVector<Expr*> Exprs(getSema()); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5538 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5539 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5540 | ExprResult AsmString; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5541 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5542 | |
| 5543 | bool ExprsChanged = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5544 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5545 | // Go through the outputs. |
| 5546 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5547 | Names.push_back(S->getOutputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5548 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5549 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5550 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5551 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5552 | // Transform the output expr. |
| 5553 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5554 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5555 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5556 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5557 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5558 | ExprsChanged |= Result.get() != OutputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5559 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5560 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5561 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5562 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5563 | // Go through the inputs. |
| 5564 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5565 | Names.push_back(S->getInputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5566 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5567 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5568 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5569 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5570 | // Transform the input expr. |
| 5571 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5572 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5573 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5574 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5575 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5576 | ExprsChanged |= Result.get() != InputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5577 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5578 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5579 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5580 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5581 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5582 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5583 | |
| 5584 | // Go through the clobbers. |
| 5585 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5586 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5587 | |
| 5588 | // No need to transform the asm string literal. |
| 5589 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 5590 | |
| 5591 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 5592 | S->isSimple(), |
| 5593 | S->isVolatile(), |
| 5594 | S->getNumOutputs(), |
| 5595 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5596 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5597 | move_arg(Constraints), |
| 5598 | move_arg(Exprs), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5599 | AsmString.get(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5600 | move_arg(Clobbers), |
| 5601 | S->getRParenLoc(), |
| 5602 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5603 | } |
| 5604 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5605 | template<typename Derived> |
| 5606 | StmtResult |
| 5607 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
| 5608 | // No need to transform the asm string literal. |
| 5609 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), |
| 5610 | *S->getAsmString(), |
| 5611 | S->getEndLoc()); |
| 5612 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5613 | |
| 5614 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5615 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5617 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5618 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5619 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5620 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5621 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5622 | // Transform the @catch statements (if present). |
| 5623 | bool AnyCatchChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5624 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5625 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5626 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5627 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5628 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5629 | if (Catch.get() != S->getCatchStmt(I)) |
| 5630 | AnyCatchChanged = true; |
| 5631 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5632 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5633 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5634 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5635 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5636 | if (S->getFinallyStmt()) { |
| 5637 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5638 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5639 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | // If nothing changed, just retain this statement. |
| 5643 | if (!getDerived().AlwaysRebuild() && |
| 5644 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5645 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5646 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5647 | return SemaRef.Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5648 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5649 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5650 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 5651 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5652 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5653 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5654 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5655 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5656 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5657 | // Transform the @catch parameter, if there is one. |
| 5658 | VarDecl *Var = 0; |
| 5659 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5660 | TypeSourceInfo *TSInfo = 0; |
| 5661 | if (FromVar->getTypeSourceInfo()) { |
| 5662 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5663 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5664 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5665 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5666 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5667 | QualType T; |
| 5668 | if (TSInfo) |
| 5669 | T = TSInfo->getType(); |
| 5670 | else { |
| 5671 | T = getDerived().TransformType(FromVar->getType()); |
| 5672 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5673 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5674 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5675 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5676 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5677 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5678 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5679 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5680 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5681 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5682 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5683 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5684 | |
| 5685 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5686 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5687 | Var, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5690 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5691 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5692 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5693 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5694 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5695 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5696 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5697 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5698 | // If nothing changed, just retain this statement. |
| 5699 | if (!getDerived().AlwaysRebuild() && |
| 5700 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5701 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5702 | |
| 5703 | // Build a new statement. |
| 5704 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5705 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5706 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5707 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5708 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5709 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5710 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5711 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5712 | if (S->getThrowExpr()) { |
| 5713 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5714 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5715 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5716 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5717 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5718 | if (!getDerived().AlwaysRebuild() && |
| 5719 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5720 | return getSema().Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5721 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5722 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5723 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5724 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5725 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5726 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5727 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5728 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5729 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5730 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5731 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5732 | return StmtError(); |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5733 | Object = |
| 5734 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5735 | Object.get()); |
| 5736 | if (Object.isInvalid()) |
| 5737 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5738 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5739 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5740 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5741 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5742 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5743 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5744 | // If nothing change, just retain the current statement. |
| 5745 | if (!getDerived().AlwaysRebuild() && |
| 5746 | Object.get() == S->getSynchExpr() && |
| 5747 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5748 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5749 | |
| 5750 | // Build a new statement. |
| 5751 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5752 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5756 | StmtResult |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5757 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5758 | ObjCAutoreleasePoolStmt *S) { |
| 5759 | // Transform the body. |
| 5760 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5761 | if (Body.isInvalid()) |
| 5762 | return StmtError(); |
| 5763 | |
| 5764 | // If nothing changed, just retain this statement. |
| 5765 | if (!getDerived().AlwaysRebuild() && |
| 5766 | Body.get() == S->getSubStmt()) |
| 5767 | return SemaRef.Owned(S); |
| 5768 | |
| 5769 | // Build a new statement. |
| 5770 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5771 | S->getAtLoc(), Body.get()); |
| 5772 | } |
| 5773 | |
| 5774 | template<typename Derived> |
| 5775 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5776 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5777 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5778 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5779 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5780 | if (Element.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5781 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5782 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5783 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5784 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5785 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5786 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5787 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5788 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5789 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5790 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5791 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5792 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5793 | // If nothing changed, just retain this statement. |
| 5794 | if (!getDerived().AlwaysRebuild() && |
| 5795 | Element.get() == S->getElement() && |
| 5796 | Collection.get() == S->getCollection() && |
| 5797 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5798 | return SemaRef.Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5799 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5800 | // Build a new statement. |
| 5801 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5802 | /*FIXME:*/S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5803 | Element.get(), |
| 5804 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5805 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5806 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5807 | } |
| 5808 | |
| 5809 | |
| 5810 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5811 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5812 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5813 | // Transform the exception declaration, if any. |
| 5814 | VarDecl *Var = 0; |
| 5815 | if (S->getExceptionDecl()) { |
| 5816 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5817 | TypeSourceInfo *T = getDerived().TransformType( |
| 5818 | ExceptionDecl->getTypeSourceInfo()); |
| 5819 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5820 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5821 | |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5822 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 5823 | ExceptionDecl->getInnerLocStart(), |
| 5824 | ExceptionDecl->getLocation(), |
| 5825 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5826 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5827 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5829 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5830 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5831 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5832 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5833 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5834 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5835 | if (!getDerived().AlwaysRebuild() && |
| 5836 | !Var && |
| 5837 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5838 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5839 | |
| 5840 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5841 | Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5842 | Handler.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5843 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5844 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5845 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5846 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5847 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5848 | // Transform the try block itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5849 | StmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5850 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5851 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5852 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5853 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5854 | // Transform the handlers. |
| 5855 | bool HandlerChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5856 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5857 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5858 | StmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5859 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5860 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5861 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5862 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5863 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5864 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5865 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5866 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5867 | if (!getDerived().AlwaysRebuild() && |
| 5868 | TryBlock.get() == S->getTryBlock() && |
| 5869 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5870 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5871 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5872 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5873 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5874 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5875 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5876 | template<typename Derived> |
| 5877 | StmtResult |
| 5878 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5879 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 5880 | if (Range.isInvalid()) |
| 5881 | return StmtError(); |
| 5882 | |
| 5883 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 5884 | if (BeginEnd.isInvalid()) |
| 5885 | return StmtError(); |
| 5886 | |
| 5887 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 5888 | if (Cond.isInvalid()) |
| 5889 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 5890 | if (Cond.get()) |
| 5891 | Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); |
| 5892 | if (Cond.isInvalid()) |
| 5893 | return StmtError(); |
| 5894 | if (Cond.get()) |
| 5895 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5896 | |
| 5897 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 5898 | if (Inc.isInvalid()) |
| 5899 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 5900 | if (Inc.get()) |
| 5901 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5902 | |
| 5903 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 5904 | if (LoopVar.isInvalid()) |
| 5905 | return StmtError(); |
| 5906 | |
| 5907 | StmtResult NewStmt = S; |
| 5908 | if (getDerived().AlwaysRebuild() || |
| 5909 | Range.get() != S->getRangeStmt() || |
| 5910 | BeginEnd.get() != S->getBeginEndStmt() || |
| 5911 | Cond.get() != S->getCond() || |
| 5912 | Inc.get() != S->getInc() || |
| 5913 | LoopVar.get() != S->getLoopVarStmt()) |
| 5914 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5915 | S->getColonLoc(), Range.get(), |
| 5916 | BeginEnd.get(), Cond.get(), |
| 5917 | Inc.get(), LoopVar.get(), |
| 5918 | S->getRParenLoc()); |
| 5919 | |
| 5920 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 5921 | if (Body.isInvalid()) |
| 5922 | return StmtError(); |
| 5923 | |
| 5924 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 5925 | // it now so we have a new statement to attach the body to. |
| 5926 | if (Body.get() != S->getBody() && NewStmt.get() == S) |
| 5927 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5928 | S->getColonLoc(), Range.get(), |
| 5929 | BeginEnd.get(), Cond.get(), |
| 5930 | Inc.get(), LoopVar.get(), |
| 5931 | S->getRParenLoc()); |
| 5932 | |
| 5933 | if (NewStmt.get() == S) |
| 5934 | return SemaRef.Owned(S); |
| 5935 | |
| 5936 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 5937 | } |
| 5938 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 5939 | template<typename Derived> |
| 5940 | StmtResult |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5941 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 5942 | MSDependentExistsStmt *S) { |
| 5943 | // Transform the nested-name-specifier, if any. |
| 5944 | NestedNameSpecifierLoc QualifierLoc; |
| 5945 | if (S->getQualifierLoc()) { |
| 5946 | QualifierLoc |
| 5947 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 5948 | if (!QualifierLoc) |
| 5949 | return StmtError(); |
| 5950 | } |
| 5951 | |
| 5952 | // Transform the declaration name. |
| 5953 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 5954 | if (NameInfo.getName()) { |
| 5955 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5956 | if (!NameInfo.getName()) |
| 5957 | return StmtError(); |
| 5958 | } |
| 5959 | |
| 5960 | // Check whether anything changed. |
| 5961 | if (!getDerived().AlwaysRebuild() && |
| 5962 | QualifierLoc == S->getQualifierLoc() && |
| 5963 | NameInfo.getName() == S->getNameInfo().getName()) |
| 5964 | return S; |
| 5965 | |
| 5966 | // Determine whether this name exists, if we can. |
| 5967 | CXXScopeSpec SS; |
| 5968 | SS.Adopt(QualifierLoc); |
| 5969 | bool Dependent = false; |
| 5970 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { |
| 5971 | case Sema::IER_Exists: |
| 5972 | if (S->isIfExists()) |
| 5973 | break; |
| 5974 | |
| 5975 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 5976 | |
| 5977 | case Sema::IER_DoesNotExist: |
| 5978 | if (S->isIfNotExists()) |
| 5979 | break; |
| 5980 | |
| 5981 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 5982 | |
| 5983 | case Sema::IER_Dependent: |
| 5984 | Dependent = true; |
| 5985 | break; |
Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 5986 | |
| 5987 | case Sema::IER_Error: |
| 5988 | return StmtError(); |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
| 5991 | // We need to continue with the instantiation, so do so now. |
| 5992 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 5993 | if (SubStmt.isInvalid()) |
| 5994 | return StmtError(); |
| 5995 | |
| 5996 | // If we have resolved the name, just transform to the substatement. |
| 5997 | if (!Dependent) |
| 5998 | return SubStmt; |
| 5999 | |
| 6000 | // The name is still dependent, so build a dependent expression again. |
| 6001 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6002 | S->isIfExists(), |
| 6003 | QualifierLoc, |
| 6004 | NameInfo, |
| 6005 | SubStmt.get()); |
| 6006 | } |
| 6007 | |
| 6008 | template<typename Derived> |
| 6009 | StmtResult |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6010 | TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 6011 | StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 6012 | if(TryBlock.isInvalid()) return StmtError(); |
| 6013 | |
| 6014 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 6015 | if(!getDerived().AlwaysRebuild() && |
| 6016 | TryBlock.get() == S->getTryBlock() && |
| 6017 | Handler.get() == S->getHandler()) |
| 6018 | return SemaRef.Owned(S); |
| 6019 | |
| 6020 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), |
| 6021 | S->getTryLoc(), |
| 6022 | TryBlock.take(), |
| 6023 | Handler.take()); |
| 6024 | } |
| 6025 | |
| 6026 | template<typename Derived> |
| 6027 | StmtResult |
| 6028 | TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 6029 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 6030 | if(Block.isInvalid()) return StmtError(); |
| 6031 | |
| 6032 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), |
| 6033 | Block.take()); |
| 6034 | } |
| 6035 | |
| 6036 | template<typename Derived> |
| 6037 | StmtResult |
| 6038 | TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 6039 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 6040 | if(FilterExpr.isInvalid()) return StmtError(); |
| 6041 | |
| 6042 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 6043 | if(Block.isInvalid()) return StmtError(); |
| 6044 | |
| 6045 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), |
| 6046 | FilterExpr.take(), |
| 6047 | Block.take()); |
| 6048 | } |
| 6049 | |
| 6050 | template<typename Derived> |
| 6051 | StmtResult |
| 6052 | TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6053 | if(isa<SEHFinallyStmt>(Handler)) |
| 6054 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6055 | else |
| 6056 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6057 | } |
| 6058 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6059 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6060 | // Expression transformation |
| 6061 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6062 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6063 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6064 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6065 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6066 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6067 | |
| 6068 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6069 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6070 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6071 | NestedNameSpecifierLoc QualifierLoc; |
| 6072 | if (E->getQualifierLoc()) { |
| 6073 | QualifierLoc |
| 6074 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6075 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6076 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6077 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6078 | |
| 6079 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6080 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6081 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6082 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6083 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6084 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6085 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6086 | if (NameInfo.getName()) { |
| 6087 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6088 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6089 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6090 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6091 | |
| 6092 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6093 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6094 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6095 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6096 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6097 | |
| 6098 | // Mark it referenced in the new context regardless. |
| 6099 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6100 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6101 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6102 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6103 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6104 | |
| 6105 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6106 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6107 | TemplateArgs = &TransArgs; |
| 6108 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6109 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6110 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6111 | E->getNumTemplateArgs(), |
| 6112 | TransArgs)) |
| 6113 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6114 | } |
| 6115 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6116 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 6117 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6118 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6119 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6120 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6121 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6122 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6123 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6124 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6125 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6126 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6127 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6128 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6129 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6130 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6131 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6132 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6133 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6134 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6135 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6137 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6138 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6139 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6140 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6141 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6143 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6144 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6145 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6146 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6147 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6151 | ExprResult |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6152 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
| 6153 | return SemaRef.MaybeBindToTemporary(E); |
| 6154 | } |
| 6155 | |
| 6156 | template<typename Derived> |
| 6157 | ExprResult |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6158 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6159 | ExprResult ControllingExpr = |
| 6160 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6161 | if (ControllingExpr.isInvalid()) |
| 6162 | return ExprError(); |
| 6163 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6164 | SmallVector<Expr *, 4> AssocExprs; |
| 6165 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6166 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6167 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6168 | if (TS) { |
| 6169 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6170 | if (!AssocType) |
| 6171 | return ExprError(); |
| 6172 | AssocTypes.push_back(AssocType); |
| 6173 | } else { |
| 6174 | AssocTypes.push_back(0); |
| 6175 | } |
| 6176 | |
| 6177 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6178 | if (AssocExpr.isInvalid()) |
| 6179 | return ExprError(); |
| 6180 | AssocExprs.push_back(AssocExpr.release()); |
| 6181 | } |
| 6182 | |
| 6183 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6184 | E->getDefaultLoc(), |
| 6185 | E->getRParenLoc(), |
| 6186 | ControllingExpr.release(), |
| 6187 | AssocTypes.data(), |
| 6188 | AssocExprs.data(), |
| 6189 | E->getNumAssocs()); |
| 6190 | } |
| 6191 | |
| 6192 | template<typename Derived> |
| 6193 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6194 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6195 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6196 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6197 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6198 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6199 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6200 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6201 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6202 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6203 | E->getRParen()); |
| 6204 | } |
| 6205 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6206 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6207 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6208 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6209 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6210 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6211 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6212 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6213 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6214 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6215 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6216 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 6217 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6218 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6219 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6222 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6223 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 6224 | // Transform the type. |
| 6225 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6226 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6227 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6228 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6229 | // Transform all of the components into components similar to what the |
| 6230 | // parser uses. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6231 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 6232 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 6233 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6234 | // template code that we don't care. |
| 6235 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6236 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6237 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6238 | SmallVector<Component, 4> Components; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6239 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 6240 | const Node &ON = E->getComponent(I); |
| 6241 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 6242 | Comp.isBrackets = true; |
Abramo Bagnara | 06dec89 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 6243 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 6244 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6245 | switch (ON.getKind()) { |
| 6246 | case Node::Array: { |
| 6247 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6248 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6249 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6250 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6251 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6252 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 6253 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6254 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6255 | break; |
| 6256 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6257 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6258 | case Node::Field: |
| 6259 | case Node::Identifier: |
| 6260 | Comp.isBrackets = false; |
| 6261 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 6262 | if (!Comp.U.IdentInfo) |
| 6263 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6264 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6265 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6266 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 6267 | case Node::Base: |
| 6268 | // Will be recomputed during the rebuild. |
| 6269 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6270 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6271 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6272 | Components.push_back(Comp); |
| 6273 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6274 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6275 | // If nothing changed, retain the existing expression. |
| 6276 | if (!getDerived().AlwaysRebuild() && |
| 6277 | Type == E->getTypeSourceInfo() && |
| 6278 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6279 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6280 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6281 | // Build a new offsetof expression. |
| 6282 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 6283 | Components.data(), Components.size(), |
| 6284 | E->getRParenLoc()); |
| 6285 | } |
| 6286 | |
| 6287 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6288 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 6289 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6290 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 6291 | "opaque value expression requires transformation"); |
| 6292 | return SemaRef.Owned(E); |
| 6293 | } |
| 6294 | |
| 6295 | template<typename Derived> |
| 6296 | ExprResult |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6297 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | 01e19be | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 6298 | // Rebuild the syntactic form. The original syntactic form has |
| 6299 | // opaque-value expressions in it, so strip those away and rebuild |
| 6300 | // the result. This is a really awful way of doing this, but the |
| 6301 | // better solution (rebuilding the semantic expressions and |
| 6302 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 6303 | // TreeTransform to not strip away implicit conversions. |
| 6304 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 6305 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6306 | if (result.isInvalid()) return ExprError(); |
| 6307 | |
| 6308 | // If that gives us a pseudo-object result back, the pseudo-object |
| 6309 | // expression must have been an lvalue-to-rvalue conversion which we |
| 6310 | // should reapply. |
| 6311 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 6312 | result = SemaRef.checkPseudoObjectRValue(result.take()); |
| 6313 | |
| 6314 | return result; |
| 6315 | } |
| 6316 | |
| 6317 | template<typename Derived> |
| 6318 | ExprResult |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6319 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 6320 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6321 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6322 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6323 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6324 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6325 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6326 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6327 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6328 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6329 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6330 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6331 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 6332 | E->getKind(), |
| 6333 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6334 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6335 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6336 | // C++0x [expr.sizeof]p1: |
| 6337 | // The operand is either an expression, which is an unevaluated operand |
| 6338 | // [...] |
| 6339 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6340 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6341 | ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 6342 | if (SubExpr.isInvalid()) |
| 6343 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6344 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6345 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 6346 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6347 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6348 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6349 | E->getOperatorLoc(), |
| 6350 | E->getKind(), |
| 6351 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6352 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6353 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6354 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6355 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6356 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6357 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6358 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6359 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6360 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6361 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6362 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6363 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6364 | |
| 6365 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6366 | if (!getDerived().AlwaysRebuild() && |
| 6367 | LHS.get() == E->getLHS() && |
| 6368 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6369 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6370 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6371 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6372 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6373 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6374 | E->getRBracketLoc()); |
| 6375 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6376 | |
| 6377 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6378 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6379 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6380 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6381 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6382 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6383 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6384 | |
| 6385 | // Transform arguments. |
| 6386 | bool ArgChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6387 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6388 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6389 | &ArgChanged)) |
| 6390 | return ExprError(); |
| 6391 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6392 | if (!getDerived().AlwaysRebuild() && |
| 6393 | Callee.get() == E->getCallee() && |
| 6394 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6395 | return SemaRef.MaybeBindToTemporary(E);; |
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 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6398 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6399 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6400 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6401 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6402 | E->getRParenLoc()); |
| 6403 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6404 | |
| 6405 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6406 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6407 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6408 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6409 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6410 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6411 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6412 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6413 | if (E->hasQualifier()) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6414 | QualifierLoc |
| 6415 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6416 | |
| 6417 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6418 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6419 | } |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6420 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6421 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6422 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6423 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6424 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6425 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6426 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6427 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6428 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6429 | if (FoundDecl == E->getMemberDecl()) { |
| 6430 | FoundDecl = Member; |
| 6431 | } else { |
| 6432 | FoundDecl = cast_or_null<NamedDecl>( |
| 6433 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6434 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6435 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6436 | } |
| 6437 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6438 | if (!getDerived().AlwaysRebuild() && |
| 6439 | Base.get() == E->getBase() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6440 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6441 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6442 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6443 | !E->hasExplicitTemplateArgs()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6444 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6445 | // Mark it referenced in the new context regardless. |
| 6446 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6447 | SemaRef.MarkMemberReferenced(E); |
| 6448 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6449 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6450 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6451 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6452 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6453 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6454 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6455 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6456 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6457 | E->getNumTemplateArgs(), |
| 6458 | TransArgs)) |
| 6459 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6460 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6461 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6462 | // FIXME: Bogus source location for the operator |
| 6463 | SourceLocation FakeOperatorLoc |
| 6464 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6465 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6466 | // FIXME: to do this check properly, we will need to preserve the |
| 6467 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6468 | // base (and therefore couldn't do the check) and a |
| 6469 | // nested-name-qualifier (and therefore could do the lookup). |
| 6470 | NamedDecl *FirstQualifierInScope = 0; |
| 6471 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6472 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6473 | E->isArrow(), |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6474 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6475 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6476 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6477 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6478 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6479 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6480 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6481 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6483 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6484 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6485 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6486 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6487 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6488 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6489 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6490 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6491 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6492 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6493 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6494 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6495 | if (!getDerived().AlwaysRebuild() && |
| 6496 | LHS.get() == E->getLHS() && |
| 6497 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6498 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6499 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6500 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6501 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6502 | } |
| 6503 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6504 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6505 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6506 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6507 | CompoundAssignOperator *E) { |
| 6508 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6509 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6510 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6511 | template<typename Derived> |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6512 | ExprResult TreeTransform<Derived>:: |
| 6513 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6514 | // Just rebuild the common and RHS expressions and see whether we |
| 6515 | // get any changes. |
| 6516 | |
| 6517 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6518 | if (commonExpr.isInvalid()) |
| 6519 | return ExprError(); |
| 6520 | |
| 6521 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6522 | if (rhs.isInvalid()) |
| 6523 | return ExprError(); |
| 6524 | |
| 6525 | if (!getDerived().AlwaysRebuild() && |
| 6526 | commonExpr.get() == e->getCommon() && |
| 6527 | rhs.get() == e->getFalseExpr()) |
| 6528 | return SemaRef.Owned(e); |
| 6529 | |
| 6530 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6531 | e->getQuestionLoc(), |
| 6532 | 0, |
| 6533 | e->getColonLoc(), |
| 6534 | rhs.get()); |
| 6535 | } |
| 6536 | |
| 6537 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6538 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6539 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6540 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6541 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6542 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6543 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6544 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6545 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6546 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6547 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6548 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6549 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6550 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6551 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6552 | if (!getDerived().AlwaysRebuild() && |
| 6553 | Cond.get() == E->getCond() && |
| 6554 | LHS.get() == E->getLHS() && |
| 6555 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6556 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6557 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6558 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6559 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6560 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6561 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6562 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6563 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6564 | |
| 6565 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6566 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6567 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6568 | // Implicit casts are eliminated during transformation, since they |
| 6569 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6570 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6571 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6572 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6573 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6574 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6575 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6576 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6577 | if (!Type) |
| 6578 | return ExprError(); |
| 6579 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6580 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6581 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6582 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6583 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6584 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6585 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6586 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6587 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6588 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6589 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6590 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6591 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6592 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6593 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6595 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6596 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6597 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6598 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6599 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6600 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6601 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6602 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6603 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6604 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6605 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6606 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6607 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6608 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6609 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6610 | Init.get() == E->getInitializer()) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6611 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6612 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6613 | // Note: the expression type doesn't necessarily match the |
| 6614 | // type-as-written, but that's okay, because it should always be |
| 6615 | // derivable from the initializer. |
| 6616 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6617 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6618 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6619 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6620 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6622 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6623 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6624 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6625 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6626 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6627 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6628 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6629 | if (!getDerived().AlwaysRebuild() && |
| 6630 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6631 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6632 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6633 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6634 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6635 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6636 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6637 | E->getAccessorLoc(), |
| 6638 | E->getAccessor()); |
| 6639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6640 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6641 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6642 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6643 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6644 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6645 | |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6646 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6647 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 6648 | Inits, &InitChanged)) |
| 6649 | return ExprError(); |
| 6650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6651 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6652 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6653 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6654 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6655 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6656 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6657 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6658 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6659 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6660 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6661 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6662 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6663 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6664 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6665 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6666 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6667 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6668 | // transform the designators. |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6669 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6670 | bool ExprChanged = false; |
| 6671 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6672 | DEnd = E->designators_end(); |
| 6673 | D != DEnd; ++D) { |
| 6674 | if (D->isFieldDesignator()) { |
| 6675 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6676 | D->getDotLoc(), |
| 6677 | D->getFieldLoc())); |
| 6678 | continue; |
| 6679 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6680 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6681 | if (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6682 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6683 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6684 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6685 | |
| 6686 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6687 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6688 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6689 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6690 | ArrayExprs.push_back(Index.release()); |
| 6691 | continue; |
| 6692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6694 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6695 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6696 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6697 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6698 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6699 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6700 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6701 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6702 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6703 | |
| 6704 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6705 | End.get(), |
| 6706 | D->getLBracketLoc(), |
| 6707 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6708 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6709 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6710 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6711 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6712 | ArrayExprs.push_back(Start.release()); |
| 6713 | ArrayExprs.push_back(End.release()); |
| 6714 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6715 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6716 | if (!getDerived().AlwaysRebuild() && |
| 6717 | Init.get() == E->getInit() && |
| 6718 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6719 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6720 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6721 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 6722 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6723 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6725 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6726 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6727 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6728 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6729 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6730 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6731 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6732 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6733 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6734 | QualType T = getDerived().TransformType(E->getType()); |
| 6735 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6736 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6737 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6738 | if (!getDerived().AlwaysRebuild() && |
| 6739 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6740 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6741 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6742 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6743 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6744 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6745 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6746 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6747 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6748 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6749 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6750 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6751 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6752 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6753 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6754 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6755 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6756 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6757 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6758 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6759 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6760 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6761 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6762 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6766 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6767 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6768 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6769 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6770 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6771 | &ArgumentChanged)) |
| 6772 | return ExprError(); |
| 6773 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6774 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 6775 | move_arg(Inits), |
| 6776 | E->getRParenLoc()); |
| 6777 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6779 | /// \brief Transform an address-of-label expression. |
| 6780 | /// |
| 6781 | /// By default, the transformation of an address-of-label expression always |
| 6782 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6783 | /// the corresponding label statement by semantic analysis. |
| 6784 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6785 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6786 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6787 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6788 | E->getLabel()); |
| 6789 | if (!LD) |
| 6790 | return ExprError(); |
| 6791 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6792 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6793 | cast<LabelDecl>(LD)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6794 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6795 | |
| 6796 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6797 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6798 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6799 | SemaRef.ActOnStartStmtExpr(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6800 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6801 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6802 | if (SubStmt.isInvalid()) { |
| 6803 | SemaRef.ActOnStmtExprError(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6804 | return ExprError(); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6805 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6807 | if (!getDerived().AlwaysRebuild() && |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6808 | SubStmt.get() == E->getSubStmt()) { |
| 6809 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 6810 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6811 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6812 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6813 | |
| 6814 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6815 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6816 | E->getRParenLoc()); |
| 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 |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6821 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6822 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6823 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6824 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6825 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6826 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6827 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6828 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6829 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6830 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6831 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6832 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6833 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6834 | if (!getDerived().AlwaysRebuild() && |
| 6835 | Cond.get() == E->getCond() && |
| 6836 | LHS.get() == E->getLHS() && |
| 6837 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6838 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6839 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6840 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6841 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6842 | E->getRParenLoc()); |
| 6843 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6844 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6845 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6846 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6847 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6848 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6849 | } |
| 6850 | |
| 6851 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6852 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6853 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6854 | switch (E->getOperator()) { |
| 6855 | case OO_New: |
| 6856 | case OO_Delete: |
| 6857 | case OO_Array_New: |
| 6858 | case OO_Array_Delete: |
| 6859 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6860 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6861 | case OO_Call: { |
| 6862 | // This is a call to an object's operator(). |
| 6863 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6864 | |
| 6865 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6866 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6867 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6868 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6869 | |
| 6870 | // FIXME: Poor location information |
| 6871 | SourceLocation FakeLParenLoc |
| 6872 | = SemaRef.PP.getLocForEndOfToken( |
| 6873 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6874 | |
| 6875 | // Transform the call arguments. |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6876 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6877 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 6878 | Args)) |
| 6879 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6880 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6881 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6882 | move_arg(Args), |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6883 | E->getLocEnd()); |
| 6884 | } |
| 6885 | |
| 6886 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6887 | case OO_##Name: |
| 6888 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6889 | #include "clang/Basic/OperatorKinds.def" |
| 6890 | case OO_Subscript: |
| 6891 | // Handled below. |
| 6892 | break; |
| 6893 | |
| 6894 | case OO_Conditional: |
| 6895 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6896 | |
| 6897 | case OO_None: |
| 6898 | case NUM_OVERLOADED_OPERATORS: |
| 6899 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6900 | } |
| 6901 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6902 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6903 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6904 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6905 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6906 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6907 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6908 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6909 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6910 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6911 | if (E->getNumArgs() == 2) { |
| 6912 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6913 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6914 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6916 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6917 | if (!getDerived().AlwaysRebuild() && |
| 6918 | Callee.get() == E->getCallee() && |
| 6919 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6920 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6921 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6922 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6923 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 6924 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6925 | Callee.get(), |
| 6926 | First.get(), |
| 6927 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6929 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6930 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6931 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6932 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6933 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6935 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6936 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6937 | ExprResult |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6938 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 6939 | // Transform the callee. |
| 6940 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 6941 | if (Callee.isInvalid()) |
| 6942 | return ExprError(); |
| 6943 | |
| 6944 | // Transform exec config. |
| 6945 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 6946 | if (EC.isInvalid()) |
| 6947 | return ExprError(); |
| 6948 | |
| 6949 | // Transform arguments. |
| 6950 | bool ArgChanged = false; |
| 6951 | ASTOwningVector<Expr*> Args(SemaRef); |
| 6952 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6953 | &ArgChanged)) |
| 6954 | return ExprError(); |
| 6955 | |
| 6956 | if (!getDerived().AlwaysRebuild() && |
| 6957 | Callee.get() == E->getCallee() && |
| 6958 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6959 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6960 | |
| 6961 | // FIXME: Wrong source location information for the '('. |
| 6962 | SourceLocation FakeLParenLoc |
| 6963 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 6964 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 6965 | move_arg(Args), |
| 6966 | E->getRParenLoc(), EC.get()); |
| 6967 | } |
| 6968 | |
| 6969 | template<typename Derived> |
| 6970 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6971 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6972 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6973 | if (!Type) |
| 6974 | return ExprError(); |
| 6975 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6976 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6977 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6978 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6979 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6980 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6981 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6982 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6983 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6984 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6985 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6986 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6987 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6988 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 6989 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 6990 | SourceLocation FakeRParenLoc |
| 6991 | = SemaRef.PP.getLocForEndOfToken( |
| 6992 | E->getSubExpr()->getSourceRange().getEnd()); |
| 6993 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6994 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6995 | FakeLAngleLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6996 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6997 | FakeRAngleLoc, |
| 6998 | FakeRAngleLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6999 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7000 | FakeRParenLoc); |
| 7001 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7002 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7003 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7004 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7005 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 7006 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7007 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7008 | |
| 7009 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7010 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7011 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 7012 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7013 | } |
| 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>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7018 | CXXReinterpretCastExpr *E) { |
| 7019 | return getDerived().TransformCXXNamedCastExpr(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>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 7025 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7026 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7027 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7028 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7029 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7030 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7031 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7032 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7033 | if (!Type) |
| 7034 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7035 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7036 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7037 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7038 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7039 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7040 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7041 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7042 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7043 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7044 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7045 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7046 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7047 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7048 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7049 | E->getRParenLoc()); |
| 7050 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7051 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7052 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7053 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7054 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7055 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7056 | TypeSourceInfo *TInfo |
| 7057 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7058 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7059 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7060 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7061 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7062 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7063 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7064 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7065 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7066 | E->getLocStart(), |
| 7067 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7068 | E->getLocEnd()); |
| 7069 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7070 | |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7071 | // We don't know whether the subexpression is potentially evaluated until |
| 7072 | // after we perform semantic analysis. We speculatively assume it is |
| 7073 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7074 | // potentially evaluated. |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7075 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7076 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7077 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7078 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7079 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7080 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7081 | if (!getDerived().AlwaysRebuild() && |
| 7082 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7083 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7084 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7085 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7086 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7087 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7088 | E->getLocEnd()); |
| 7089 | } |
| 7090 | |
| 7091 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7092 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7093 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7094 | if (E->isTypeOperand()) { |
| 7095 | TypeSourceInfo *TInfo |
| 7096 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7097 | if (!TInfo) |
| 7098 | return ExprError(); |
| 7099 | |
| 7100 | if (!getDerived().AlwaysRebuild() && |
| 7101 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7102 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7103 | |
Douglas Gregor | 3c52a21 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7104 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7105 | E->getLocStart(), |
| 7106 | TInfo, |
| 7107 | E->getLocEnd()); |
| 7108 | } |
| 7109 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7110 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7111 | |
| 7112 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7113 | if (SubExpr.isInvalid()) |
| 7114 | return ExprError(); |
| 7115 | |
| 7116 | if (!getDerived().AlwaysRebuild() && |
| 7117 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7118 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7119 | |
| 7120 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7121 | E->getLocStart(), |
| 7122 | SubExpr.get(), |
| 7123 | E->getLocEnd()); |
| 7124 | } |
| 7125 | |
| 7126 | template<typename Derived> |
| 7127 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7128 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7129 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7130 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7131 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7132 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7133 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7134 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7135 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7136 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7138 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7139 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7140 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7141 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7142 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 7143 | QualType T; |
| 7144 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) |
| 7145 | T = MD->getThisType(getSema().Context); |
| 7146 | else |
| 7147 | T = getSema().Context.getPointerType( |
| 7148 | getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7149 | |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7150 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7151 | // Make sure that we capture 'this'. |
| 7152 | getSema().CheckCXXThisCapture(E->getLocStart()); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7153 | return SemaRef.Owned(E); |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7154 | } |
| 7155 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7156 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7159 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7160 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7161 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7162 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7163 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7164 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7165 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7166 | if (!getDerived().AlwaysRebuild() && |
| 7167 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7168 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7169 | |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7170 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7171 | E->isThrownVariableInScope()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7173 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7174 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7175 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7176 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7177 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7178 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7179 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7180 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7181 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7182 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7183 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7184 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7185 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7186 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7187 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7188 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7189 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7190 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7191 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7192 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 7193 | CXXScalarValueInitExpr *E) { |
| 7194 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7195 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7196 | return ExprError(); |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7197 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7198 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7199 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7200 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7201 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7202 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 7203 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 7204 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7205 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7206 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7207 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7208 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7209 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7210 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7211 | TypeSourceInfo *AllocTypeInfo |
| 7212 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 7213 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7214 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7215 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7216 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7217 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7218 | if (ArraySize.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7219 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7220 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7221 | // Transform the placement arguments (if any). |
| 7222 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7223 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7224 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 7225 | E->getNumPlacementArgs(), true, |
| 7226 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7227 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7228 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7229 | // Transform the initializer (if any). |
| 7230 | Expr *OldInit = E->getInitializer(); |
| 7231 | ExprResult NewInit; |
| 7232 | if (OldInit) |
| 7233 | NewInit = getDerived().TransformExpr(OldInit); |
| 7234 | if (NewInit.isInvalid()) |
| 7235 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7236 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7237 | // Transform new operator and delete operator. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7238 | FunctionDecl *OperatorNew = 0; |
| 7239 | if (E->getOperatorNew()) { |
| 7240 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7241 | getDerived().TransformDecl(E->getLocStart(), |
| 7242 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7243 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7244 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | FunctionDecl *OperatorDelete = 0; |
| 7248 | if (E->getOperatorDelete()) { |
| 7249 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7250 | getDerived().TransformDecl(E->getLocStart(), |
| 7251 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7252 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7253 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7254 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7255 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7256 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7257 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7258 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7259 | NewInit.get() == OldInit && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7260 | OperatorNew == E->getOperatorNew() && |
| 7261 | OperatorDelete == E->getOperatorDelete() && |
| 7262 | !ArgumentChanged) { |
| 7263 | // Mark any declarations we need as referenced. |
| 7264 | // FIXME: instantiation-specific. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7265 | if (OperatorNew) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7266 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7267 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7268 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7269 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7270 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7271 | QualType ElementType |
| 7272 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 7273 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 7274 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 7275 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7276 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7277 | } |
| 7278 | } |
| 7279 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7280 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7281 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7282 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7283 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7284 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7285 | if (!ArraySize.get()) { |
| 7286 | // If no array size was specified, but the new expression was |
| 7287 | // instantiated with an array type (e.g., "new T" where T is |
| 7288 | // instantiated with "int[4]"), extract the outer bound from the |
| 7289 | // array type as our array size. We do this with constant and |
| 7290 | // dependently-sized array types. |
| 7291 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 7292 | if (!ArrayT) { |
| 7293 | // Do nothing |
| 7294 | } else if (const ConstantArrayType *ConsArrayT |
| 7295 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7296 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7297 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 7298 | ConsArrayT->getSize(), |
| 7299 | SemaRef.Context.getSizeType(), |
| 7300 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7301 | AllocType = ConsArrayT->getElementType(); |
| 7302 | } else if (const DependentSizedArrayType *DepArrayT |
| 7303 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 7304 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7305 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7306 | AllocType = DepArrayT->getElementType(); |
| 7307 | } |
| 7308 | } |
| 7309 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7310 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7311 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 7312 | E->isGlobalNew(), |
| 7313 | /*FIXME:*/E->getLocStart(), |
| 7314 | move_arg(PlacementArgs), |
| 7315 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 7316 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7317 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7318 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7319 | ArraySize.get(), |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7320 | E->getDirectInitRange(), |
| 7321 | NewInit.take()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7323 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7324 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7325 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7326 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7327 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7328 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7329 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7330 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7331 | // Transform the delete operator, if known. |
| 7332 | FunctionDecl *OperatorDelete = 0; |
| 7333 | if (E->getOperatorDelete()) { |
| 7334 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7335 | getDerived().TransformDecl(E->getLocStart(), |
| 7336 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7337 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7338 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7339 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7341 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7342 | Operand.get() == E->getArgument() && |
| 7343 | OperatorDelete == E->getOperatorDelete()) { |
| 7344 | // Mark any declarations we need as referenced. |
| 7345 | // FIXME: instantiation-specific. |
| 7346 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7347 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7348 | |
| 7349 | if (!E->getArgument()->isTypeDependent()) { |
| 7350 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7351 | E->getDestroyedType()); |
| 7352 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7353 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7354 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
| 7355 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7356 | } |
| 7357 | } |
| 7358 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7359 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7360 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7361 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7362 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7363 | E->isGlobalDelete(), |
| 7364 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7365 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7366 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7367 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7368 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7369 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7370 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7371 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7372 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7373 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7374 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7375 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7376 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7377 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7378 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7379 | E->getOperatorLoc(), |
| 7380 | E->isArrow()? tok::arrow : tok::period, |
| 7381 | ObjectTypePtr, |
| 7382 | MayBePseudoDestructor); |
| 7383 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7384 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7385 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7386 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7387 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7388 | if (QualifierLoc) { |
| 7389 | QualifierLoc |
| 7390 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7391 | if (!QualifierLoc) |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7392 | return ExprError(); |
| 7393 | } |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7394 | CXXScopeSpec SS; |
| 7395 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7396 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7397 | PseudoDestructorTypeStorage Destroyed; |
| 7398 | if (E->getDestroyedTypeInfo()) { |
| 7399 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7400 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7401 | ObjectType, 0, SS); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7402 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7403 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7404 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 7405 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7406 | // We aren't likely to be able to resolve the identifier down to a type |
| 7407 | // now anyway, so just retain the identifier. |
| 7408 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7409 | E->getDestroyedTypeLoc()); |
| 7410 | } else { |
| 7411 | // Look for a destructor known with the given name. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7412 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7413 | *E->getDestroyedTypeIdentifier(), |
| 7414 | E->getDestroyedTypeLoc(), |
| 7415 | /*Scope=*/0, |
| 7416 | SS, ObjectTypePtr, |
| 7417 | false); |
| 7418 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7419 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7420 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7421 | Destroyed |
| 7422 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7423 | E->getDestroyedTypeLoc()); |
| 7424 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7425 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7426 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7427 | if (E->getScopeTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7428 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7429 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7430 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7431 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7432 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7433 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7434 | E->getOperatorLoc(), |
| 7435 | E->isArrow(), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7436 | SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7437 | ScopeTypeInfo, |
| 7438 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7439 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7440 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7441 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7442 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7443 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7444 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7445 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7446 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7447 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7448 | Sema::LookupOrdinaryName); |
| 7449 | |
| 7450 | // Transform all the decls. |
| 7451 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7452 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7453 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7454 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7455 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7456 | if (!InstD) { |
| 7457 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7458 | // This can happen because of dependent hiding. |
| 7459 | if (isa<UsingShadowDecl>(*I)) |
| 7460 | continue; |
| 7461 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7462 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7463 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7464 | |
| 7465 | // Expand using declarations. |
| 7466 | if (isa<UsingDecl>(InstD)) { |
| 7467 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7468 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7469 | E = UD->shadow_end(); I != E; ++I) |
| 7470 | R.addDecl(*I); |
| 7471 | continue; |
| 7472 | } |
| 7473 | |
| 7474 | R.addDecl(InstD); |
| 7475 | } |
| 7476 | |
| 7477 | // Resolve a kind, but don't do any further analysis. If it's |
| 7478 | // ambiguous, the callee needs to deal with it. |
| 7479 | R.resolveKind(); |
| 7480 | |
| 7481 | // Rebuild the nested-name qualifier, if present. |
| 7482 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7483 | if (Old->getQualifierLoc()) { |
| 7484 | NestedNameSpecifierLoc QualifierLoc |
| 7485 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7486 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7487 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7488 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7489 | SS.Adopt(QualifierLoc); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7490 | } |
| 7491 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7492 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7493 | CXXRecordDecl *NamingClass |
| 7494 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7495 | Old->getNameLoc(), |
| 7496 | Old->getNamingClass())); |
| 7497 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7498 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7499 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7500 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7501 | } |
| 7502 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7503 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7504 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7505 | // If we have neither explicit template arguments, nor the template keyword, |
| 7506 | // it's a normal declaration name. |
| 7507 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7508 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7509 | |
| 7510 | // If we have template arguments, rebuild them, then rebuild the |
| 7511 | // templateid expression. |
| 7512 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7513 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7514 | Old->getNumTemplateArgs(), |
| 7515 | TransArgs)) |
| 7516 | return ExprError(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7517 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7518 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7519 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7520 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7521 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7522 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7523 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7524 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7525 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7526 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7527 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7528 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7529 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7530 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7531 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7532 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7533 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7534 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7535 | T, |
| 7536 | E->getLocEnd()); |
| 7537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7538 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7539 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7540 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7541 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7542 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7543 | if (!LhsT) |
| 7544 | return ExprError(); |
| 7545 | |
| 7546 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7547 | if (!RhsT) |
| 7548 | return ExprError(); |
| 7549 | |
| 7550 | if (!getDerived().AlwaysRebuild() && |
| 7551 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7552 | return SemaRef.Owned(E); |
| 7553 | |
| 7554 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7555 | E->getLocStart(), |
| 7556 | LhsT, RhsT, |
| 7557 | E->getLocEnd()); |
| 7558 | } |
| 7559 | |
| 7560 | template<typename Derived> |
| 7561 | ExprResult |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7562 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 7563 | bool ArgChanged = false; |
| 7564 | llvm::SmallVector<TypeSourceInfo *, 4> Args; |
| 7565 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 7566 | TypeSourceInfo *From = E->getArg(I); |
| 7567 | TypeLoc FromTL = From->getTypeLoc(); |
| 7568 | if (!isa<PackExpansionTypeLoc>(FromTL)) { |
| 7569 | TypeLocBuilder TLB; |
| 7570 | TLB.reserve(FromTL.getFullDataSize()); |
| 7571 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 7572 | if (To.isNull()) |
| 7573 | return ExprError(); |
| 7574 | |
| 7575 | if (To == From->getType()) |
| 7576 | Args.push_back(From); |
| 7577 | else { |
| 7578 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7579 | ArgChanged = true; |
| 7580 | } |
| 7581 | continue; |
| 7582 | } |
| 7583 | |
| 7584 | ArgChanged = true; |
| 7585 | |
| 7586 | // We have a pack expansion. Instantiate it. |
| 7587 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL); |
| 7588 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 7589 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7590 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
| 7591 | |
| 7592 | // Determine whether the set of unexpanded parameter packs can and should |
| 7593 | // be expanded. |
| 7594 | bool Expand = true; |
| 7595 | bool RetainExpansion = false; |
| 7596 | llvm::Optional<unsigned> OrigNumExpansions |
| 7597 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 7598 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 7599 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 7600 | PatternTL.getSourceRange(), |
| 7601 | Unexpanded, |
| 7602 | Expand, RetainExpansion, |
| 7603 | NumExpansions)) |
| 7604 | return ExprError(); |
| 7605 | |
| 7606 | if (!Expand) { |
| 7607 | // The transform has determined that we should perform a simple |
| 7608 | // transformation on the pack expansion, producing another pack |
| 7609 | // expansion. |
| 7610 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 7611 | |
| 7612 | TypeLocBuilder TLB; |
| 7613 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 7614 | |
| 7615 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7616 | if (To.isNull()) |
| 7617 | return ExprError(); |
| 7618 | |
| 7619 | To = getDerived().RebuildPackExpansionType(To, |
| 7620 | PatternTL.getSourceRange(), |
| 7621 | ExpansionTL.getEllipsisLoc(), |
| 7622 | NumExpansions); |
| 7623 | if (To.isNull()) |
| 7624 | return ExprError(); |
| 7625 | |
| 7626 | PackExpansionTypeLoc ToExpansionTL |
| 7627 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7628 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7629 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7630 | continue; |
| 7631 | } |
| 7632 | |
| 7633 | // Expand the pack expansion by substituting for each argument in the |
| 7634 | // pack(s). |
| 7635 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7636 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 7637 | TypeLocBuilder TLB; |
| 7638 | TLB.reserve(PatternTL.getFullDataSize()); |
| 7639 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7640 | if (To.isNull()) |
| 7641 | return ExprError(); |
| 7642 | |
| 7643 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7644 | } |
| 7645 | |
| 7646 | if (!RetainExpansion) |
| 7647 | continue; |
| 7648 | |
| 7649 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 7650 | // forgetting the partially-substituted parameter pack. |
| 7651 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 7652 | |
| 7653 | TypeLocBuilder TLB; |
| 7654 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 7655 | |
| 7656 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7657 | if (To.isNull()) |
| 7658 | return ExprError(); |
| 7659 | |
| 7660 | To = getDerived().RebuildPackExpansionType(To, |
| 7661 | PatternTL.getSourceRange(), |
| 7662 | ExpansionTL.getEllipsisLoc(), |
| 7663 | NumExpansions); |
| 7664 | if (To.isNull()) |
| 7665 | return ExprError(); |
| 7666 | |
| 7667 | PackExpansionTypeLoc ToExpansionTL |
| 7668 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7669 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7670 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7671 | } |
| 7672 | |
| 7673 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 7674 | return SemaRef.Owned(E); |
| 7675 | |
| 7676 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 7677 | E->getLocStart(), |
| 7678 | Args, |
| 7679 | E->getLocEnd()); |
| 7680 | } |
| 7681 | |
| 7682 | template<typename Derived> |
| 7683 | ExprResult |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 7684 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 7685 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7686 | if (!T) |
| 7687 | return ExprError(); |
| 7688 | |
| 7689 | if (!getDerived().AlwaysRebuild() && |
| 7690 | T == E->getQueriedTypeSourceInfo()) |
| 7691 | return SemaRef.Owned(E); |
| 7692 | |
| 7693 | ExprResult SubExpr; |
| 7694 | { |
| 7695 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7696 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 7697 | if (SubExpr.isInvalid()) |
| 7698 | return ExprError(); |
| 7699 | |
| 7700 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 7701 | return SemaRef.Owned(E); |
| 7702 | } |
| 7703 | |
| 7704 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 7705 | E->getLocStart(), |
| 7706 | T, |
| 7707 | SubExpr.get(), |
| 7708 | E->getLocEnd()); |
| 7709 | } |
| 7710 | |
| 7711 | template<typename Derived> |
| 7712 | ExprResult |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 7713 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 7714 | ExprResult SubExpr; |
| 7715 | { |
| 7716 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7717 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 7718 | if (SubExpr.isInvalid()) |
| 7719 | return ExprError(); |
| 7720 | |
| 7721 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 7722 | return SemaRef.Owned(E); |
| 7723 | } |
| 7724 | |
| 7725 | return getDerived().RebuildExpressionTrait( |
| 7726 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 7727 | } |
| 7728 | |
| 7729 | template<typename Derived> |
| 7730 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7731 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7732 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7733 | NestedNameSpecifierLoc QualifierLoc |
| 7734 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7735 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7736 | return ExprError(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7737 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7738 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7739 | // TODO: If this is a conversion-function-id, verify that the |
| 7740 | // destination type name (if present) resolves the same way after |
| 7741 | // instantiation as it did in the local scope. |
| 7742 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7743 | DeclarationNameInfo NameInfo |
| 7744 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 7745 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7746 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7747 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7748 | if (!E->hasExplicitTemplateArgs()) { |
| 7749 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7750 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7751 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 7752 | // if name has not changed, DNLoc has not changed either. |
| 7753 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7754 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7755 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7756 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7757 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7758 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7759 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 7760 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7761 | |
| 7762 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7763 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7764 | E->getNumTemplateArgs(), |
| 7765 | TransArgs)) |
| 7766 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7767 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7768 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7769 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7770 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7771 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7772 | } |
| 7773 | |
| 7774 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7775 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7776 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 7777 | // CXXConstructExprs are always implicit, so when we have a |
| 7778 | // 1-argument construction we just transform that argument. |
| 7779 | if (E->getNumArgs() == 1 || |
| 7780 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 7781 | return getDerived().TransformExpr(E->getArg(0)); |
| 7782 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7783 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 7784 | |
| 7785 | QualType T = getDerived().TransformType(E->getType()); |
| 7786 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7787 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7788 | |
| 7789 | CXXConstructorDecl *Constructor |
| 7790 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7791 | getDerived().TransformDecl(E->getLocStart(), |
| 7792 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7793 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7794 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7795 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7796 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7797 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7798 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7799 | &ArgumentChanged)) |
| 7800 | return ExprError(); |
| 7801 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7802 | if (!getDerived().AlwaysRebuild() && |
| 7803 | T == E->getType() && |
| 7804 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7805 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7806 | // Mark the constructor as referenced. |
| 7807 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7808 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7809 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7810 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7811 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 7812 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 7813 | Constructor, E->isElidable(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7814 | move_arg(Args), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 7815 | E->hadMultipleCandidates(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7816 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 7817 | E->getConstructionKind(), |
| 7818 | E->getParenRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7819 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7820 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7821 | /// \brief Transform a C++ temporary-binding expression. |
| 7822 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7823 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 7824 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7825 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7826 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7827 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7828 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7829 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7830 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7831 | /// \brief Transform a C++ expression that contains cleanups that should |
| 7832 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7833 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7834 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7835 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7836 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7837 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7838 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7839 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7841 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7842 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7843 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7844 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7845 | CXXTemporaryObjectExpr *E) { |
| 7846 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7847 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7848 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7849 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7850 | CXXConstructorDecl *Constructor |
| 7851 | = cast_or_null<CXXConstructorDecl>( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7852 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7853 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7854 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7855 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7856 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7857 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7858 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7859 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7860 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7861 | &ArgumentChanged)) |
| 7862 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7863 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7864 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7865 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7866 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7867 | !ArgumentChanged) { |
| 7868 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7869 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7870 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7871 | } |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7872 | |
| 7873 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 7874 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7875 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7876 | E->getLocEnd()); |
| 7877 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7878 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7879 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7880 | ExprResult |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 7881 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7882 | // Create the local class that will describe the lambda. |
| 7883 | CXXRecordDecl *Class |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 7884 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| 7885 | /*KnownDependent=*/false); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7886 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 7887 | |
| 7888 | // Transform the type of the lambda parameters and start the definition of |
| 7889 | // the lambda itself. |
| 7890 | TypeSourceInfo *MethodTy |
| 7891 | = TransformType(E->getCallOperator()->getTypeSourceInfo()); |
| 7892 | if (!MethodTy) |
| 7893 | return ExprError(); |
| 7894 | |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 7895 | // Transform lambda parameters. |
| 7896 | bool Invalid = false; |
| 7897 | llvm::SmallVector<QualType, 4> ParamTypes; |
| 7898 | llvm::SmallVector<ParmVarDecl *, 4> Params; |
| 7899 | if (getDerived().TransformFunctionTypeParams(E->getLocStart(), |
| 7900 | E->getCallOperator()->param_begin(), |
| 7901 | E->getCallOperator()->param_size(), |
| 7902 | 0, ParamTypes, &Params)) |
| 7903 | Invalid = true; |
| 7904 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7905 | // Build the call operator. |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 7906 | // Note: Once a lambda mangling number and context declaration have been |
| 7907 | // assigned, they never change. |
| 7908 | unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber(); |
| 7909 | Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl(); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7910 | CXXMethodDecl *CallOperator |
| 7911 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
| 7912 | MethodTy, |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 7913 | E->getCallOperator()->getLocEnd(), |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 7914 | Params, ManglingNumber, ContextDecl); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7915 | getDerived().transformAttrs(E->getCallOperator(), CallOperator); |
| 7916 | |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 7917 | // FIXME: Instantiation-specific. |
| 7918 | CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(), |
| 7919 | TSK_ImplicitInstantiation); |
| 7920 | |
| 7921 | // Introduce the context of the call operator. |
| 7922 | Sema::ContextRAII SavedContext(getSema(), CallOperator); |
| 7923 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7924 | // Enter the scope of the lambda. |
| 7925 | sema::LambdaScopeInfo *LSI |
| 7926 | = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(), |
| 7927 | E->getCaptureDefault(), |
| 7928 | E->hasExplicitParameters(), |
| 7929 | E->hasExplicitResultType(), |
| 7930 | E->isMutable()); |
| 7931 | |
| 7932 | // Transform captures. |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7933 | bool FinishedExplicitCaptures = false; |
| 7934 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 7935 | CEnd = E->capture_end(); |
| 7936 | C != CEnd; ++C) { |
| 7937 | // When we hit the first implicit capture, tell Sema that we've finished |
| 7938 | // the list of explicit captures. |
| 7939 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 7940 | getSema().finishLambdaExplicitCaptures(LSI); |
| 7941 | FinishedExplicitCaptures = true; |
| 7942 | } |
| 7943 | |
| 7944 | // Capturing 'this' is trivial. |
| 7945 | if (C->capturesThis()) { |
| 7946 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 7947 | continue; |
| 7948 | } |
| 7949 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7950 | // Determine the capture kind for Sema. |
| 7951 | Sema::TryCaptureKind Kind |
| 7952 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 7953 | : C->getCaptureKind() == LCK_ByCopy |
| 7954 | ? Sema::TryCapture_ExplicitByVal |
| 7955 | : Sema::TryCapture_ExplicitByRef; |
| 7956 | SourceLocation EllipsisLoc; |
| 7957 | if (C->isPackExpansion()) { |
| 7958 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 7959 | bool ShouldExpand = false; |
| 7960 | bool RetainExpansion = false; |
| 7961 | llvm::Optional<unsigned> NumExpansions; |
| 7962 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 7963 | C->getLocation(), |
| 7964 | Unexpanded, |
| 7965 | ShouldExpand, RetainExpansion, |
| 7966 | NumExpansions)) |
| 7967 | return ExprError(); |
| 7968 | |
| 7969 | if (ShouldExpand) { |
| 7970 | // The transform has determined that we should perform an expansion; |
| 7971 | // transform and capture each of the arguments. |
| 7972 | // expansion of the pattern. Do so. |
| 7973 | VarDecl *Pack = C->getCapturedVar(); |
| 7974 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7975 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 7976 | VarDecl *CapturedVar |
| 7977 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| 7978 | Pack)); |
| 7979 | if (!CapturedVar) { |
| 7980 | Invalid = true; |
| 7981 | continue; |
| 7982 | } |
| 7983 | |
| 7984 | // Capture the transformed variable. |
Douglas Gregor | 999713e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 7985 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7986 | } |
| 7987 | continue; |
| 7988 | } |
| 7989 | |
| 7990 | EllipsisLoc = C->getEllipsisLoc(); |
| 7991 | } |
| 7992 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7993 | // Transform the captured variable. |
| 7994 | VarDecl *CapturedVar |
| 7995 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| 7996 | C->getCapturedVar())); |
| 7997 | if (!CapturedVar) { |
| 7998 | Invalid = true; |
| 7999 | continue; |
| 8000 | } |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8001 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8002 | // Capture the transformed variable. |
Douglas Gregor | 999713e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 8003 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8004 | } |
| 8005 | if (!FinishedExplicitCaptures) |
| 8006 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8007 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8008 | |
| 8009 | // Enter a new evaluation context to insulate the lambda from any |
| 8010 | // cleanups from the enclosing full-expression. |
| 8011 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
| 8012 | |
| 8013 | if (Invalid) { |
| 8014 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
| 8015 | /*IsInstantiation=*/true); |
| 8016 | return ExprError(); |
| 8017 | } |
| 8018 | |
| 8019 | // Instantiate the body of the lambda expression. |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8020 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 8021 | if (Body.isInvalid()) { |
| 8022 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
| 8023 | /*IsInstantiation=*/true); |
| 8024 | return ExprError(); |
| 8025 | } |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 8026 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8027 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 8028 | /*CurScope=*/0, /*IsInstantiation=*/true); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8029 | } |
| 8030 | |
| 8031 | template<typename Derived> |
| 8032 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8033 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8034 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8035 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8036 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8037 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8038 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8039 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 8040 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8041 | Args.reserve(E->arg_size()); |
| 8042 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 8043 | &ArgumentChanged)) |
| 8044 | return ExprError(); |
| 8045 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8046 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8047 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8048 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8049 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8050 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8051 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8052 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8053 | E->getLParenLoc(), |
| 8054 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8055 | E->getRParenLoc()); |
| 8056 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8057 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8058 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8059 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8060 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8061 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8062 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8063 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8064 | Expr *OldBase; |
| 8065 | QualType BaseType; |
| 8066 | QualType ObjectType; |
| 8067 | if (!E->isImplicitAccess()) { |
| 8068 | OldBase = E->getBase(); |
| 8069 | Base = getDerived().TransformExpr(OldBase); |
| 8070 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8071 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8072 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8073 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8074 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8075 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8076 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8077 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8078 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8079 | ObjectTy, |
| 8080 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8081 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8082 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8083 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8084 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8085 | BaseType = ((Expr*) Base.get())->getType(); |
| 8086 | } else { |
| 8087 | OldBase = 0; |
| 8088 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 8089 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 8090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8091 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8092 | // Transform the first part of the nested-name-specifier that qualifies |
| 8093 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 8094 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8095 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8096 | E->getFirstQualifierFoundInScope(), |
| 8097 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8098 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8099 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8100 | if (E->getQualifier()) { |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8101 | QualifierLoc |
| 8102 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 8103 | ObjectType, |
| 8104 | FirstQualifierInScope); |
| 8105 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8106 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8107 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8108 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8109 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 8110 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8111 | // TODO: If this is a conversion-function-id, verify that the |
| 8112 | // destination type name (if present) resolves the same way after |
| 8113 | // instantiation as it did in the local scope. |
| 8114 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8115 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8116 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8117 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8118 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8119 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8120 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8121 | // This is a reference to a member without an explicitly-specified |
| 8122 | // template argument list. Optimize for this common case. |
| 8123 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8124 | Base.get() == OldBase && |
| 8125 | BaseType == E->getBaseType() && |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8126 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8127 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8128 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8129 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8130 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8131 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8132 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8133 | E->isArrow(), |
| 8134 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8135 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8136 | TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8137 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8138 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8139 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8140 | } |
| 8141 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8142 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8143 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8144 | E->getNumTemplateArgs(), |
| 8145 | TransArgs)) |
| 8146 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8147 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8148 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8149 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8150 | E->isArrow(), |
| 8151 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8152 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8153 | TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8154 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8155 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8156 | &TransArgs); |
| 8157 | } |
| 8158 | |
| 8159 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8160 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8161 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8162 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8163 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8164 | QualType BaseType; |
| 8165 | if (!Old->isImplicitAccess()) { |
| 8166 | Base = getDerived().TransformExpr(Old->getBase()); |
| 8167 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8168 | return ExprError(); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 8169 | Base = getSema().PerformMemberExprBaseConversion(Base.take(), |
| 8170 | Old->isArrow()); |
| 8171 | if (Base.isInvalid()) |
| 8172 | return ExprError(); |
| 8173 | BaseType = Base.get()->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8174 | } else { |
| 8175 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 8176 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8177 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8178 | NestedNameSpecifierLoc QualifierLoc; |
| 8179 | if (Old->getQualifierLoc()) { |
| 8180 | QualifierLoc |
| 8181 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8182 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8183 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8184 | } |
| 8185 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8186 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8187 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8188 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8189 | Sema::LookupOrdinaryName); |
| 8190 | |
| 8191 | // Transform all the decls. |
| 8192 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 8193 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8194 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8195 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 8196 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8197 | if (!InstD) { |
| 8198 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8199 | // This can happen because of dependent hiding. |
| 8200 | if (isa<UsingShadowDecl>(*I)) |
| 8201 | continue; |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8202 | else { |
| 8203 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8204 | return ExprError(); |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8205 | } |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8206 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8207 | |
| 8208 | // Expand using declarations. |
| 8209 | if (isa<UsingDecl>(InstD)) { |
| 8210 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 8211 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 8212 | E = UD->shadow_end(); I != E; ++I) |
| 8213 | R.addDecl(*I); |
| 8214 | continue; |
| 8215 | } |
| 8216 | |
| 8217 | R.addDecl(InstD); |
| 8218 | } |
| 8219 | |
| 8220 | R.resolveKind(); |
| 8221 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8222 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 8223 | if (Old->getNamingClass()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8224 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8225 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8226 | Old->getMemberLoc(), |
| 8227 | Old->getNamingClass())); |
| 8228 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8229 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8230 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8231 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8232 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8233 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8234 | TemplateArgumentListInfo TransArgs; |
| 8235 | if (Old->hasExplicitTemplateArgs()) { |
| 8236 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 8237 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8238 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 8239 | Old->getNumTemplateArgs(), |
| 8240 | TransArgs)) |
| 8241 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8242 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8243 | |
| 8244 | // FIXME: to do this check properly, we will need to preserve the |
| 8245 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8246 | // base (and therefore couldn't do the check) and a |
| 8247 | // nested-name-qualifier (and therefore could do the lookup). |
| 8248 | NamedDecl *FirstQualifierInScope = 0; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8249 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8250 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8251 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8252 | Old->getOperatorLoc(), |
| 8253 | Old->isArrow(), |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8254 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8255 | TemplateKWLoc, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8256 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8257 | R, |
| 8258 | (Old->hasExplicitTemplateArgs() |
| 8259 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8260 | } |
| 8261 | |
| 8262 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8263 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8264 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Sean Hunt | eea06c6 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 8265 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8266 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 8267 | if (SubExpr.isInvalid()) |
| 8268 | return ExprError(); |
| 8269 | |
| 8270 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8271 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8272 | |
| 8273 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 8274 | } |
| 8275 | |
| 8276 | template<typename Derived> |
| 8277 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8278 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8279 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 8280 | if (Pattern.isInvalid()) |
| 8281 | return ExprError(); |
| 8282 | |
| 8283 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 8284 | return SemaRef.Owned(E); |
| 8285 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 8286 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 8287 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8288 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8289 | |
| 8290 | template<typename Derived> |
| 8291 | ExprResult |
| 8292 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 8293 | // If E is not value-dependent, then nothing will change when we transform it. |
| 8294 | // Note: This is an instantiation-centric view. |
| 8295 | if (!E->isValueDependent()) |
| 8296 | return SemaRef.Owned(E); |
| 8297 | |
| 8298 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 8299 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 8300 | // so |
| 8301 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 8302 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8303 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 8304 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8305 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 8306 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8307 | ShouldExpand, RetainExpansion, |
| 8308 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8309 | return ExprError(); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8310 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8311 | if (RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8312 | return SemaRef.Owned(E); |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8313 | |
| 8314 | NamedDecl *Pack = E->getPack(); |
| 8315 | if (!ShouldExpand) { |
| 8316 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
| 8317 | Pack)); |
| 8318 | if (!Pack) |
| 8319 | return ExprError(); |
| 8320 | } |
| 8321 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8322 | |
| 8323 | // We now know the length of the parameter pack, so build a new expression |
| 8324 | // that stores that length. |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8325 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8326 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8327 | NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8328 | } |
| 8329 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8330 | template<typename Derived> |
| 8331 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 8332 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 8333 | SubstNonTypeTemplateParmPackExpr *E) { |
| 8334 | // Default behavior is to do nothing with this transformation. |
| 8335 | return SemaRef.Owned(E); |
| 8336 | } |
| 8337 | |
| 8338 | template<typename Derived> |
| 8339 | ExprResult |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 8340 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 8341 | SubstNonTypeTemplateParmExpr *E) { |
| 8342 | // Default behavior is to do nothing with this transformation. |
| 8343 | return SemaRef.Owned(E); |
| 8344 | } |
| 8345 | |
| 8346 | template<typename Derived> |
| 8347 | ExprResult |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8348 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 8349 | MaterializeTemporaryExpr *E) { |
| 8350 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 8351 | } |
| 8352 | |
| 8353 | template<typename Derived> |
| 8354 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8355 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8356 | return SemaRef.MaybeBindToTemporary(E); |
| 8357 | } |
| 8358 | |
| 8359 | template<typename Derived> |
| 8360 | ExprResult |
| 8361 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Jordy Rose | d8b5ca1 | 2012-03-12 17:53:02 +0000 | [diff] [blame] | 8362 | return SemaRef.Owned(E); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8363 | } |
| 8364 | |
| 8365 | template<typename Derived> |
| 8366 | ExprResult |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 8367 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 8368 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 8369 | if (SubExpr.isInvalid()) |
| 8370 | return ExprError(); |
| 8371 | |
| 8372 | if (!getDerived().AlwaysRebuild() && |
| 8373 | SubExpr.get() == E->getSubExpr()) |
| 8374 | return SemaRef.Owned(E); |
| 8375 | |
| 8376 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8377 | } |
| 8378 | |
| 8379 | template<typename Derived> |
| 8380 | ExprResult |
| 8381 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 8382 | // Transform each of the elements. |
| 8383 | llvm::SmallVector<Expr *, 8> Elements; |
| 8384 | bool ArgChanged = false; |
| 8385 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
| 8386 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 8387 | return ExprError(); |
| 8388 | |
| 8389 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8390 | return SemaRef.MaybeBindToTemporary(E); |
| 8391 | |
| 8392 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 8393 | Elements.data(), |
| 8394 | Elements.size()); |
| 8395 | } |
| 8396 | |
| 8397 | template<typename Derived> |
| 8398 | ExprResult |
| 8399 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
| 8400 | ObjCDictionaryLiteral *E) { |
| 8401 | // Transform each of the elements. |
| 8402 | llvm::SmallVector<ObjCDictionaryElement, 8> Elements; |
| 8403 | bool ArgChanged = false; |
| 8404 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 8405 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
| 8406 | |
| 8407 | if (OrigElement.isPackExpansion()) { |
| 8408 | // This key/value element is a pack expansion. |
| 8409 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8410 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 8411 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 8412 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 8413 | |
| 8414 | // Determine whether the set of unexpanded parameter packs can |
| 8415 | // and should be expanded. |
| 8416 | bool Expand = true; |
| 8417 | bool RetainExpansion = false; |
| 8418 | llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 8419 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 8420 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 8421 | OrigElement.Value->getLocEnd()); |
| 8422 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 8423 | PatternRange, |
| 8424 | Unexpanded, |
| 8425 | Expand, RetainExpansion, |
| 8426 | NumExpansions)) |
| 8427 | return ExprError(); |
| 8428 | |
| 8429 | if (!Expand) { |
| 8430 | // The transform has determined that we should perform a simple |
| 8431 | // transformation on the pack expansion, producing another pack |
| 8432 | // expansion. |
| 8433 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 8434 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8435 | if (Key.isInvalid()) |
| 8436 | return ExprError(); |
| 8437 | |
| 8438 | if (Key.get() != OrigElement.Key) |
| 8439 | ArgChanged = true; |
| 8440 | |
| 8441 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8442 | if (Value.isInvalid()) |
| 8443 | return ExprError(); |
| 8444 | |
| 8445 | if (Value.get() != OrigElement.Value) |
| 8446 | ArgChanged = true; |
| 8447 | |
| 8448 | ObjCDictionaryElement Expansion = { |
| 8449 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 8450 | }; |
| 8451 | Elements.push_back(Expansion); |
| 8452 | continue; |
| 8453 | } |
| 8454 | |
| 8455 | // Record right away that the argument was changed. This needs |
| 8456 | // to happen even if the array expands to nothing. |
| 8457 | ArgChanged = true; |
| 8458 | |
| 8459 | // The transform has determined that we should perform an elementwise |
| 8460 | // expansion of the pattern. Do so. |
| 8461 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8462 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8463 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8464 | if (Key.isInvalid()) |
| 8465 | return ExprError(); |
| 8466 | |
| 8467 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8468 | if (Value.isInvalid()) |
| 8469 | return ExprError(); |
| 8470 | |
| 8471 | ObjCDictionaryElement Element = { |
| 8472 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 8473 | }; |
| 8474 | |
| 8475 | // If any unexpanded parameter packs remain, we still have a |
| 8476 | // pack expansion. |
| 8477 | if (Key.get()->containsUnexpandedParameterPack() || |
| 8478 | Value.get()->containsUnexpandedParameterPack()) |
| 8479 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
| 8480 | |
| 8481 | Elements.push_back(Element); |
| 8482 | } |
| 8483 | |
| 8484 | // We've finished with this pack expansion. |
| 8485 | continue; |
| 8486 | } |
| 8487 | |
| 8488 | // Transform and check key. |
| 8489 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8490 | if (Key.isInvalid()) |
| 8491 | return ExprError(); |
| 8492 | |
| 8493 | if (Key.get() != OrigElement.Key) |
| 8494 | ArgChanged = true; |
| 8495 | |
| 8496 | // Transform and check value. |
| 8497 | ExprResult Value |
| 8498 | = getDerived().TransformExpr(OrigElement.Value); |
| 8499 | if (Value.isInvalid()) |
| 8500 | return ExprError(); |
| 8501 | |
| 8502 | if (Value.get() != OrigElement.Value) |
| 8503 | ArgChanged = true; |
| 8504 | |
| 8505 | ObjCDictionaryElement Element = { |
| 8506 | Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>() |
| 8507 | }; |
| 8508 | Elements.push_back(Element); |
| 8509 | } |
| 8510 | |
| 8511 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8512 | return SemaRef.MaybeBindToTemporary(E); |
| 8513 | |
| 8514 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 8515 | Elements.data(), |
| 8516 | Elements.size()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8517 | } |
| 8518 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8519 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8520 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8521 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8522 | TypeSourceInfo *EncodedTypeInfo |
| 8523 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 8524 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8525 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8526 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8527 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8528 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8529 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8530 | |
| 8531 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8532 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8533 | E->getRParenLoc()); |
| 8534 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8535 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8536 | template<typename Derived> |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8537 | ExprResult TreeTransform<Derived>:: |
| 8538 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| 8539 | ExprResult result = getDerived().TransformExpr(E->getSubExpr()); |
| 8540 | if (result.isInvalid()) return ExprError(); |
| 8541 | Expr *subExpr = result.take(); |
| 8542 | |
| 8543 | if (!getDerived().AlwaysRebuild() && |
| 8544 | subExpr == E->getSubExpr()) |
| 8545 | return SemaRef.Owned(E); |
| 8546 | |
| 8547 | return SemaRef.Owned(new(SemaRef.Context) |
| 8548 | ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); |
| 8549 | } |
| 8550 | |
| 8551 | template<typename Derived> |
| 8552 | ExprResult TreeTransform<Derived>:: |
| 8553 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| 8554 | TypeSourceInfo *TSInfo |
| 8555 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8556 | if (!TSInfo) |
| 8557 | return ExprError(); |
| 8558 | |
| 8559 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
| 8560 | if (Result.isInvalid()) |
| 8561 | return ExprError(); |
| 8562 | |
| 8563 | if (!getDerived().AlwaysRebuild() && |
| 8564 | TSInfo == E->getTypeInfoAsWritten() && |
| 8565 | Result.get() == E->getSubExpr()) |
| 8566 | return SemaRef.Owned(E); |
| 8567 | |
| 8568 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
| 8569 | E->getBridgeKeywordLoc(), TSInfo, |
| 8570 | Result.get()); |
| 8571 | } |
| 8572 | |
| 8573 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8574 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8575 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8576 | // Transform arguments. |
| 8577 | bool ArgChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 8578 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8579 | Args.reserve(E->getNumArgs()); |
| 8580 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 8581 | &ArgChanged)) |
| 8582 | return ExprError(); |
| 8583 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8584 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 8585 | // Class message: transform the receiver type. |
| 8586 | TypeSourceInfo *ReceiverTypeInfo |
| 8587 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 8588 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8589 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8590 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8591 | // If nothing changed, just retain the existing message send. |
| 8592 | if (!getDerived().AlwaysRebuild() && |
| 8593 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8594 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8595 | |
| 8596 | // Build a new class message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8597 | SmallVector<SourceLocation, 16> SelLocs; |
| 8598 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8599 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 8600 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8601 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8602 | E->getMethodDecl(), |
| 8603 | E->getLeftLoc(), |
| 8604 | move_arg(Args), |
| 8605 | E->getRightLoc()); |
| 8606 | } |
| 8607 | |
| 8608 | // Instance message: transform the receiver |
| 8609 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 8610 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8611 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8612 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 8613 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8614 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8615 | |
| 8616 | // If nothing changed, just retain the existing message send. |
| 8617 | if (!getDerived().AlwaysRebuild() && |
| 8618 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8619 | return SemaRef.MaybeBindToTemporary(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8620 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8621 | // Build a new instance message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8622 | SmallVector<SourceLocation, 16> SelLocs; |
| 8623 | E->getSelectorLocs(SelLocs); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8624 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8625 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8626 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8627 | E->getMethodDecl(), |
| 8628 | E->getLeftLoc(), |
| 8629 | move_arg(Args), |
| 8630 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8631 | } |
| 8632 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8633 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8634 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8635 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8636 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8637 | } |
| 8638 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8639 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8640 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8641 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8642 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8643 | } |
| 8644 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8645 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8646 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8647 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8648 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8649 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8650 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8651 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8652 | |
| 8653 | // We don't need to transform the ivar; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8654 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8655 | // If nothing changed, just retain the existing expression. |
| 8656 | if (!getDerived().AlwaysRebuild() && |
| 8657 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8658 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8659 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8660 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8661 | E->getLocation(), |
| 8662 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8663 | } |
| 8664 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8665 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8666 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8667 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8668 | // 'super' and types never change. Property never changes. Just |
| 8669 | // retain the existing expression. |
| 8670 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8671 | return SemaRef.Owned(E); |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 8672 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8673 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8674 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8675 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8676 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8677 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8678 | // We don't need to transform the property; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8679 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8680 | // If nothing changed, just retain the existing expression. |
| 8681 | if (!getDerived().AlwaysRebuild() && |
| 8682 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8683 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8684 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8685 | if (E->isExplicitProperty()) |
| 8686 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 8687 | E->getExplicitProperty(), |
| 8688 | E->getLocation()); |
| 8689 | |
| 8690 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 8691 | SemaRef.Context.PseudoObjectTy, |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8692 | E->getImplicitPropertyGetter(), |
| 8693 | E->getImplicitPropertySetter(), |
| 8694 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8695 | } |
| 8696 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8697 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8698 | ExprResult |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8699 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 8700 | // Transform the base expression. |
| 8701 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 8702 | if (Base.isInvalid()) |
| 8703 | return ExprError(); |
| 8704 | |
| 8705 | // Transform the key expression. |
| 8706 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 8707 | if (Key.isInvalid()) |
| 8708 | return ExprError(); |
| 8709 | |
| 8710 | // If nothing changed, just retain the existing expression. |
| 8711 | if (!getDerived().AlwaysRebuild() && |
| 8712 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 8713 | return SemaRef.Owned(E); |
| 8714 | |
| 8715 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
| 8716 | Base.get(), Key.get(), |
| 8717 | E->getAtIndexMethodDecl(), |
| 8718 | E->setAtIndexMethodDecl()); |
| 8719 | } |
| 8720 | |
| 8721 | template<typename Derived> |
| 8722 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8723 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8724 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8725 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8726 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8727 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8728 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8729 | // If nothing changed, just retain the existing expression. |
| 8730 | if (!getDerived().AlwaysRebuild() && |
| 8731 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8732 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8733 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8734 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8735 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8736 | } |
| 8737 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8738 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8739 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8740 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8741 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 8742 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8743 | SubExprs.reserve(E->getNumSubExprs()); |
| 8744 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 8745 | SubExprs, &ArgumentChanged)) |
| 8746 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8747 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8748 | if (!getDerived().AlwaysRebuild() && |
| 8749 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8750 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8751 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8752 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 8753 | move_arg(SubExprs), |
| 8754 | E->getRParenLoc()); |
| 8755 | } |
| 8756 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8757 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8758 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8759 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8760 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8761 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8762 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 8763 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 8764 | |
| 8765 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 0586520 | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 8766 | blockScope->TheDecl->setBlockMissingReturnType( |
| 8767 | oldBlock->blockMissingReturnType()); |
Fariborz Jahanian | ff36559 | 2011-05-05 17:18:12 +0000 | [diff] [blame] | 8768 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 8769 | SmallVector<ParmVarDecl*, 4> params; |
| 8770 | SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8771 | |
| 8772 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8773 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 8774 | oldBlock->param_begin(), |
| 8775 | oldBlock->param_size(), |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8776 | 0, paramTypes, ¶ms)) { |
| 8777 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8778 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8779 | } |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8780 | |
| 8781 | const FunctionType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8782 | QualType exprResultType = |
| 8783 | getDerived().TransformType(exprFunctionType->getResultType()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8784 | |
| 8785 | // Don't allow returning a objc interface by value. |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8786 | if (exprResultType->isObjCObjectType()) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8787 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8788 | diag::err_object_cannot_be_passed_returned_by_value) |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8789 | << 0 << exprResultType; |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8790 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8791 | return ExprError(); |
| 8792 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8793 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8794 | QualType functionType = getDerived().RebuildFunctionProtoType( |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8795 | exprResultType, |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8796 | paramTypes.data(), |
| 8797 | paramTypes.size(), |
| 8798 | oldBlock->isVariadic(), |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 8799 | false, 0, RQ_None, |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8800 | exprFunctionType->getExtInfo()); |
| 8801 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8802 | |
| 8803 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8804 | if (!params.empty()) |
David Blaikie | 4278c65 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 8805 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8806 | |
| 8807 | if (!oldBlock->blockMissingReturnType()) { |
| 8808 | blockScope->HasImplicitReturnType = false; |
| 8809 | blockScope->ReturnType = exprResultType; |
| 8810 | } |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8811 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8812 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8813 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8814 | if (body.isInvalid()) { |
| 8815 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8816 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8817 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8818 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8819 | #ifndef NDEBUG |
| 8820 | // In builds with assertions, make sure that we captured everything we |
| 8821 | // captured before. |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8822 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 8823 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 8824 | e = oldBlock->capture_end(); i != e; ++i) { |
| 8825 | VarDecl *oldCapture = i->getVariable(); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8826 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8827 | // Ignore parameter packs. |
| 8828 | if (isa<ParmVarDecl>(oldCapture) && |
| 8829 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 8830 | continue; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8831 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8832 | VarDecl *newCapture = |
| 8833 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 8834 | oldCapture)); |
| 8835 | assert(blockScope->CaptureMap.count(newCapture)); |
| 8836 | } |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8837 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8838 | } |
| 8839 | #endif |
| 8840 | |
| 8841 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 8842 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8843 | } |
| 8844 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8845 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8846 | ExprResult |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8847 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 8848 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8849 | } |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 8850 | |
| 8851 | template<typename Derived> |
| 8852 | ExprResult |
| 8853 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 8854 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 8855 | bool ArgumentChanged = false; |
| 8856 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
| 8857 | SubExprs.reserve(E->getNumSubExprs()); |
| 8858 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 8859 | SubExprs, &ArgumentChanged)) |
| 8860 | return ExprError(); |
| 8861 | |
| 8862 | if (!getDerived().AlwaysRebuild() && |
| 8863 | !ArgumentChanged) |
| 8864 | return SemaRef.Owned(E); |
| 8865 | |
| 8866 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs), |
| 8867 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 8868 | } |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8869 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8870 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8871 | // Type reconstruction |
| 8872 | //===----------------------------------------------------------------------===// |
| 8873 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8874 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8875 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 8876 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8877 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8878 | getDerived().getBaseEntity()); |
| 8879 | } |
| 8880 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8881 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8882 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 8883 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8884 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8885 | getDerived().getBaseEntity()); |
| 8886 | } |
| 8887 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8888 | template<typename Derived> |
| 8889 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8890 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 8891 | bool WrittenAsLValue, |
| 8892 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8893 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8894 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8895 | } |
| 8896 | |
| 8897 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8898 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8899 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 8900 | QualType ClassType, |
| 8901 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8902 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8903 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8904 | } |
| 8905 | |
| 8906 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8907 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8908 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 8909 | ArrayType::ArraySizeModifier SizeMod, |
| 8910 | const llvm::APInt *Size, |
| 8911 | Expr *SizeExpr, |
| 8912 | unsigned IndexTypeQuals, |
| 8913 | SourceRange BracketsRange) { |
| 8914 | if (SizeExpr || !Size) |
| 8915 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 8916 | IndexTypeQuals, BracketsRange, |
| 8917 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8918 | |
| 8919 | QualType Types[] = { |
| 8920 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 8921 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 8922 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8923 | }; |
| 8924 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 8925 | QualType SizeType; |
| 8926 | for (unsigned I = 0; I != NumTypes; ++I) |
| 8927 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 8928 | SizeType = Types[I]; |
| 8929 | break; |
| 8930 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8931 | |
Eli Friedman | 01f276d | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 8932 | // Note that we can return a VariableArrayType here in the case where |
| 8933 | // the element type was a dependent VariableArrayType. |
| 8934 | IntegerLiteral *ArraySize |
| 8935 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 8936 | /*FIXME*/BracketsRange.getBegin()); |
| 8937 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8938 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8939 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8940 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8941 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8942 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8943 | QualType |
| 8944 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8945 | ArrayType::ArraySizeModifier SizeMod, |
| 8946 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8947 | unsigned IndexTypeQuals, |
| 8948 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8949 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8950 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8951 | } |
| 8952 | |
| 8953 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8954 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8955 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8956 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8957 | unsigned IndexTypeQuals, |
| 8958 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8959 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8960 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8961 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8962 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8963 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8964 | QualType |
| 8965 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8966 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8967 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8968 | unsigned IndexTypeQuals, |
| 8969 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8970 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8971 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8972 | IndexTypeQuals, BracketsRange); |
| 8973 | } |
| 8974 | |
| 8975 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8976 | QualType |
| 8977 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8978 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8979 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8980 | unsigned IndexTypeQuals, |
| 8981 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8982 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8983 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8984 | IndexTypeQuals, BracketsRange); |
| 8985 | } |
| 8986 | |
| 8987 | template<typename Derived> |
| 8988 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 8989 | unsigned NumElements, |
| 8990 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8991 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 8992 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8994 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8995 | template<typename Derived> |
| 8996 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 8997 | unsigned NumElements, |
| 8998 | SourceLocation AttributeLoc) { |
| 8999 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 9000 | NumElements, true); |
| 9001 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 9002 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 9003 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9004 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9005 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9006 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9007 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9008 | QualType |
| 9009 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9010 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9011 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9012 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9013 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9014 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9015 | template<typename Derived> |
| 9016 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9017 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9018 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9019 | bool Variadic, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 9020 | bool HasTrailingReturn, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9021 | unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 9022 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9023 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9024 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 9025 | HasTrailingReturn, Quals, RefQualifier, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9026 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9027 | getDerived().getBaseEntity(), |
| 9028 | Info); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9029 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9030 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9031 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 9032 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 9033 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 9034 | } |
| 9035 | |
| 9036 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9037 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 9038 | assert(D && "no decl found"); |
| 9039 | if (D->isInvalidDecl()) return QualType(); |
| 9040 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9041 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9042 | TypeDecl *Ty; |
| 9043 | if (isa<UsingDecl>(D)) { |
| 9044 | UsingDecl *Using = cast<UsingDecl>(D); |
| 9045 | assert(Using->isTypeName() && |
| 9046 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 9047 | |
| 9048 | // A valid resolved using typename decl points to exactly one type decl. |
| 9049 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 9050 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 9051 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9052 | } else { |
| 9053 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 9054 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 9055 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 9056 | } |
| 9057 | |
| 9058 | return SemaRef.Context.getTypeDeclType(Ty); |
| 9059 | } |
| 9060 | |
| 9061 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9062 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 9063 | SourceLocation Loc) { |
| 9064 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9065 | } |
| 9066 | |
| 9067 | template<typename Derived> |
| 9068 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 9069 | return SemaRef.Context.getTypeOfType(Underlying); |
| 9070 | } |
| 9071 | |
| 9072 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9073 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 9074 | SourceLocation Loc) { |
| 9075 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9076 | } |
| 9077 | |
| 9078 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 9079 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 9080 | UnaryTransformType::UTTKind UKind, |
| 9081 | SourceLocation Loc) { |
| 9082 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 9083 | } |
| 9084 | |
| 9085 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9086 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 9087 | TemplateName Template, |
| 9088 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 9089 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9090 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9091 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9092 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 9093 | template<typename Derived> |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 9094 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 9095 | SourceLocation KWLoc) { |
| 9096 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 9097 | } |
| 9098 | |
| 9099 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9100 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9101 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9102 | bool TemplateKW, |
| 9103 | TemplateDecl *Template) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9104 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9105 | Template); |
| 9106 | } |
| 9107 | |
| 9108 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9109 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9110 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 9111 | const IdentifierInfo &Name, |
| 9112 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9113 | QualType ObjectType, |
| 9114 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9115 | UnqualifiedId TemplateName; |
| 9116 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9117 | Sema::TemplateTy Template; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9118 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9119 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9120 | SS, TemplateKWLoc, TemplateName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9121 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9122 | /*EnteringContext=*/false, |
| 9123 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9124 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9125 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9126 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9127 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9128 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9129 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9130 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9131 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9132 | QualType ObjectType) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9133 | UnqualifiedId Name; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9134 | // FIXME: Bogus location information. |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9135 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9136 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9137 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9138 | Sema::TemplateTy Template; |
| 9139 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9140 | SS, TemplateKWLoc, Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9141 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9142 | /*EnteringContext=*/false, |
| 9143 | Template); |
| 9144 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9145 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 9146 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9147 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9148 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9149 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 9150 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9151 | Expr *OrigCallee, |
| 9152 | Expr *First, |
| 9153 | Expr *Second) { |
| 9154 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 9155 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9156 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9157 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9158 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9159 | if (!First->getType()->isOverloadableType() && |
| 9160 | !Second->getType()->isOverloadableType()) |
| 9161 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 9162 | Callee->getLocStart(), |
| 9163 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 9164 | } else if (Op == OO_Arrow) { |
| 9165 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9166 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 9167 | } else if (Second == 0 || isPostIncDec) { |
| 9168 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9169 | // The argument is not of overloadable type, so try to create a |
| 9170 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9171 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9172 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9173 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9174 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9175 | } |
| 9176 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9177 | if (!First->getType()->isOverloadableType() && |
| 9178 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9179 | // Neither of the arguments is an overloadable type, so try to |
| 9180 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9181 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9182 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9183 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9184 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9185 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9186 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9187 | return move(Result); |
| 9188 | } |
| 9189 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9190 | |
| 9191 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9192 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9193 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9194 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9195 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9196 | assert(ULE->requiresADL()); |
| 9197 | |
| 9198 | // FIXME: Do we have to check |
| 9199 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9200 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9201 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9202 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9203 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9204 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9205 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9206 | Expr *Args[2] = { First, Second }; |
| 9207 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9208 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9209 | // Create the overloaded operator invocation for unary operators. |
| 9210 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9211 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9212 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9213 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9214 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9215 | |
Douglas Gregor | 5b8968c | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 9216 | if (Op == OO_Subscript) { |
| 9217 | SourceLocation LBrace; |
| 9218 | SourceLocation RBrace; |
| 9219 | |
| 9220 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 9221 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 9222 | LBrace = SourceLocation::getFromRawEncoding( |
| 9223 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 9224 | RBrace = SourceLocation::getFromRawEncoding( |
| 9225 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 9226 | } else { |
| 9227 | LBrace = Callee->getLocStart(); |
| 9228 | RBrace = OpLoc; |
| 9229 | } |
| 9230 | |
| 9231 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 9232 | First, Second); |
| 9233 | } |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9234 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9235 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9236 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9237 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9238 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 9239 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9240 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9241 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9242 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9243 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9244 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9245 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9246 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9247 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9248 | SourceLocation OperatorLoc, |
| 9249 | bool isArrow, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9250 | CXXScopeSpec &SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9251 | TypeSourceInfo *ScopeType, |
| 9252 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9253 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9254 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9255 | QualType BaseType = Base->getType(); |
| 9256 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9257 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 9258 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 9259 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 9260 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9261 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9262 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9263 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9264 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9265 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9266 | /*FIXME?*/true); |
| 9267 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9268 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9269 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9270 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 9271 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 9272 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 9273 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 9274 | |
Richard Smith | 6314db9 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 9275 | // The scope type is now known to be a valid nested name specifier |
| 9276 | // component. Tack it on to the end of the nested name specifier. |
| 9277 | if (ScopeType) |
| 9278 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 9279 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9280 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9281 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9282 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9283 | OperatorLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9284 | SS, TemplateKWLoc, |
| 9285 | /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9286 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9287 | /*TemplateArgs*/ 0); |
| 9288 | } |
| 9289 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9290 | } // end namespace clang |
| 9291 | |
| 9292 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |