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 | |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "TypeLocBuilder.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
John McCall | 7cd088e | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
| 23 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 24 | #include "clang/AST/Stmt.h" |
| 25 | #include "clang/AST/StmtCXX.h" |
| 26 | #include "clang/AST/StmtObjC.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 27 | #include "clang/Lex/Preprocessor.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Designator.h" |
| 29 | #include "clang/Sema/Lookup.h" |
| 30 | #include "clang/Sema/Ownership.h" |
| 31 | #include "clang/Sema/ParsedTemplate.h" |
| 32 | #include "clang/Sema/ScopeInfo.h" |
| 33 | #include "clang/Sema/SemaDiagnostic.h" |
| 34 | #include "clang/Sema/SemaInternal.h" |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/ArrayRef.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 36 | #include "llvm/Support/ErrorHandling.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; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 102 | public: |
| 103 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 104 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 105 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 106 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 107 | ~ForgetPartiallySubstitutedPackRAII() { |
| 108 | Self.RememberPartiallySubstitutedPack(Old); |
| 109 | } |
| 110 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 111 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 112 | protected: |
| 113 | Sema &SemaRef; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +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; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 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(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 180 | |
Douglas Gregor | ae201f7 | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 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 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +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 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 224 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 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 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 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) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 247 | /// must be set. |
| 248 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 249 | SourceRange PatternRange, |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 250 | 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, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 253 | Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 254 | ShouldExpand = false; |
| 255 | return false; |
| 256 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 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 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 266 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 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) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 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) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 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 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 326 | /// \brief Transform the given initializer. |
| 327 | /// |
| 328 | /// By default, this routine transforms an initializer by stripping off the |
| 329 | /// semantic nodes added by initialization, then passing the result to |
| 330 | /// TransformExpr or TransformExprs. |
| 331 | /// |
| 332 | /// \returns the transformed initializer. |
| 333 | ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit); |
| 334 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 335 | /// \brief Transform the given list of expressions. |
| 336 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 337 | /// This routine transforms a list of expressions by invoking |
| 338 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 339 | /// support for variadic templates by expanding any pack expansions (if the |
| 340 | /// derived class permits such expansion) along the way. When pack expansions |
| 341 | /// are present, the number of outputs may not equal the number of inputs. |
| 342 | /// |
| 343 | /// \param Inputs The set of expressions to be transformed. |
| 344 | /// |
| 345 | /// \param NumInputs The number of expressions in \c Inputs. |
| 346 | /// |
| 347 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 348 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 349 | /// be. |
| 350 | /// |
| 351 | /// \param Outputs The transformed input expressions will be added to this |
| 352 | /// vector. |
| 353 | /// |
| 354 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 355 | /// due to transformation. |
| 356 | /// |
| 357 | /// \returns true if an error occurred, false otherwise. |
| 358 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 359 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 360 | bool *ArgChanged = 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 361 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 362 | /// \brief Transform the given declaration, which is referenced from a type |
| 363 | /// or expression. |
| 364 | /// |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 365 | /// By default, acts as the identity function on declarations, unless the |
| 366 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 367 | /// may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 368 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 369 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 370 | = TransformedLocalDecls.find(D); |
| 371 | if (Known != TransformedLocalDecls.end()) |
| 372 | return Known->second; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 373 | |
| 374 | return D; |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 375 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 376 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 377 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 378 | /// place them on the new declaration. |
| 379 | /// |
| 380 | /// By default, this operation does nothing. Subclasses may override this |
| 381 | /// behavior to transform attributes. |
| 382 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 383 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 384 | /// \brief Note that a local declaration has been transformed by this |
| 385 | /// transformer. |
| 386 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 387 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 388 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 389 | /// the transformer itself has to transform the declarations. This routine |
| 390 | /// can be overridden by a subclass that keeps track of such mappings. |
| 391 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 392 | TransformedLocalDecls[Old] = New; |
| 393 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 394 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 395 | /// \brief Transform the definition of the given declaration. |
| 396 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 398 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 399 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 400 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 401 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 402 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 403 | /// \brief Transform the given declaration, which was the first part of a |
| 404 | /// nested-name-specifier in a member access expression. |
| 405 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 406 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 407 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 408 | /// the \c T in \c x->T::member |
| 409 | /// |
| 410 | /// By default, invokes TransformDecl() to transform the declaration. |
| 411 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 412 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 413 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 414 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 415 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 416 | /// \brief Transform the given nested-name-specifier with source-location |
| 417 | /// information. |
| 418 | /// |
| 419 | /// By default, transforms all of the types and declarations within the |
| 420 | /// nested-name-specifier. Subclasses may override this function to provide |
| 421 | /// alternate behavior. |
| 422 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 423 | NestedNameSpecifierLoc NNS, |
| 424 | QualType ObjectType = QualType(), |
| 425 | NamedDecl *FirstQualifierInScope = 0); |
| 426 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 427 | /// \brief Transform the given declaration name. |
| 428 | /// |
| 429 | /// By default, transforms the types of conversion function, constructor, |
| 430 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 431 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 432 | /// override this function to provide alternate behavior. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 433 | DeclarationNameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 434 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 436 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | /// |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 438 | /// \param SS The nested-name-specifier that qualifies the template |
| 439 | /// name. This nested-name-specifier must already have been transformed. |
| 440 | /// |
| 441 | /// \param Name The template name to transform. |
| 442 | /// |
| 443 | /// \param NameLoc The source location of the template name. |
| 444 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 445 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 446 | /// access expression, this is the type of the object whose member template |
| 447 | /// is being referenced. |
| 448 | /// |
| 449 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 450 | /// also refers to a name within the current (lexical) scope, this is the |
| 451 | /// declaration it refers to. |
| 452 | /// |
| 453 | /// By default, transforms the template name by transforming the declarations |
| 454 | /// and nested-name-specifiers that occur within the template name. |
| 455 | /// Subclasses may override this function to provide alternate behavior. |
| 456 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 457 | TemplateName Name, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 458 | SourceLocation NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 459 | QualType ObjectType = QualType(), |
| 460 | NamedDecl *FirstQualifierInScope = 0); |
| 461 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | /// \brief Transform the given template argument. |
| 463 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 464 | /// By default, this operation transforms the type, expression, or |
| 465 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 466 | /// new template argument from the transformed result. Subclasses may |
| 467 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 468 | /// |
| 469 | /// Returns true if there was an error. |
| 470 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 471 | TemplateArgumentLoc &Output); |
| 472 | |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 473 | /// \brief Transform the given set of template arguments. |
| 474 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 475 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 476 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 477 | /// the transformed arguments to the output list. |
| 478 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 479 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 480 | /// a convenience function. Subclasses that wish to override this behavior |
| 481 | /// should override the iterator-based member template version. |
| 482 | /// |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 483 | /// \param Inputs The set of template arguments to be transformed. |
| 484 | /// |
| 485 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 486 | /// |
| 487 | /// \param Outputs The set of transformed template arguments output by this |
| 488 | /// routine. |
| 489 | /// |
| 490 | /// Returns true if an error occurred. |
| 491 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 492 | unsigned NumInputs, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 493 | TemplateArgumentListInfo &Outputs) { |
| 494 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 495 | } |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 496 | |
| 497 | /// \brief Transform the given set of template arguments. |
| 498 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 499 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 500 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 501 | /// the transformed arguments to the output list. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 502 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 503 | /// \param First An iterator to the first template argument. |
| 504 | /// |
| 505 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 506 | /// |
| 507 | /// \param Outputs The set of transformed template arguments output by this |
| 508 | /// routine. |
| 509 | /// |
| 510 | /// Returns true if an error occurred. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 511 | template<typename InputIterator> |
| 512 | bool TransformTemplateArguments(InputIterator First, |
| 513 | InputIterator Last, |
| 514 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 515 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 516 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 517 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 518 | TemplateArgumentLoc &ArgLoc); |
| 519 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 520 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 521 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 522 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 523 | getDerived().getBaseLocation()); |
| 524 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 526 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 527 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 528 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 529 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 531 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 532 | FunctionProtoTypeLoc TL, |
| 533 | CXXRecordDecl *ThisContext, |
| 534 | unsigned ThisTypeQuals); |
| 535 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 536 | StmtResult |
| 537 | TransformSEHHandler(Stmt *Handler); |
| 538 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 539 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 540 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 541 | TemplateSpecializationTypeLoc TL, |
| 542 | TemplateName Template); |
| 543 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 544 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 545 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 546 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 547 | TemplateName Template, |
| 548 | CXXScopeSpec &SS); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 549 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 550 | QualType |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 551 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 552 | DependentTemplateSpecializationTypeLoc TL, |
| 553 | NestedNameSpecifierLoc QualifierLoc); |
| 554 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 555 | /// \brief Transforms the parameters of a function type into the |
| 556 | /// given vectors. |
| 557 | /// |
| 558 | /// The result vectors should be kept in sync; null entries in the |
| 559 | /// variables vector are acceptable. |
| 560 | /// |
| 561 | /// Return true on error. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 562 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 563 | ParmVarDecl **Params, unsigned NumParams, |
| 564 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 565 | SmallVectorImpl<QualType> &PTypes, |
| 566 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 567 | |
| 568 | /// \brief Transforms a single function-type parameter. Return null |
| 569 | /// on error. |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 570 | /// |
| 571 | /// \param indexAdjustment - A number to add to the parameter's |
| 572 | /// scope index; can be negative |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 573 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 574 | int indexAdjustment, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 575 | Optional<unsigned> NumExpansions, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 576 | bool ExpectParameterPack); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 577 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 578 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 579 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 580 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 581 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 583 | /// \brief Transform the captures and body of a lambda expression. |
| 584 | ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator); |
| 585 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 586 | ExprResult TransformAddressOfOperand(Expr *E); |
| 587 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| 588 | bool IsAddressOfOperand); |
| 589 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 590 | #define STMT(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 591 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 592 | #define EXPR(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 593 | ExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 594 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 595 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 596 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 597 | /// \brief Build a new pointer type given its pointee type. |
| 598 | /// |
| 599 | /// By default, performs semantic analysis when building the pointer type. |
| 600 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 601 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 602 | |
| 603 | /// \brief Build a new block pointer type given its pointee type. |
| 604 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 606 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 607 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 608 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 609 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 610 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 611 | /// By default, performs semantic analysis when building the |
| 612 | /// reference type. Subclasses may override this routine to provide |
| 613 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 614 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 615 | /// \param LValue whether the type was written with an lvalue sigil |
| 616 | /// or an rvalue sigil. |
| 617 | QualType RebuildReferenceType(QualType ReferentType, |
| 618 | bool LValue, |
| 619 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 620 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 621 | /// \brief Build a new member pointer type given the pointee type and the |
| 622 | /// class type it refers into. |
| 623 | /// |
| 624 | /// By default, performs semantic analysis when building the member pointer |
| 625 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 626 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 627 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 629 | /// \brief Build a new array type given the element type, size |
| 630 | /// modifier, size of the array (if known), size expression, and index type |
| 631 | /// qualifiers. |
| 632 | /// |
| 633 | /// By default, performs semantic analysis when building the array type. |
| 634 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 636 | QualType RebuildArrayType(QualType ElementType, |
| 637 | ArrayType::ArraySizeModifier SizeMod, |
| 638 | const llvm::APInt *Size, |
| 639 | Expr *SizeExpr, |
| 640 | unsigned IndexTypeQuals, |
| 641 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 642 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 643 | /// \brief Build a new constant array type given the element type, size |
| 644 | /// modifier, (known) size of the array, and index type qualifiers. |
| 645 | /// |
| 646 | /// By default, performs semantic analysis when building the array type. |
| 647 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 648 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 649 | ArrayType::ArraySizeModifier SizeMod, |
| 650 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 651 | unsigned IndexTypeQuals, |
| 652 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 653 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 654 | /// \brief Build a new incomplete array type given the element type, size |
| 655 | /// modifier, and index type qualifiers. |
| 656 | /// |
| 657 | /// By default, performs semantic analysis when building the array type. |
| 658 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 659 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 660 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 661 | unsigned IndexTypeQuals, |
| 662 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 663 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 665 | /// size modifier, size expression, and index type qualifiers. |
| 666 | /// |
| 667 | /// By default, performs semantic analysis when building the array type. |
| 668 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 670 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 671 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 672 | unsigned IndexTypeQuals, |
| 673 | SourceRange BracketsRange); |
| 674 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 675 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 676 | /// size modifier, size expression, and index type qualifiers. |
| 677 | /// |
| 678 | /// By default, performs semantic analysis when building the array type. |
| 679 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 680 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 681 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 682 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 683 | unsigned IndexTypeQuals, |
| 684 | SourceRange BracketsRange); |
| 685 | |
| 686 | /// \brief Build a new vector type given the element type and |
| 687 | /// 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. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 691 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 692 | VectorType::VectorKind VecKind); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 693 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 694 | /// \brief Build a new extended vector type given the element type and |
| 695 | /// number of elements. |
| 696 | /// |
| 697 | /// By default, performs semantic analysis when building the vector type. |
| 698 | /// Subclasses may override this routine to provide different behavior. |
| 699 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 700 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
| 702 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 703 | /// given the element type and number of elements. |
| 704 | /// |
| 705 | /// By default, performs semantic analysis when building the vector type. |
| 706 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 708 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 709 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 711 | /// \brief Build a new function type. |
| 712 | /// |
| 713 | /// By default, performs semantic analysis when building the function type. |
| 714 | /// Subclasses may override this routine to provide different behavior. |
| 715 | QualType RebuildFunctionProtoType(QualType T, |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 716 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 717 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 719 | /// \brief Build a new unprototyped function type. |
| 720 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 721 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 722 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 723 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 724 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 725 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 726 | /// \brief Build a new typedef type. |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 727 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 728 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 729 | } |
| 730 | |
| 731 | /// \brief Build a new class/struct/union type. |
| 732 | QualType RebuildRecordType(RecordDecl *Record) { |
| 733 | return SemaRef.Context.getTypeDeclType(Record); |
| 734 | } |
| 735 | |
| 736 | /// \brief Build a new Enum type. |
| 737 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 738 | return SemaRef.Context.getTypeDeclType(Enum); |
| 739 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 740 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 742 | /// |
| 743 | /// By default, performs semantic analysis when building the typeof type. |
| 744 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 745 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 746 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 747 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 748 | /// |
| 749 | /// By default, builds a new TypeOfType with the given underlying type. |
| 750 | QualType RebuildTypeOfType(QualType Underlying); |
| 751 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 752 | /// \brief Build a new unary transform type. |
| 753 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 754 | UnaryTransformType::UTTKind UKind, |
| 755 | SourceLocation Loc); |
| 756 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 758 | /// |
| 759 | /// By default, performs semantic analysis when building the decltype type. |
| 760 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 761 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 763 | /// \brief Build a new C++0x auto type. |
| 764 | /// |
| 765 | /// By default, builds a new AutoType with the given deduced type. |
| 766 | QualType RebuildAutoType(QualType Deduced) { |
| 767 | return SemaRef.Context.getAutoType(Deduced); |
| 768 | } |
| 769 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 770 | /// \brief Build a new template specialization type. |
| 771 | /// |
| 772 | /// By default, performs semantic analysis when building the template |
| 773 | /// specialization type. Subclasses may override this routine to provide |
| 774 | /// different behavior. |
| 775 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 776 | SourceLocation TemplateLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 777 | TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 779 | /// \brief Build a new parenthesized type. |
| 780 | /// |
| 781 | /// By default, builds a new ParenType type from the inner type. |
| 782 | /// Subclasses may override this routine to provide different behavior. |
| 783 | QualType RebuildParenType(QualType InnerType) { |
| 784 | return SemaRef.Context.getParenType(InnerType); |
| 785 | } |
| 786 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 787 | /// \brief Build a new qualified name type. |
| 788 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 789 | /// By default, builds a new ElaboratedType type from the keyword, |
| 790 | /// the nested-name-specifier and the named type. |
| 791 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 792 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 793 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 794 | NestedNameSpecifierLoc QualifierLoc, |
| 795 | QualType Named) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 796 | return SemaRef.Context.getElaboratedType(Keyword, |
| 797 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 798 | Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 800 | |
| 801 | /// \brief Build a new typename type that refers to a template-id. |
| 802 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 803 | /// By default, builds a new DependentNameType type from the |
| 804 | /// nested-name-specifier and the given type. Subclasses may override |
| 805 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 806 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 807 | ElaboratedTypeKeyword Keyword, |
| 808 | NestedNameSpecifierLoc QualifierLoc, |
| 809 | const IdentifierInfo *Name, |
| 810 | SourceLocation NameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 811 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 812 | // Rebuild the template name. |
| 813 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 814 | CXXScopeSpec SS; |
| 815 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 816 | TemplateName InstName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 817 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 818 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 819 | if (InstName.isNull()) |
| 820 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 821 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 822 | // If it's still dependent, make a dependent specialization. |
| 823 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 824 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 825 | QualifierLoc.getNestedNameSpecifier(), |
| 826 | Name, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 827 | Args); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 828 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 829 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 830 | // specialization. |
| 831 | QualType T = |
| 832 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 833 | if (T.isNull()) return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 834 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 835 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 836 | return T; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 837 | |
| 838 | return SemaRef.Context.getElaboratedType(Keyword, |
| 839 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 840 | T); |
| 841 | } |
| 842 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 843 | /// \brief Build a new typename type that refers to an identifier. |
| 844 | /// |
| 845 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 846 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 847 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 848 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 849 | SourceLocation KeywordLoc, |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 850 | NestedNameSpecifierLoc QualifierLoc, |
| 851 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 852 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 853 | CXXScopeSpec SS; |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 854 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 855 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 856 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 857 | // If the name is still dependent, just build a new dependent name type. |
| 858 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 859 | return SemaRef.Context.getDependentNameType(Keyword, |
| 860 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 861 | Id); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 864 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 865 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | e29425b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 866 | *Id, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 867 | |
| 868 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 869 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 870 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 871 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 872 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 873 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 874 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 875 | if (!DC) |
| 876 | return QualType(); |
| 877 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 878 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 879 | return QualType(); |
| 880 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 881 | TagDecl *Tag = 0; |
| 882 | SemaRef.LookupQualifiedName(Result, DC); |
| 883 | switch (Result.getResultKind()) { |
| 884 | case LookupResult::NotFound: |
| 885 | case LookupResult::NotFoundInCurrentInstantiation: |
| 886 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 887 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 888 | case LookupResult::Found: |
| 889 | Tag = Result.getAsSingle<TagDecl>(); |
| 890 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 891 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 892 | case LookupResult::FoundOverloaded: |
| 893 | case LookupResult::FoundUnresolvedValue: |
| 894 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 895 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 896 | case LookupResult::Ambiguous: |
| 897 | // Let the LookupResult structure handle ambiguities. |
| 898 | return QualType(); |
| 899 | } |
| 900 | |
| 901 | if (!Tag) { |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 902 | // Check where the name exists but isn't a tag type and use that to emit |
| 903 | // better diagnostics. |
| 904 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 905 | SemaRef.LookupQualifiedName(Result, DC); |
| 906 | switch (Result.getResultKind()) { |
| 907 | case LookupResult::Found: |
| 908 | case LookupResult::FoundOverloaded: |
| 909 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 910 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 911 | unsigned Kind = 0; |
| 912 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 913 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 914 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 915 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 916 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 917 | break; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 918 | } |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 919 | default: |
| 920 | // FIXME: Would be nice to highlight just the source range. |
| 921 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 922 | << Kind << Id << DC; |
| 923 | break; |
| 924 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 925 | return QualType(); |
| 926 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 927 | |
Richard Trieu | bbf34c0 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 928 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 929 | IdLoc, *Id)) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 930 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 931 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 932 | return QualType(); |
| 933 | } |
| 934 | |
| 935 | // Build the elaborated-type-specifier type. |
| 936 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 937 | return SemaRef.Context.getElaboratedType(Keyword, |
| 938 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 939 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 940 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 941 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 942 | /// \brief Build a new pack expansion type. |
| 943 | /// |
| 944 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 945 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 946 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 947 | SourceRange PatternRange, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 948 | SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 949 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 950 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 951 | NumExpansions); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 954 | /// \brief Build a new atomic type given its value type. |
| 955 | /// |
| 956 | /// By default, performs semantic analysis when building the atomic type. |
| 957 | /// Subclasses may override this routine to provide different behavior. |
| 958 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 959 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 960 | /// \brief Build a new template name given a nested name specifier, a flag |
| 961 | /// indicating whether the "template" keyword was provided, and the template |
| 962 | /// that the template name refers to. |
| 963 | /// |
| 964 | /// By default, builds the new template name directly. Subclasses may override |
| 965 | /// this routine to provide different behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 966 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 967 | bool TemplateKW, |
| 968 | TemplateDecl *Template); |
| 969 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 970 | /// \brief Build a new template name given a nested name specifier and the |
| 971 | /// name that is referred to as a template. |
| 972 | /// |
| 973 | /// By default, performs semantic analysis to determine whether the name can |
| 974 | /// be resolved to a specific template, then builds the appropriate kind of |
| 975 | /// template name. Subclasses may override this routine to provide different |
| 976 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 977 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 978 | const IdentifierInfo &Name, |
| 979 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 980 | QualType ObjectType, |
| 981 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 982 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 983 | /// \brief Build a new template name given a nested name specifier and the |
| 984 | /// overloaded operator name that is referred to as a template. |
| 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. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 990 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 991 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 992 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 993 | QualType ObjectType); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 994 | |
| 995 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 996 | /// and the |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 997 | /// |
| 998 | /// By default, performs semantic analysis to determine whether the name can |
| 999 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1000 | /// template name. Subclasses may override this routine to provide different |
| 1001 | /// behavior. |
| 1002 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1003 | const TemplateArgument &ArgPack) { |
| 1004 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1005 | } |
| 1006 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1007 | /// \brief Build a new compound 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 RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1012 | MultiStmtArg Statements, |
| 1013 | SourceLocation RBraceLoc, |
| 1014 | bool IsStmtExpr) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1015 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1016 | IsStmtExpr); |
| 1017 | } |
| 1018 | |
| 1019 | /// \brief Build a new case statement. |
| 1020 | /// |
| 1021 | /// By default, performs semantic analysis to build the new statement. |
| 1022 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1023 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1024 | Expr *LHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1025 | SourceLocation EllipsisLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1026 | Expr *RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1027 | SourceLocation ColonLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1028 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1029 | ColonLoc); |
| 1030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1031 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1032 | /// \brief Attach the body to a new case statement. |
| 1033 | /// |
| 1034 | /// By default, performs semantic analysis to build the new statement. |
| 1035 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1036 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1037 | getSema().ActOnCaseStmtBody(S, Body); |
| 1038 | return S; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1039 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1041 | /// \brief Build a new default statement. |
| 1042 | /// |
| 1043 | /// By default, performs semantic analysis to build the new statement. |
| 1044 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1045 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1046 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1047 | Stmt *SubStmt) { |
| 1048 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1049 | /*CurScope=*/0); |
| 1050 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1051 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1052 | /// \brief Build a new label statement. |
| 1053 | /// |
| 1054 | /// By default, performs semantic analysis to build the new statement. |
| 1055 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1056 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1057 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1058 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1059 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1061 | /// \brief Build a new label statement. |
| 1062 | /// |
| 1063 | /// By default, performs semantic analysis to build the new statement. |
| 1064 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1065 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1066 | ArrayRef<const Attr*> Attrs, |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1067 | Stmt *SubStmt) { |
| 1068 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1069 | } |
| 1070 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1071 | /// \brief Build a new "if" statement. |
| 1072 | /// |
| 1073 | /// By default, performs semantic analysis to build the new statement. |
| 1074 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1075 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1076 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1077 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1078 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1079 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1081 | /// \brief Start building a new switch statement. |
| 1082 | /// |
| 1083 | /// By default, performs semantic analysis to build the new statement. |
| 1084 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1085 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1086 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1087 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1088 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1089 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1091 | /// \brief Attach the body to the switch statement. |
| 1092 | /// |
| 1093 | /// By default, performs semantic analysis to build the new statement. |
| 1094 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1095 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1096 | Stmt *Switch, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1097 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /// \brief Build a new while statement. |
| 1101 | /// |
| 1102 | /// By default, performs semantic analysis to build the new statement. |
| 1103 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1104 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1105 | VarDecl *CondVar, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1106 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1107 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1109 | /// \brief Build a new do-while statement. |
| 1110 | /// |
| 1111 | /// By default, performs semantic analysis to build the new statement. |
| 1112 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1113 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1114 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1115 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1116 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1117 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | /// \brief Build a new for statement. |
| 1121 | /// |
| 1122 | /// By default, performs semantic analysis to build the new statement. |
| 1123 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1124 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1125 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1126 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1127 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1128 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1129 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1130 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1132 | /// \brief Build a new goto statement. |
| 1133 | /// |
| 1134 | /// By default, performs semantic analysis to build the new statement. |
| 1135 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1136 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1137 | LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1138 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /// \brief Build a new indirect goto statement. |
| 1142 | /// |
| 1143 | /// By default, performs semantic analysis to build the new statement. |
| 1144 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1145 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1146 | SourceLocation StarLoc, |
| 1147 | Expr *Target) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1148 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1151 | /// \brief Build a new return statement. |
| 1152 | /// |
| 1153 | /// By default, performs semantic analysis to build the new statement. |
| 1154 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1155 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1156 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1159 | /// \brief Build a new declaration statement. |
| 1160 | /// |
| 1161 | /// By default, performs semantic analysis to build the new statement. |
| 1162 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1163 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1165 | SourceLocation EndLoc) { |
Richard Smith | 406c38e | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1166 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1167 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1168 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1170 | /// \brief Build a new inline asm statement. |
| 1171 | /// |
| 1172 | /// By default, performs semantic analysis to build the new statement. |
| 1173 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1174 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1175 | bool IsVolatile, unsigned NumOutputs, |
| 1176 | unsigned NumInputs, IdentifierInfo **Names, |
| 1177 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1178 | Expr *AsmString, MultiExprArg Clobbers, |
| 1179 | SourceLocation RParenLoc) { |
| 1180 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1181 | NumInputs, Names, Constraints, Exprs, |
| 1182 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1183 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1184 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1185 | /// \brief Build a new MS style inline asm statement. |
| 1186 | /// |
| 1187 | /// By default, performs semantic analysis to build the new statement. |
| 1188 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1189 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
| 1190 | ArrayRef<Token> AsmToks, SourceLocation EndLoc) { |
Chad Rosier | 7bd092b | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 1191 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1194 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1195 | /// |
| 1196 | /// By default, performs semantic analysis to build the new statement. |
| 1197 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1198 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1199 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1200 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1201 | Stmt *Finally) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1202 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1203 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1206 | /// \brief Rebuild an Objective-C exception declaration. |
| 1207 | /// |
| 1208 | /// By default, performs semantic analysis to build the new declaration. |
| 1209 | /// Subclasses may override this routine to provide different behavior. |
| 1210 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1211 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1212 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1213 | ExceptionDecl->getInnerLocStart(), |
| 1214 | ExceptionDecl->getLocation(), |
| 1215 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1216 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1217 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1218 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1219 | /// |
| 1220 | /// By default, performs semantic analysis to build the new statement. |
| 1221 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1222 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1223 | SourceLocation RParenLoc, |
| 1224 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1225 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1226 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1227 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1228 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1229 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1230 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1231 | /// |
| 1232 | /// By default, performs semantic analysis to build the new statement. |
| 1233 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1234 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1235 | Stmt *Body) { |
| 1236 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1237 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1238 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1239 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1240 | /// |
| 1241 | /// By default, performs semantic analysis to build the new statement. |
| 1242 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1243 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1244 | Expr *Operand) { |
| 1245 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1246 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1247 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1248 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1249 | /// |
| 1250 | /// By default, performs semantic analysis to build the new statement. |
| 1251 | /// Subclasses may override this routine to provide different behavior. |
| 1252 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1253 | Expr *object) { |
| 1254 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1255 | } |
| 1256 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1257 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1258 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1259 | /// By default, performs semantic analysis to build the new statement. |
| 1260 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1261 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1262 | Expr *Object, Stmt *Body) { |
| 1263 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1264 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1265 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1266 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1267 | /// |
| 1268 | /// By default, performs semantic analysis to build the new statement. |
| 1269 | /// Subclasses may override this routine to provide different behavior. |
| 1270 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1271 | Stmt *Body) { |
| 1272 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1273 | } |
John McCall | 990567c | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1274 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1275 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1276 | /// |
| 1277 | /// By default, performs semantic analysis to build the new statement. |
| 1278 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1279 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1280 | Stmt *Element, |
| 1281 | Expr *Collection, |
| 1282 | SourceLocation RParenLoc, |
| 1283 | Stmt *Body) { |
Sam Panzer | bc20bbb | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1284 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1285 | Element, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1286 | Collection, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1287 | RParenLoc); |
| 1288 | if (ForEachStmt.isInvalid()) |
| 1289 | return StmtError(); |
| 1290 | |
| 1291 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1292 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1293 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1294 | /// \brief Build a new C++ exception declaration. |
| 1295 | /// |
| 1296 | /// By default, performs semantic analysis to build the new decaration. |
| 1297 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1298 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1299 | TypeSourceInfo *Declarator, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1300 | SourceLocation StartLoc, |
| 1301 | SourceLocation IdLoc, |
| 1302 | IdentifierInfo *Id) { |
Douglas Gregor | efdf988 | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1303 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1304 | StartLoc, IdLoc, Id); |
| 1305 | if (Var) |
| 1306 | getSema().CurContext->addDecl(Var); |
| 1307 | return Var; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | /// \brief Build a new C++ catch statement. |
| 1311 | /// |
| 1312 | /// By default, performs semantic analysis to build the new statement. |
| 1313 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1314 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1315 | VarDecl *ExceptionDecl, |
| 1316 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1317 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1318 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1319 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1321 | /// \brief Build a new C++ try statement. |
| 1322 | /// |
| 1323 | /// By default, performs semantic analysis to build the new statement. |
| 1324 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1325 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1326 | Stmt *TryBlock, |
| 1327 | MultiStmtArg Handlers) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1328 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1329 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1331 | /// \brief Build a new C++0x range-based for statement. |
| 1332 | /// |
| 1333 | /// By default, performs semantic analysis to build the new statement. |
| 1334 | /// Subclasses may override this routine to provide different behavior. |
| 1335 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1336 | SourceLocation ColonLoc, |
| 1337 | Stmt *Range, Stmt *BeginEnd, |
| 1338 | Expr *Cond, Expr *Inc, |
| 1339 | Stmt *LoopVar, |
| 1340 | SourceLocation RParenLoc) { |
Douglas Gregor | 6f96f4b | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1341 | // If we've just learned that the range is actually an Objective-C |
| 1342 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1343 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1344 | if (RangeStmt->isSingleDecl()) { |
| 1345 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
| 1346 | Expr *RangeExpr = RangeVar->getInit(); |
| 1347 | if (!RangeExpr->isTypeDependent() && |
| 1348 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1349 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1350 | RParenLoc); |
| 1351 | } |
| 1352 | } |
| 1353 | } |
| 1354 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1355 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | 8b533d9 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1356 | Cond, Inc, LoopVar, RParenLoc, |
| 1357 | Sema::BFRK_Rebuild); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1358 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1359 | |
| 1360 | /// \brief Build a new C++0x range-based for statement. |
| 1361 | /// |
| 1362 | /// By default, performs semantic analysis to build the new statement. |
| 1363 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1364 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1365 | bool IsIfExists, |
| 1366 | NestedNameSpecifierLoc QualifierLoc, |
| 1367 | DeclarationNameInfo NameInfo, |
| 1368 | Stmt *Nested) { |
| 1369 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1370 | QualifierLoc, NameInfo, Nested); |
| 1371 | } |
| 1372 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1373 | /// \brief Attach body to a C++0x range-based for statement. |
| 1374 | /// |
| 1375 | /// By default, performs semantic analysis to finish the new statement. |
| 1376 | /// Subclasses may override this routine to provide different behavior. |
| 1377 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1378 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1379 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1380 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1381 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, |
| 1382 | SourceLocation TryLoc, |
| 1383 | Stmt *TryBlock, |
| 1384 | Stmt *Handler) { |
| 1385 | return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1386 | } |
| 1387 | |
| 1388 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, |
| 1389 | Expr *FilterExpr, |
| 1390 | Stmt *Block) { |
| 1391 | return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); |
| 1392 | } |
| 1393 | |
| 1394 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, |
| 1395 | Stmt *Block) { |
| 1396 | return getSema().ActOnSEHFinallyBlock(Loc,Block); |
| 1397 | } |
| 1398 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | /// \brief Build a new expression that references a declaration. |
| 1400 | /// |
| 1401 | /// By default, performs semantic analysis to build the new expression. |
| 1402 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1403 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1404 | LookupResult &R, |
| 1405 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1406 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1407 | } |
| 1408 | |
| 1409 | |
| 1410 | /// \brief Build a new expression that references a declaration. |
| 1411 | /// |
| 1412 | /// By default, performs semantic analysis to build the new expression. |
| 1413 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1414 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1415 | ValueDecl *VD, |
| 1416 | const DeclarationNameInfo &NameInfo, |
| 1417 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1418 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1419 | SS.Adopt(QualifierLoc); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1420 | |
| 1421 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1422 | |
| 1423 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1424 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | /// By default, performs semantic analysis to build the new expression. |
| 1429 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1430 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1431 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1432 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1435 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1436 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1437 | /// By default, performs semantic analysis to build the new expression. |
| 1438 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1439 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1440 | SourceLocation OperatorLoc, |
| 1441 | bool isArrow, |
| 1442 | CXXScopeSpec &SS, |
| 1443 | TypeSourceInfo *ScopeType, |
| 1444 | SourceLocation CCLoc, |
| 1445 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1446 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1448 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1449 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1450 | /// By default, performs semantic analysis to build the new expression. |
| 1451 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1452 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1453 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1454 | Expr *SubExpr) { |
| 1455 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1457 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1458 | /// \brief Build a new builtin offsetof expression. |
| 1459 | /// |
| 1460 | /// By default, performs semantic analysis to build the new expression. |
| 1461 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1462 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1463 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1464 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1465 | unsigned NumComponents, |
| 1466 | SourceLocation RParenLoc) { |
| 1467 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1468 | NumComponents, RParenLoc); |
| 1469 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1470 | |
| 1471 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1472 | /// type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1473 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1474 | /// By default, performs semantic analysis to build the new expression. |
| 1475 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1476 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1477 | SourceLocation OpLoc, |
| 1478 | UnaryExprOrTypeTrait ExprKind, |
| 1479 | SourceRange R) { |
| 1480 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1483 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1484 | /// expression argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1485 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1486 | /// By default, performs semantic analysis to build the new expression. |
| 1487 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1488 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1489 | UnaryExprOrTypeTrait ExprKind, |
| 1490 | SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1491 | ExprResult Result |
Chandler Carruth | e72c55b | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1492 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1494 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1495 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1496 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1497 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1498 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1499 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1500 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1501 | /// By default, performs semantic analysis to build the new expression. |
| 1502 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1503 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1504 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1505 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1506 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1507 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1508 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1509 | RBracketLoc); |
| 1510 | } |
| 1511 | |
| 1512 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1513 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1514 | /// By default, performs semantic analysis to build the new expression. |
| 1515 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1516 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1517 | MultiExprArg Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1518 | SourceLocation RParenLoc, |
| 1519 | Expr *ExecConfig = 0) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1520 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1521 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1525 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1526 | /// By default, performs semantic analysis to build the new expression. |
| 1527 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1528 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1529 | bool isArrow, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1530 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1531 | SourceLocation TemplateKWLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1532 | const DeclarationNameInfo &MemberNameInfo, |
| 1533 | ValueDecl *Member, |
| 1534 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1535 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1536 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1537 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1538 | isArrow); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1539 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1540 | // We have a reference to an unnamed field. This is always the |
| 1541 | // base of an anonymous struct/union member access, i.e. the |
| 1542 | // field is always of record type. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1543 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1544 | assert(Member->getType()->isRecordType() && |
| 1545 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1546 | |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1547 | BaseResult = |
| 1548 | getSema().PerformObjectMemberConversion(BaseResult.take(), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1549 | QualifierLoc.getNestedNameSpecifier(), |
| 1550 | FoundDecl, Member); |
| 1551 | if (BaseResult.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1552 | return ExprError(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1553 | Base = BaseResult.take(); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1554 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1555 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1556 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1557 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1558 | cast<FieldDecl>(Member)->getType(), |
| 1559 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1560 | return getSema().Owned(ME); |
| 1561 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1562 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1563 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1564 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1565 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1566 | Base = BaseResult.take(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1567 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1568 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1569 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1570 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1571 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1572 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1573 | R.resolveKind(); |
| 1574 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1575 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1576 | SS, TemplateKWLoc, |
| 1577 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1578 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1580 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1581 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1582 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | /// By default, performs semantic analysis to build the new expression. |
| 1584 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1585 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1586 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1587 | Expr *LHS, Expr *RHS) { |
| 1588 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | /// By default, performs semantic analysis to build the new expression. |
| 1594 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1595 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1596 | SourceLocation QuestionLoc, |
| 1597 | Expr *LHS, |
| 1598 | SourceLocation ColonLoc, |
| 1599 | Expr *RHS) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1600 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1601 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1605 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1606 | /// By default, performs semantic analysis to build the new expression. |
| 1607 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1608 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1609 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1610 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1611 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1612 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1613 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1615 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1617 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1618 | /// By default, performs semantic analysis to build the new expression. |
| 1619 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1620 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1621 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1623 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1624 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1625 | Init); |
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 extended vector element access 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 RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1633 | SourceLocation OpLoc, |
| 1634 | SourceLocation AccessorLoc, |
| 1635 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1636 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1637 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1638 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1639 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1640 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1641 | SS, SourceLocation(), |
| 1642 | /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1643 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1644 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1646 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1648 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1649 | /// By default, performs semantic analysis to build the new expression. |
| 1650 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1651 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1652 | MultiExprArg Inits, |
| 1653 | SourceLocation RBraceLoc, |
| 1654 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1655 | ExprResult Result |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1656 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1657 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1658 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1659 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1660 | // Patch in the result type we were given, which may have been computed |
| 1661 | // when the initial InitListExpr was built. |
| 1662 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1663 | ILE->setType(ResultTy); |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1664 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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 designated initializer 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, performs semantic analysis to build the new expression. |
| 1670 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1671 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1672 | MultiExprArg ArrayExprs, |
| 1673 | SourceLocation EqualOrColonLoc, |
| 1674 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1675 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1676 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1677 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1678 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1679 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1680 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1681 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1682 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1685 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1686 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | /// By default, builds the implicit value initialization without performing |
| 1688 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1689 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1690 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1691 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1694 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1695 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | /// By default, performs semantic analysis to build the new expression. |
| 1697 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1698 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1699 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1700 | SourceLocation RParenLoc) { |
| 1701 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1702 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1703 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | /// \brief Build a new expression list in parentheses. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1709 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1710 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1711 | MultiExprArg SubExprs, |
| 1712 | SourceLocation RParenLoc) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1713 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1715 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1716 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1717 | /// |
| 1718 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1719 | /// rather than attempting to map the label statement itself. |
| 1720 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1721 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1722 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1723 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1725 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1726 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1727 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1728 | /// By default, performs semantic analysis to build the new expression. |
| 1729 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1730 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1731 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1733 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1735 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1736 | /// \brief Build a new __builtin_choose_expr expression. |
| 1737 | /// |
| 1738 | /// By default, performs semantic analysis to build the new expression. |
| 1739 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1740 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1741 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | SourceLocation RParenLoc) { |
| 1743 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1744 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1745 | RParenLoc); |
| 1746 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1747 | |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1748 | /// \brief Build a new generic selection expression. |
| 1749 | /// |
| 1750 | /// By default, performs semantic analysis to build the new expression. |
| 1751 | /// Subclasses may override this routine to provide different behavior. |
| 1752 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1753 | SourceLocation DefaultLoc, |
| 1754 | SourceLocation RParenLoc, |
| 1755 | Expr *ControllingExpr, |
| 1756 | TypeSourceInfo **Types, |
| 1757 | Expr **Exprs, |
| 1758 | unsigned NumAssocs) { |
| 1759 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 1760 | ControllingExpr, Types, Exprs, |
| 1761 | NumAssocs); |
| 1762 | } |
| 1763 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1764 | /// \brief Build a new overloaded operator call expression. |
| 1765 | /// |
| 1766 | /// By default, performs semantic analysis to build the new expression. |
| 1767 | /// The semantic analysis provides the behavior of template instantiation, |
| 1768 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1770 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1771 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1772 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1773 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1774 | Expr *Callee, |
| 1775 | Expr *First, |
| 1776 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | |
| 1778 | /// \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] | 1779 | /// reinterpret_cast. |
| 1780 | /// |
| 1781 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1783 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1784 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1785 | Stmt::StmtClass Class, |
| 1786 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1787 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1788 | SourceLocation RAngleLoc, |
| 1789 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1790 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1791 | SourceLocation RParenLoc) { |
| 1792 | switch (Class) { |
| 1793 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1794 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1795 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1796 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | |
| 1798 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1799 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1800 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1801 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1802 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1803 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1804 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1805 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1806 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1807 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1808 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1809 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1810 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1811 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1812 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1813 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1814 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1815 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1816 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1817 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1818 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1819 | /// \brief Build a new C++ static_cast expression. |
| 1820 | /// |
| 1821 | /// By default, performs semantic analysis to build the new expression. |
| 1822 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1823 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1824 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1825 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1826 | SourceLocation RAngleLoc, |
| 1827 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1828 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1829 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1830 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1831 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1832 | SourceRange(LAngleLoc, RAngleLoc), |
| 1833 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | /// \brief Build a new C++ dynamic_cast expression. |
| 1837 | /// |
| 1838 | /// By default, performs semantic analysis to build the new expression. |
| 1839 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1840 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1841 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1842 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1843 | SourceLocation RAngleLoc, |
| 1844 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1845 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1846 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1847 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1848 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1849 | SourceRange(LAngleLoc, RAngleLoc), |
| 1850 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1854 | /// |
| 1855 | /// By default, performs semantic analysis to build the new expression. |
| 1856 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1857 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1858 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1859 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1860 | SourceLocation RAngleLoc, |
| 1861 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1862 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1863 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1864 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1865 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1866 | SourceRange(LAngleLoc, RAngleLoc), |
| 1867 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | /// \brief Build a new C++ const_cast expression. |
| 1871 | /// |
| 1872 | /// By default, performs semantic analysis to build the new expression. |
| 1873 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1874 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1875 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1876 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1877 | SourceLocation RAngleLoc, |
| 1878 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1879 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1880 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1881 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1882 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1883 | SourceRange(LAngleLoc, RAngleLoc), |
| 1884 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1885 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1886 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1887 | /// \brief Build a new C++ functional-style cast expression. |
| 1888 | /// |
| 1889 | /// By default, performs semantic analysis to build the new expression. |
| 1890 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1891 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1892 | SourceLocation LParenLoc, |
| 1893 | Expr *Sub, |
| 1894 | SourceLocation RParenLoc) { |
| 1895 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1896 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1897 | RParenLoc); |
| 1898 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1899 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1900 | /// \brief Build a new C++ typeid(type) expression. |
| 1901 | /// |
| 1902 | /// By default, performs semantic analysis to build the new expression. |
| 1903 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1904 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1905 | SourceLocation TypeidLoc, |
| 1906 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1907 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1908 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1909 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1910 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1911 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1912 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1913 | /// \brief Build a new C++ typeid(expr) expression. |
| 1914 | /// |
| 1915 | /// By default, performs semantic analysis to build the new expression. |
| 1916 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1917 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1918 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1919 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1920 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1921 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1922 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1925 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1926 | /// |
| 1927 | /// By default, performs semantic analysis to build the new expression. |
| 1928 | /// Subclasses may override this routine to provide different behavior. |
| 1929 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1930 | SourceLocation TypeidLoc, |
| 1931 | TypeSourceInfo *Operand, |
| 1932 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1933 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1934 | RParenLoc); |
| 1935 | } |
| 1936 | |
| 1937 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1938 | /// |
| 1939 | /// By default, performs semantic analysis to build the new expression. |
| 1940 | /// Subclasses may override this routine to provide different behavior. |
| 1941 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1942 | SourceLocation TypeidLoc, |
| 1943 | Expr *Operand, |
| 1944 | SourceLocation RParenLoc) { |
| 1945 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1946 | RParenLoc); |
| 1947 | } |
| 1948 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | /// \brief Build a new C++ "this" expression. |
| 1950 | /// |
| 1951 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1952 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1953 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1954 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1955 | QualType ThisType, |
| 1956 | bool isImplicit) { |
Eli Friedman | b69b42c | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 1957 | getSema().CheckCXXThisCapture(ThisLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1958 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1959 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1960 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | /// \brief Build a new C++ throw expression. |
| 1964 | /// |
| 1965 | /// By default, performs semantic analysis to build the new expression. |
| 1966 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 1967 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 1968 | bool IsThrownVariableInScope) { |
| 1969 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | /// \brief Build a new C++ default-argument expression. |
| 1973 | /// |
| 1974 | /// By default, builds a new default-argument expression, which does not |
| 1975 | /// require any semantic analysis. Subclasses may override this routine to |
| 1976 | /// provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1977 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1978 | ParmVarDecl *Param) { |
| 1979 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1980 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 1983 | /// \brief Build a new C++11 default-initialization expression. |
| 1984 | /// |
| 1985 | /// By default, builds a new default field initialization expression, which |
| 1986 | /// does not require any semantic analysis. Subclasses may override this |
| 1987 | /// routine to provide different behavior. |
| 1988 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 1989 | FieldDecl *Field) { |
| 1990 | return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc, |
| 1991 | Field)); |
| 1992 | } |
| 1993 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1994 | /// \brief Build a new C++ zero-initialization expression. |
| 1995 | /// |
| 1996 | /// By default, performs semantic analysis to build the new expression. |
| 1997 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1998 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1999 | SourceLocation LParenLoc, |
| 2000 | SourceLocation RParenLoc) { |
| 2001 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 2002 | MultiExprArg(), RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2003 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2004 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2005 | /// \brief Build a new C++ "new" expression. |
| 2006 | /// |
| 2007 | /// By default, performs semantic analysis to build the new expression. |
| 2008 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2009 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2010 | bool UseGlobal, |
| 2011 | SourceLocation PlacementLParen, |
| 2012 | MultiExprArg PlacementArgs, |
| 2013 | SourceLocation PlacementRParen, |
| 2014 | SourceRange TypeIdParens, |
| 2015 | QualType AllocatedType, |
| 2016 | TypeSourceInfo *AllocatedTypeInfo, |
| 2017 | Expr *ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2018 | SourceRange DirectInitRange, |
| 2019 | Expr *Initializer) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2020 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2021 | PlacementLParen, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2022 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2023 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2024 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2025 | AllocatedType, |
| 2026 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2027 | ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2028 | DirectInitRange, |
| 2029 | Initializer); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2032 | /// \brief Build a new C++ "delete" expression. |
| 2033 | /// |
| 2034 | /// By default, performs semantic analysis to build the new expression. |
| 2035 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2036 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2037 | bool IsGlobalDelete, |
| 2038 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2039 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2040 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2041 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2043 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2044 | /// \brief Build a new unary type trait expression. |
| 2045 | /// |
| 2046 | /// By default, performs semantic analysis to build the new expression. |
| 2047 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2048 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 2049 | SourceLocation StartLoc, |
| 2050 | TypeSourceInfo *T, |
| 2051 | SourceLocation RParenLoc) { |
| 2052 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2055 | /// \brief Build a new binary type trait expression. |
| 2056 | /// |
| 2057 | /// By default, performs semantic analysis to build the new expression. |
| 2058 | /// Subclasses may override this routine to provide different behavior. |
| 2059 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 2060 | SourceLocation StartLoc, |
| 2061 | TypeSourceInfo *LhsT, |
| 2062 | TypeSourceInfo *RhsT, |
| 2063 | SourceLocation RParenLoc) { |
| 2064 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 2065 | } |
| 2066 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2067 | /// \brief Build a new type trait expression. |
| 2068 | /// |
| 2069 | /// By default, performs semantic analysis to build the new expression. |
| 2070 | /// Subclasses may override this routine to provide different behavior. |
| 2071 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2072 | SourceLocation StartLoc, |
| 2073 | ArrayRef<TypeSourceInfo *> Args, |
| 2074 | SourceLocation RParenLoc) { |
| 2075 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2076 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2077 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2078 | /// \brief Build a new array type trait expression. |
| 2079 | /// |
| 2080 | /// By default, performs semantic analysis to build the new expression. |
| 2081 | /// Subclasses may override this routine to provide different behavior. |
| 2082 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2083 | SourceLocation StartLoc, |
| 2084 | TypeSourceInfo *TSInfo, |
| 2085 | Expr *DimExpr, |
| 2086 | SourceLocation RParenLoc) { |
| 2087 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2088 | } |
| 2089 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2090 | /// \brief Build a new expression trait expression. |
| 2091 | /// |
| 2092 | /// By default, performs semantic analysis to build the new expression. |
| 2093 | /// Subclasses may override this routine to provide different behavior. |
| 2094 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2095 | SourceLocation StartLoc, |
| 2096 | Expr *Queried, |
| 2097 | SourceLocation RParenLoc) { |
| 2098 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2099 | } |
| 2100 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2101 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2102 | /// expression. |
| 2103 | /// |
| 2104 | /// By default, performs semantic analysis to build the new expression. |
| 2105 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2106 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2107 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2108 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2109 | const DeclarationNameInfo &NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2110 | const TemplateArgumentListInfo *TemplateArgs, |
| 2111 | bool IsAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2112 | CXXScopeSpec SS; |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2113 | SS.Adopt(QualifierLoc); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2114 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2115 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2116 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2117 | NameInfo, TemplateArgs); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2118 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2119 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo, |
| 2120 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | /// \brief Build a new template-id expression. |
| 2124 | /// |
| 2125 | /// By default, performs semantic analysis to build the new expression. |
| 2126 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2127 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2128 | SourceLocation TemplateKWLoc, |
| 2129 | LookupResult &R, |
| 2130 | bool RequiresADL, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2131 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2132 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2133 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | /// \brief Build a new object-construction expression. |
| 2137 | /// |
| 2138 | /// By default, performs semantic analysis to build the new expression. |
| 2139 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2140 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2141 | SourceLocation Loc, |
| 2142 | CXXConstructorDecl *Constructor, |
| 2143 | bool IsElidable, |
| 2144 | MultiExprArg Args, |
| 2145 | bool HadMultipleCandidates, |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2146 | bool ListInitialization, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2147 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2148 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2149 | SourceRange ParenRange) { |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2150 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2151 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2152 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2153 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2154 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2155 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2156 | ConvertedArgs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2157 | HadMultipleCandidates, |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2158 | ListInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2159 | RequiresZeroInit, ConstructKind, |
| 2160 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | /// \brief Build a new object-construction expression. |
| 2164 | /// |
| 2165 | /// By default, performs semantic analysis to build the new expression. |
| 2166 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2167 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2168 | SourceLocation LParenLoc, |
| 2169 | MultiExprArg Args, |
| 2170 | SourceLocation RParenLoc) { |
| 2171 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2172 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2173 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2174 | RParenLoc); |
| 2175 | } |
| 2176 | |
| 2177 | /// \brief Build a new object-construction expression. |
| 2178 | /// |
| 2179 | /// By default, performs semantic analysis to build the new expression. |
| 2180 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2181 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2182 | SourceLocation LParenLoc, |
| 2183 | MultiExprArg Args, |
| 2184 | SourceLocation RParenLoc) { |
| 2185 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2186 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2187 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2188 | RParenLoc); |
| 2189 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2190 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2191 | /// \brief Build a new member reference expression. |
| 2192 | /// |
| 2193 | /// By default, performs semantic analysis to build the new expression. |
| 2194 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2195 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2196 | QualType BaseType, |
| 2197 | bool IsArrow, |
| 2198 | SourceLocation OperatorLoc, |
| 2199 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2200 | SourceLocation TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2201 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2202 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2203 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2204 | CXXScopeSpec SS; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2205 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2206 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2207 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2208 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2209 | SS, TemplateKWLoc, |
| 2210 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2211 | MemberNameInfo, |
| 2212 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2215 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2216 | /// |
| 2217 | /// By default, performs semantic analysis to build the new expression. |
| 2218 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2219 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2220 | SourceLocation OperatorLoc, |
| 2221 | bool IsArrow, |
| 2222 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2223 | SourceLocation TemplateKWLoc, |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2224 | NamedDecl *FirstQualifierInScope, |
| 2225 | LookupResult &R, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2226 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2227 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2228 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2229 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2230 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2231 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2232 | SS, TemplateKWLoc, |
| 2233 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2234 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2235 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2236 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2237 | /// \brief Build a new noexcept expression. |
| 2238 | /// |
| 2239 | /// By default, performs semantic analysis to build the new expression. |
| 2240 | /// Subclasses may override this routine to provide different behavior. |
| 2241 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2242 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2243 | } |
| 2244 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2245 | /// \brief Build a new expression to compute the length of a parameter pack. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2246 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2247 | SourceLocation PackLoc, |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2248 | SourceLocation RParenLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2249 | Optional<unsigned> Length) { |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2250 | if (Length) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2251 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2252 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2253 | RParenLoc, *Length); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2254 | |
| 2255 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2256 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2257 | RParenLoc); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2258 | } |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2259 | |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2260 | /// \brief Build a new Objective-C boxed expression. |
| 2261 | /// |
| 2262 | /// By default, performs semantic analysis to build the new expression. |
| 2263 | /// Subclasses may override this routine to provide different behavior. |
| 2264 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2265 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2266 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2267 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2268 | /// \brief Build a new Objective-C array literal. |
| 2269 | /// |
| 2270 | /// By default, performs semantic analysis to build the new expression. |
| 2271 | /// Subclasses may override this routine to provide different behavior. |
| 2272 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2273 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2274 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2275 | MultiExprArg(Elements, NumElements)); |
| 2276 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2277 | |
| 2278 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2279 | Expr *Base, Expr *Key, |
| 2280 | ObjCMethodDecl *getterMethod, |
| 2281 | ObjCMethodDecl *setterMethod) { |
| 2282 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2283 | getterMethod, setterMethod); |
| 2284 | } |
| 2285 | |
| 2286 | /// \brief Build a new Objective-C dictionary literal. |
| 2287 | /// |
| 2288 | /// By default, performs semantic analysis to build the new expression. |
| 2289 | /// Subclasses may override this routine to provide different behavior. |
| 2290 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2291 | ObjCDictionaryElement *Elements, |
| 2292 | unsigned NumElements) { |
| 2293 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2294 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2295 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2296 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2297 | /// |
| 2298 | /// By default, performs semantic analysis to build the new expression. |
| 2299 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2300 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2301 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2302 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2303 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2304 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2305 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2306 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2307 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2308 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2309 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2310 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2311 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2312 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2313 | MultiExprArg Args, |
| 2314 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2315 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2316 | ReceiverTypeInfo->getType(), |
| 2317 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2318 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2319 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2323 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2324 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2325 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2326 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2327 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2328 | MultiExprArg Args, |
| 2329 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2330 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2331 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2332 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2333 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2334 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2337 | /// \brief Build a new Objective-C ivar reference expression. |
| 2338 | /// |
| 2339 | /// By default, performs semantic analysis to build the new expression. |
| 2340 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2341 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2342 | SourceLocation IvarLoc, |
| 2343 | bool IsArrow, bool IsFreeIvar) { |
| 2344 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2345 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2346 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2347 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2348 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2349 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2350 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2351 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2352 | false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2353 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2354 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2355 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2356 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2357 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2358 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2359 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2360 | /*FIXME:*/IvarLoc, IsArrow, |
| 2361 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2362 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2363 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2364 | /*TemplateArgs=*/0); |
| 2365 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2366 | |
| 2367 | /// \brief Build a new Objective-C property reference expression. |
| 2368 | /// |
| 2369 | /// By default, performs semantic analysis to build the new expression. |
| 2370 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2371 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2372 | ObjCPropertyDecl *Property, |
| 2373 | SourceLocation PropertyLoc) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2374 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2375 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2376 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2377 | Sema::LookupMemberName); |
| 2378 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2379 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2380 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2381 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2382 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2383 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2384 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2385 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2386 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2387 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2388 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2389 | /*FIXME:*/PropertyLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2390 | SS, SourceLocation(), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2391 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2392 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2393 | /*TemplateArgs=*/0); |
| 2394 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2395 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2396 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2397 | /// |
| 2398 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2399 | /// Subclasses may override this routine to provide different behavior. |
| 2400 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2401 | ObjCMethodDecl *Getter, |
| 2402 | ObjCMethodDecl *Setter, |
| 2403 | SourceLocation PropertyLoc) { |
| 2404 | // Since these expressions can only be value-dependent, we do not |
| 2405 | // need to perform semantic analysis again. |
| 2406 | return Owned( |
| 2407 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2408 | VK_LValue, OK_ObjCProperty, |
| 2409 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2412 | /// \brief Build a new Objective-C "isa" expression. |
| 2413 | /// |
| 2414 | /// By default, performs semantic analysis to build the new expression. |
| 2415 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2416 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2417 | SourceLocation OpLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2418 | bool IsArrow) { |
| 2419 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2420 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2421 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2422 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2423 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2424 | OpLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2425 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2426 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2427 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2428 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2429 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2430 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2431 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2432 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2433 | OpLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2434 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2435 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2436 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2437 | /*TemplateArgs=*/0); |
| 2438 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2439 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2440 | /// \brief Build a new shuffle vector expression. |
| 2441 | /// |
| 2442 | /// By default, performs semantic analysis to build the new expression. |
| 2443 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2444 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2445 | MultiExprArg SubExprs, |
| 2446 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2447 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2448 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2449 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2450 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2451 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2452 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2453 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2454 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2455 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2456 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2457 | SemaRef.Context.BuiltinFnTy, |
| 2458 | VK_RValue, BuiltinLoc); |
| 2459 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2460 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| 2461 | CK_BuiltinFnToFnPtr).take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2462 | |
| 2463 | // Build the CallExpr |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2464 | ExprResult TheCall = SemaRef.Owned( |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2465 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs, |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2466 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2467 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2468 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2469 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2470 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2471 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2472 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2473 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2474 | /// \brief Build a new template argument pack expansion. |
| 2475 | /// |
| 2476 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2477 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2478 | /// different behavior. |
| 2479 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2480 | SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2481 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2482 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2483 | case TemplateArgument::Expression: { |
| 2484 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2485 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2486 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2487 | if (Result.isInvalid()) |
| 2488 | return TemplateArgumentLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2489 | |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2490 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2491 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2492 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2493 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2494 | return TemplateArgumentLoc(TemplateArgument( |
| 2495 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2496 | NumExpansions), |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2497 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2498 | Pattern.getTemplateNameLoc(), |
| 2499 | EllipsisLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2500 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2501 | case TemplateArgument::Null: |
| 2502 | case TemplateArgument::Integral: |
| 2503 | case TemplateArgument::Declaration: |
| 2504 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2505 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2506 | case TemplateArgument::NullPtr: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2507 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2508 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2509 | case TemplateArgument::Type: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2510 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2511 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2512 | EllipsisLoc, |
| 2513 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2514 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2515 | Expansion); |
| 2516 | break; |
| 2517 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2518 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2519 | return TemplateArgumentLoc(); |
| 2520 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2521 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2522 | /// \brief Build a new expression pack expansion. |
| 2523 | /// |
| 2524 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2525 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2526 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2527 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2528 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2529 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2530 | } |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2531 | |
| 2532 | /// \brief Build a new atomic operation expression. |
| 2533 | /// |
| 2534 | /// By default, performs semantic analysis to build the new expression. |
| 2535 | /// Subclasses may override this routine to provide different behavior. |
| 2536 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2537 | MultiExprArg SubExprs, |
| 2538 | QualType RetTy, |
| 2539 | AtomicExpr::AtomicOp Op, |
| 2540 | SourceLocation RParenLoc) { |
| 2541 | // Just create the expression; there is not any interesting semantic |
| 2542 | // analysis here because we can't actually build an AtomicExpr until |
| 2543 | // we are sure it is semantically sound. |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2544 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2545 | RParenLoc); |
| 2546 | } |
| 2547 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2548 | private: |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2549 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2550 | QualType ObjectType, |
| 2551 | NamedDecl *FirstQualifierInScope, |
| 2552 | CXXScopeSpec &SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2553 | |
| 2554 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2555 | QualType ObjectType, |
| 2556 | NamedDecl *FirstQualifierInScope, |
| 2557 | CXXScopeSpec &SS); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2558 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2559 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2560 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2561 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2562 | if (!S) |
| 2563 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2564 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2565 | switch (S->getStmtClass()) { |
| 2566 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2567 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2568 | // Transform individual statement nodes |
| 2569 | #define STMT(Node, Parent) \ |
| 2570 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2571 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2572 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2573 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2575 | // Transform expressions by calling TransformExpr. |
| 2576 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2577 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2578 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2579 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2580 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2581 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2582 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2583 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2584 | |
Richard Smith | 4195637 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2585 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2586 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2589 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2590 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2591 | |
| 2592 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2593 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2594 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2595 | if (!E) |
| 2596 | return SemaRef.Owned(E); |
| 2597 | |
| 2598 | switch (E->getStmtClass()) { |
| 2599 | case Stmt::NoStmtClass: break; |
| 2600 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2601 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2602 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2603 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2604 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2607 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | template<typename Derived> |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2611 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 2612 | bool CXXDirectInit) { |
| 2613 | // Initializers are instantiated like expressions, except that various outer |
| 2614 | // layers are stripped. |
| 2615 | if (!Init) |
| 2616 | return SemaRef.Owned(Init); |
| 2617 | |
| 2618 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2619 | Init = ExprTemp->getSubExpr(); |
| 2620 | |
| 2621 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 2622 | Init = Binder->getSubExpr(); |
| 2623 | |
| 2624 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 2625 | Init = ICE->getSubExprAsWritten(); |
| 2626 | |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2627 | // If this is not a direct-initializer, we only need to reconstruct |
| 2628 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 2629 | // the initializer is already the right type. |
| 2630 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 2631 | if (!CXXDirectInit && !(Construct && Construct->isListInitialization())) |
| 2632 | return getDerived().TransformExpr(Init); |
| 2633 | |
| 2634 | // Revert value-initialization back to empty parens. |
| 2635 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 2636 | SourceRange Parens = VIE->getSourceRange(); |
| 2637 | return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(), |
| 2638 | Parens.getEnd()); |
| 2639 | } |
| 2640 | |
| 2641 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 2642 | if (isa<ImplicitValueInitExpr>(Init)) |
| 2643 | return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(), |
| 2644 | SourceLocation()); |
| 2645 | |
| 2646 | // Revert initialization by constructor back to a parenthesized or braced list |
| 2647 | // of expressions. Any other form of initializer can just be reused directly. |
| 2648 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2649 | return getDerived().TransformExpr(Init); |
| 2650 | |
| 2651 | SmallVector<Expr*, 8> NewArgs; |
| 2652 | bool ArgChanged = false; |
| 2653 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 2654 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| 2655 | return ExprError(); |
| 2656 | |
| 2657 | // If this was list initialization, revert to list form. |
| 2658 | if (Construct->isListInitialization()) |
| 2659 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 2660 | Construct->getLocEnd(), |
| 2661 | Construct->getType()); |
| 2662 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2663 | // Build a ParenListExpr to represent anything else. |
| 2664 | SourceRange Parens = Construct->getParenRange(); |
| 2665 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 2666 | Parens.getEnd()); |
| 2667 | } |
| 2668 | |
| 2669 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2670 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2671 | unsigned NumInputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2672 | bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2673 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2674 | bool *ArgChanged) { |
| 2675 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2676 | // If requested, drop call arguments that need to be dropped. |
| 2677 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2678 | if (ArgChanged) |
| 2679 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2680 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2681 | break; |
| 2682 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2683 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2684 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2685 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2686 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2687 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2688 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2689 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2690 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2691 | // Determine whether the set of unexpanded parameter packs can and should |
| 2692 | // be expanded. |
| 2693 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2694 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2695 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 2696 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2697 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2698 | Pattern->getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2699 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2700 | Expand, RetainExpansion, |
| 2701 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2702 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2703 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2704 | if (!Expand) { |
| 2705 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2706 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2707 | // expansion. |
| 2708 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2709 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2710 | if (OutPattern.isInvalid()) |
| 2711 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2712 | |
| 2713 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2714 | Expansion->getEllipsisLoc(), |
| 2715 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2716 | if (Out.isInvalid()) |
| 2717 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2718 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2719 | if (ArgChanged) |
| 2720 | *ArgChanged = true; |
| 2721 | Outputs.push_back(Out.get()); |
| 2722 | continue; |
| 2723 | } |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2724 | |
| 2725 | // Record right away that the argument was changed. This needs |
| 2726 | // to happen even if the array expands to nothing. |
| 2727 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2728 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2729 | // The transform has determined that we should perform an elementwise |
| 2730 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2731 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2732 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2733 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2734 | if (Out.isInvalid()) |
| 2735 | return true; |
| 2736 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2737 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2738 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2739 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2740 | if (Out.isInvalid()) |
| 2741 | return true; |
| 2742 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2743 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2744 | Outputs.push_back(Out.get()); |
| 2745 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2746 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2747 | continue; |
| 2748 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2749 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2750 | ExprResult Result = |
| 2751 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 2752 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2753 | if (Result.isInvalid()) |
| 2754 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2755 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2756 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2757 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2758 | |
| 2759 | Outputs.push_back(Result.get()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2760 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2761 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2762 | return false; |
| 2763 | } |
| 2764 | |
| 2765 | template<typename Derived> |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2766 | NestedNameSpecifierLoc |
| 2767 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2768 | NestedNameSpecifierLoc NNS, |
| 2769 | QualType ObjectType, |
| 2770 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2771 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2772 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2773 | Qualifier = Qualifier.getPrefix()) |
| 2774 | Qualifiers.push_back(Qualifier); |
| 2775 | |
| 2776 | CXXScopeSpec SS; |
| 2777 | while (!Qualifiers.empty()) { |
| 2778 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2779 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2780 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2781 | switch (QNNS->getKind()) { |
| 2782 | case NestedNameSpecifier::Identifier: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2783 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2784 | *QNNS->getAsIdentifier(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2785 | Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2786 | Q.getLocalEndLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2787 | ObjectType, false, SS, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2788 | FirstQualifierInScope, false)) |
| 2789 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2790 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2791 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2792 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2793 | case NestedNameSpecifier::Namespace: { |
| 2794 | NamespaceDecl *NS |
| 2795 | = cast_or_null<NamespaceDecl>( |
| 2796 | getDerived().TransformDecl( |
| 2797 | Q.getLocalBeginLoc(), |
| 2798 | QNNS->getAsNamespace())); |
| 2799 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2800 | break; |
| 2801 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2802 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2803 | case NestedNameSpecifier::NamespaceAlias: { |
| 2804 | NamespaceAliasDecl *Alias |
| 2805 | = cast_or_null<NamespaceAliasDecl>( |
| 2806 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2807 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2808 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2809 | Q.getLocalEndLoc()); |
| 2810 | break; |
| 2811 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2812 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2813 | case NestedNameSpecifier::Global: |
| 2814 | // There is no meaningful transformation that one could perform on the |
| 2815 | // global scope. |
| 2816 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2817 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2818 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2819 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2820 | case NestedNameSpecifier::TypeSpec: { |
| 2821 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2822 | FirstQualifierInScope, SS); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2823 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2824 | if (!TL) |
| 2825 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2826 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2827 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2828 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2829 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2830 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2831 | "Can't get cv-qualifiers here"); |
Richard Smith | 95aafb2 | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 2832 | if (TL.getType()->isEnumeralType()) |
| 2833 | SemaRef.Diag(TL.getBeginLoc(), |
| 2834 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2835 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2836 | Q.getLocalEndLoc()); |
| 2837 | break; |
| 2838 | } |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2839 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2840 | // error because a previous error should have already been emitted. |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 2841 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 2842 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2843 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2844 | << TL.getType() << SS.getRange(); |
| 2845 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2846 | return NestedNameSpecifierLoc(); |
| 2847 | } |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2848 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2849 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2850 | // 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] | 2851 | FirstQualifierInScope = 0; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2852 | ObjectType = QualType(); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2853 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2854 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2855 | // Don't rebuild the nested-name-specifier if we don't have to. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2856 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2857 | !getDerived().AlwaysRebuild()) |
| 2858 | return NNS; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2859 | |
| 2860 | // If we can re-use the source-location data from the original |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2861 | // nested-name-specifier, do so. |
| 2862 | if (SS.location_size() == NNS.getDataLength() && |
| 2863 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2864 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2865 | |
| 2866 | // Allocate new nested-name-specifier location information. |
| 2867 | return SS.getWithLocInContext(SemaRef.Context); |
| 2868 | } |
| 2869 | |
| 2870 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2871 | DeclarationNameInfo |
| 2872 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2873 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2874 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2875 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2876 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2877 | |
| 2878 | switch (Name.getNameKind()) { |
| 2879 | case DeclarationName::Identifier: |
| 2880 | case DeclarationName::ObjCZeroArgSelector: |
| 2881 | case DeclarationName::ObjCOneArgSelector: |
| 2882 | case DeclarationName::ObjCMultiArgSelector: |
| 2883 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2884 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2885 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2886 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2887 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2888 | case DeclarationName::CXXConstructorName: |
| 2889 | case DeclarationName::CXXDestructorName: |
| 2890 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2891 | TypeSourceInfo *NewTInfo; |
| 2892 | CanQualType NewCanTy; |
| 2893 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2894 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2895 | if (!NewTInfo) |
| 2896 | return DeclarationNameInfo(); |
| 2897 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2898 | } |
| 2899 | else { |
| 2900 | NewTInfo = 0; |
| 2901 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2902 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2903 | if (NewT.isNull()) |
| 2904 | return DeclarationNameInfo(); |
| 2905 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2906 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2907 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2908 | DeclarationName NewName |
| 2909 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2910 | NewCanTy); |
| 2911 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2912 | NewNameInfo.setName(NewName); |
| 2913 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2914 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2918 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2922 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2923 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 2924 | TemplateName Name, |
| 2925 | SourceLocation NameLoc, |
| 2926 | QualType ObjectType, |
| 2927 | NamedDecl *FirstQualifierInScope) { |
| 2928 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 2929 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 2930 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2931 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2932 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2933 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2934 | Template)); |
| 2935 | if (!TransTemplate) |
| 2936 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2937 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2938 | if (!getDerived().AlwaysRebuild() && |
| 2939 | SS.getScopeRep() == QTN->getQualifier() && |
| 2940 | TransTemplate == Template) |
| 2941 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2942 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2943 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 2944 | TransTemplate); |
| 2945 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2946 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2947 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 2948 | if (SS.getScopeRep()) { |
| 2949 | // These apply to the scope specifier, not the template. |
| 2950 | ObjectType = QualType(); |
| 2951 | FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2954 | if (!getDerived().AlwaysRebuild() && |
| 2955 | SS.getScopeRep() == DTN->getQualifier() && |
| 2956 | ObjectType.isNull()) |
| 2957 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2958 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2959 | if (DTN->isIdentifier()) { |
| 2960 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2961 | *DTN->getIdentifier(), |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2962 | NameLoc, |
| 2963 | ObjectType, |
| 2964 | FirstQualifierInScope); |
| 2965 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2966 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2967 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 2968 | ObjectType); |
| 2969 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2970 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2971 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 2972 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2973 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2974 | Template)); |
| 2975 | if (!TransTemplate) |
| 2976 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2977 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2978 | if (!getDerived().AlwaysRebuild() && |
| 2979 | TransTemplate == Template) |
| 2980 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2981 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2982 | return TemplateName(TransTemplate); |
| 2983 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2984 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2985 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2986 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2987 | TemplateTemplateParmDecl *TransParam |
| 2988 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2989 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 2990 | if (!TransParam) |
| 2991 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2992 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2993 | if (!getDerived().AlwaysRebuild() && |
| 2994 | TransParam == SubstPack->getParameterPack()) |
| 2995 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2996 | |
| 2997 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2998 | SubstPack->getArgumentPack()); |
| 2999 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3000 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3001 | // These should be getting filtered out before they reach the AST. |
| 3002 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3006 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3007 | const TemplateArgument &Arg, |
| 3008 | TemplateArgumentLoc &Output) { |
| 3009 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3010 | switch (Arg.getKind()) { |
| 3011 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3012 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3013 | break; |
| 3014 | |
| 3015 | case TemplateArgument::Type: |
| 3016 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3017 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3018 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3019 | break; |
| 3020 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3021 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3022 | case TemplateArgument::TemplateExpansion: { |
| 3023 | NestedNameSpecifierLocBuilder Builder; |
| 3024 | TemplateName Template = Arg.getAsTemplate(); |
| 3025 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3026 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3027 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3028 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3029 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3030 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3031 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3032 | Builder.getWithLocInContext(SemaRef.Context), |
| 3033 | Loc); |
| 3034 | else |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3035 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3036 | Builder.getWithLocInContext(SemaRef.Context), |
| 3037 | Loc, Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3038 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3039 | break; |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3040 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3041 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3042 | case TemplateArgument::Expression: |
| 3043 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3044 | break; |
| 3045 | |
| 3046 | case TemplateArgument::Declaration: |
| 3047 | case TemplateArgument::Integral: |
| 3048 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3049 | case TemplateArgument::NullPtr: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3050 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3051 | break; |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | template<typename Derived> |
| 3056 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3057 | const TemplateArgumentLoc &Input, |
| 3058 | TemplateArgumentLoc &Output) { |
| 3059 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3060 | switch (Arg.getKind()) { |
| 3061 | case TemplateArgument::Null: |
| 3062 | case TemplateArgument::Integral: |
Eli Friedman | 511e3ae | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3063 | case TemplateArgument::Pack: |
| 3064 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3065 | case TemplateArgument::NullPtr: |
| 3066 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3067 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3068 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3069 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3070 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3071 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3072 | |
| 3073 | DI = getDerived().TransformType(DI); |
| 3074 | if (!DI) return true; |
| 3075 | |
| 3076 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3077 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3078 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3079 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3080 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3081 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3082 | if (QualifierLoc) { |
| 3083 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3084 | if (!QualifierLoc) |
| 3085 | return true; |
| 3086 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3087 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3088 | CXXScopeSpec SS; |
| 3089 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3090 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3091 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3092 | Input.getTemplateNameLoc()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3093 | if (Template.isNull()) |
| 3094 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3095 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3096 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3097 | Input.getTemplateNameLoc()); |
| 3098 | return false; |
| 3099 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3100 | |
| 3101 | case TemplateArgument::TemplateExpansion: |
| 3102 | llvm_unreachable("Caller should expand pack expansions"); |
| 3103 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3104 | case TemplateArgument::Expression: { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3105 | // Template argument expressions are constant expressions. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3106 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3107 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3108 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3109 | Expr *InputExpr = Input.getSourceExpression(); |
| 3110 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3111 | |
Chris Lattner | 223de24 | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3112 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3113 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3114 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3115 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3116 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3117 | } |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3118 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3119 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3120 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3121 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3124 | /// \brief Iterator adaptor that invents template argument location information |
| 3125 | /// for each of the template arguments in its underlying iterator. |
| 3126 | template<typename Derived, typename InputIterator> |
| 3127 | class TemplateArgumentLocInventIterator { |
| 3128 | TreeTransform<Derived> &Self; |
| 3129 | InputIterator Iter; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3130 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3131 | public: |
| 3132 | typedef TemplateArgumentLoc value_type; |
| 3133 | typedef TemplateArgumentLoc reference; |
| 3134 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3135 | difference_type; |
| 3136 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3138 | class pointer { |
| 3139 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3140 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3141 | public: |
| 3142 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3143 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3144 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3145 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3146 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3147 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3148 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3149 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3150 | InputIterator Iter) |
| 3151 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3152 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3153 | TemplateArgumentLocInventIterator &operator++() { |
| 3154 | ++Iter; |
| 3155 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3156 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3157 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3158 | TemplateArgumentLocInventIterator operator++(int) { |
| 3159 | TemplateArgumentLocInventIterator Old(*this); |
| 3160 | ++(*this); |
| 3161 | return Old; |
| 3162 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3163 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3164 | reference operator*() const { |
| 3165 | TemplateArgumentLoc Result; |
| 3166 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3167 | return Result; |
| 3168 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3169 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3170 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3171 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3172 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3173 | const TemplateArgumentLocInventIterator &Y) { |
| 3174 | return X.Iter == Y.Iter; |
| 3175 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3176 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3177 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3178 | const TemplateArgumentLocInventIterator &Y) { |
| 3179 | return X.Iter != Y.Iter; |
| 3180 | } |
| 3181 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3182 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3183 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3184 | template<typename InputIterator> |
| 3185 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3186 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3187 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3188 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3189 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3190 | TemplateArgumentLoc In = *First; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3191 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3192 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3193 | // Unpack argument packs, which we translate them into separate |
| 3194 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3195 | // FIXME: We could do much better if we could guarantee that the |
| 3196 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3197 | // all of the template arguments in the argument pack. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3198 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3199 | TemplateArgument::pack_iterator> |
| 3200 | PackLocIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3201 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3202 | In.getArgument().pack_begin()), |
| 3203 | PackLocIterator(*this, |
| 3204 | In.getArgument().pack_end()), |
| 3205 | Outputs)) |
| 3206 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3207 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3208 | continue; |
| 3209 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3210 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3211 | if (In.getArgument().isPackExpansion()) { |
| 3212 | // We have a pack expansion, for which we will be substituting into |
| 3213 | // the pattern. |
| 3214 | SourceLocation Ellipsis; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3215 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3216 | TemplateArgumentLoc Pattern |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3217 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3218 | getSema().Context); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3219 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3220 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3221 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3222 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3223 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3224 | // Determine whether the set of unexpanded parameter packs can and should |
| 3225 | // be expanded. |
| 3226 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3227 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3228 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3229 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3230 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3231 | Unexpanded, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3232 | Expand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3233 | RetainExpansion, |
| 3234 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3235 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3236 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3237 | if (!Expand) { |
| 3238 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3239 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3240 | // expansion. |
| 3241 | TemplateArgumentLoc OutPattern; |
| 3242 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3243 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3244 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3245 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3246 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3247 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3248 | if (Out.getArgument().isNull()) |
| 3249 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3251 | Outputs.addArgument(Out); |
| 3252 | continue; |
| 3253 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3255 | // The transform has determined that we should perform an elementwise |
| 3256 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3257 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3258 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3259 | |
| 3260 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3261 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3262 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3263 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3264 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3265 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3266 | if (Out.getArgument().isNull()) |
| 3267 | return true; |
| 3268 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3269 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3270 | Outputs.addArgument(Out); |
| 3271 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3272 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3273 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3274 | // forgetting the partially-substituted parameter pack. |
| 3275 | if (RetainExpansion) { |
| 3276 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3277 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3278 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3279 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3280 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3281 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3282 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3283 | if (Out.getArgument().isNull()) |
| 3284 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3285 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3286 | Outputs.addArgument(Out); |
| 3287 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3288 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3289 | continue; |
| 3290 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3291 | |
| 3292 | // The simple case: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3293 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3294 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3295 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3296 | Outputs.addArgument(Out); |
| 3297 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3298 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3299 | return false; |
| 3300 | |
| 3301 | } |
| 3302 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3303 | //===----------------------------------------------------------------------===// |
| 3304 | // Type transformation |
| 3305 | //===----------------------------------------------------------------------===// |
| 3306 | |
| 3307 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3308 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3309 | if (getDerived().AlreadyTransformed(T)) |
| 3310 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3311 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3312 | // Temporary workaround. All of these transformations should |
| 3313 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3314 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3315 | getDerived().getBaseLocation()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3316 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3317 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3318 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3319 | if (!NewDI) |
| 3320 | return QualType(); |
| 3321 | |
| 3322 | return NewDI->getType(); |
| 3323 | } |
| 3324 | |
| 3325 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3326 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3327 | // Refine the base location to the type's location. |
| 3328 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3329 | getDerived().getBaseEntity()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3330 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3331 | return DI; |
| 3332 | |
| 3333 | TypeLocBuilder TLB; |
| 3334 | |
| 3335 | TypeLoc TL = DI->getTypeLoc(); |
| 3336 | TLB.reserve(TL.getFullDataSize()); |
| 3337 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3338 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3339 | if (Result.isNull()) |
| 3340 | return 0; |
| 3341 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3342 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | template<typename Derived> |
| 3346 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3347 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3348 | switch (T.getTypeLocClass()) { |
| 3349 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3350 | #define TYPELOC(CLASS, PARENT) \ |
| 3351 | case TypeLoc::CLASS: \ |
| 3352 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3353 | T.castAs<CLASS##TypeLoc>()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3354 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3355 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3356 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3357 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3361 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3362 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3363 | /// types). This is the right thing for template instantiation, but |
| 3364 | /// probably not for other clients. |
| 3365 | template<typename Derived> |
| 3366 | QualType |
| 3367 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3368 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3369 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3370 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3371 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3372 | if (Result.isNull()) |
| 3373 | return QualType(); |
| 3374 | |
| 3375 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3376 | // FIXME: this is the right thing for template instantiation, but |
| 3377 | // probably not for other clients. |
| 3378 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3379 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3380 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3381 | // 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] | 3382 | // resulting type. |
| 3383 | if (Quals.hasObjCLifetime()) { |
| 3384 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3385 | Quals.removeObjCLifetime(); |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3386 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3387 | // Objective-C ARC: |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3388 | // A lifetime qualifier applied to a substituted template parameter |
| 3389 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3390 | const AutoType *AutoTy; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3391 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3392 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3393 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3394 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3395 | Qs.removeObjCLifetime(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3396 | Replacement |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3397 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3398 | Qs); |
| 3399 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3400 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3401 | Replacement); |
| 3402 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3403 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3404 | // 'auto' types behave the same way as template parameters. |
| 3405 | QualType Deduced = AutoTy->getDeducedType(); |
| 3406 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3407 | Qs.removeObjCLifetime(); |
| 3408 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3409 | Qs); |
| 3410 | Result = SemaRef.Context.getAutoType(Deduced); |
| 3411 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3412 | } else { |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3413 | // Otherwise, complain about the addition of a qualifier to an |
| 3414 | // already-qualified type. |
| 3415 | SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3416 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3417 | << Result << R; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3418 | |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3419 | Quals.removeObjCLifetime(); |
| 3420 | } |
| 3421 | } |
| 3422 | } |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3423 | if (!Quals.empty()) { |
| 3424 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | 9807a2e | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3425 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3426 | if (Result.hasLocalQualifiers()) |
| 3427 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3428 | // No location information to preserve. |
| 3429 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3430 | |
| 3431 | return Result; |
| 3432 | } |
| 3433 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3434 | template<typename Derived> |
| 3435 | TypeLoc |
| 3436 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3437 | QualType ObjectType, |
| 3438 | NamedDecl *UnqualLookup, |
| 3439 | CXXScopeSpec &SS) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3440 | QualType T = TL.getType(); |
| 3441 | if (getDerived().AlreadyTransformed(T)) |
| 3442 | return TL; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3443 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3444 | TypeLocBuilder TLB; |
| 3445 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3446 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3447 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3448 | TemplateSpecializationTypeLoc SpecTL = |
| 3449 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3450 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3451 | TemplateName Template = |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3452 | getDerived().TransformTemplateName(SS, |
| 3453 | SpecTL.getTypePtr()->getTemplateName(), |
| 3454 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3455 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3456 | if (Template.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3457 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3458 | |
| 3459 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3460 | Template); |
| 3461 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3462 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3463 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3464 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3465 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3466 | = getDerived().RebuildTemplateName(SS, |
| 3467 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3468 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3469 | ObjectType, UnqualLookup); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3470 | if (Template.isNull()) |
| 3471 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3472 | |
| 3473 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3474 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3475 | Template, |
| 3476 | SS); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3477 | } else { |
| 3478 | // Nothing special needs to be done for these. |
| 3479 | Result = getDerived().TransformType(TLB, TL); |
| 3480 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3481 | |
| 3482 | if (Result.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3483 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3484 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3485 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3486 | } |
| 3487 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3488 | template<typename Derived> |
| 3489 | TypeSourceInfo * |
| 3490 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3491 | QualType ObjectType, |
| 3492 | NamedDecl *UnqualLookup, |
| 3493 | CXXScopeSpec &SS) { |
| 3494 | // FIXME: Painfully copy-paste from the above! |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3495 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3496 | QualType T = TSInfo->getType(); |
| 3497 | if (getDerived().AlreadyTransformed(T)) |
| 3498 | return TSInfo; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3499 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3500 | TypeLocBuilder TLB; |
| 3501 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3502 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3503 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3504 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3505 | TemplateSpecializationTypeLoc SpecTL = |
| 3506 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3507 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3508 | TemplateName Template |
| 3509 | = getDerived().TransformTemplateName(SS, |
| 3510 | SpecTL.getTypePtr()->getTemplateName(), |
| 3511 | SpecTL.getTemplateNameLoc(), |
| 3512 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3513 | if (Template.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3514 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3515 | |
| 3516 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3517 | Template); |
| 3518 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3519 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3520 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3521 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3522 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3523 | = getDerived().RebuildTemplateName(SS, |
| 3524 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3525 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3526 | ObjectType, UnqualLookup); |
| 3527 | if (Template.isNull()) |
| 3528 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3529 | |
| 3530 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3531 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3532 | Template, |
| 3533 | SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3534 | } else { |
| 3535 | // Nothing special needs to be done for these. |
| 3536 | Result = getDerived().TransformType(TLB, TL); |
| 3537 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3538 | |
| 3539 | if (Result.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3540 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3542 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3543 | } |
| 3544 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3545 | template <class TyLoc> static inline |
| 3546 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3547 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3548 | NewT.setNameLoc(T.getNameLoc()); |
| 3549 | return T.getType(); |
| 3550 | } |
| 3551 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3552 | template<typename Derived> |
| 3553 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3554 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3555 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3556 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3557 | if (T.needsExtraLocalData()) |
| 3558 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3559 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3561 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3562 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3563 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3564 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3565 | // FIXME: recurse? |
| 3566 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3567 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3568 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3569 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3570 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3571 | PointerTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3572 | QualType PointeeType |
| 3573 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3574 | if (PointeeType.isNull()) |
| 3575 | return QualType(); |
| 3576 | |
| 3577 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3578 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3579 | // A dependent pointer type 'T *' has is being transformed such |
| 3580 | // that an Objective-C class type is being replaced for 'T'. The |
| 3581 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3582 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3583 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3584 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3585 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3586 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3587 | return Result; |
| 3588 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3589 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3590 | if (getDerived().AlwaysRebuild() || |
| 3591 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3592 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3593 | if (Result.isNull()) |
| 3594 | return QualType(); |
| 3595 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3596 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3597 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3598 | // pointing to. |
| 3599 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3600 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3601 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3602 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3603 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3604 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3605 | |
| 3606 | template<typename Derived> |
| 3607 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3608 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3609 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3610 | QualType PointeeType |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3611 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3612 | if (PointeeType.isNull()) |
| 3613 | return QualType(); |
| 3614 | |
| 3615 | QualType Result = TL.getType(); |
| 3616 | if (getDerived().AlwaysRebuild() || |
| 3617 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3618 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3619 | TL.getSigilLoc()); |
| 3620 | if (Result.isNull()) |
| 3621 | return QualType(); |
| 3622 | } |
| 3623 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3624 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3625 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3626 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3627 | } |
| 3628 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3629 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3630 | /// don't care whether the type itself is an l-value type or an r-value |
| 3631 | /// type; we only care if the type was *written* as an l-value type |
| 3632 | /// or an r-value type. |
| 3633 | template<typename Derived> |
| 3634 | QualType |
| 3635 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3636 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3637 | const ReferenceType *T = TL.getTypePtr(); |
| 3638 | |
| 3639 | // Note that this works with the pointee-as-written. |
| 3640 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3641 | if (PointeeType.isNull()) |
| 3642 | return QualType(); |
| 3643 | |
| 3644 | QualType Result = TL.getType(); |
| 3645 | if (getDerived().AlwaysRebuild() || |
| 3646 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3647 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3648 | T->isSpelledAsLValue(), |
| 3649 | TL.getSigilLoc()); |
| 3650 | if (Result.isNull()) |
| 3651 | return QualType(); |
| 3652 | } |
| 3653 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3654 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3655 | // referring to. |
| 3656 | TLB.TypeWasModifiedSafely( |
| 3657 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3658 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3659 | // r-value references can be rebuilt as l-value references. |
| 3660 | ReferenceTypeLoc NewTL; |
| 3661 | if (isa<LValueReferenceType>(Result)) |
| 3662 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3663 | else |
| 3664 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3665 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3666 | |
| 3667 | return Result; |
| 3668 | } |
| 3669 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | template<typename Derived> |
| 3671 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3672 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3673 | LValueReferenceTypeLoc TL) { |
| 3674 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3675 | } |
| 3676 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | template<typename Derived> |
| 3678 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3679 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3680 | RValueReferenceTypeLoc TL) { |
| 3681 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3682 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3683 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3684 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3686 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3687 | MemberPointerTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3688 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3689 | if (PointeeType.isNull()) |
| 3690 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3691 | |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3692 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3693 | TypeSourceInfo* NewClsTInfo = 0; |
| 3694 | if (OldClsTInfo) { |
| 3695 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3696 | if (!NewClsTInfo) |
| 3697 | return QualType(); |
| 3698 | } |
| 3699 | |
| 3700 | const MemberPointerType *T = TL.getTypePtr(); |
| 3701 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3702 | QualType NewClsType; |
| 3703 | if (NewClsTInfo) |
| 3704 | NewClsType = NewClsTInfo->getType(); |
| 3705 | else { |
| 3706 | NewClsType = getDerived().TransformType(OldClsType); |
| 3707 | if (NewClsType.isNull()) |
| 3708 | return QualType(); |
| 3709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3710 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3711 | QualType Result = TL.getType(); |
| 3712 | if (getDerived().AlwaysRebuild() || |
| 3713 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3714 | NewClsType != OldClsType) { |
| 3715 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3716 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3717 | if (Result.isNull()) |
| 3718 | return QualType(); |
| 3719 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3720 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3721 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3722 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3723 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3724 | |
| 3725 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3728 | template<typename Derived> |
| 3729 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3730 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3731 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3732 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3733 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3734 | if (ElementType.isNull()) |
| 3735 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3736 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3737 | QualType Result = TL.getType(); |
| 3738 | if (getDerived().AlwaysRebuild() || |
| 3739 | ElementType != T->getElementType()) { |
| 3740 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3741 | T->getSizeModifier(), |
| 3742 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3743 | T->getIndexTypeCVRQualifiers(), |
| 3744 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3745 | if (Result.isNull()) |
| 3746 | return QualType(); |
| 3747 | } |
Eli Friedman | 457a377 | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 3748 | |
| 3749 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 3750 | // a ConstantArrayType is allowed to have an element type which is a |
| 3751 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 3752 | // types have the same location layout. |
| 3753 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3754 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3755 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3756 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3757 | Expr *Size = TL.getSizeExpr(); |
| 3758 | if (Size) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3759 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3760 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3761 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3762 | Size = SemaRef.ActOnConstantExpression(Size).take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3763 | } |
| 3764 | NewTL.setSizeExpr(Size); |
| 3765 | |
| 3766 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3767 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3768 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3769 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3770 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3771 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3772 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3773 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3774 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3775 | if (ElementType.isNull()) |
| 3776 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3778 | QualType Result = TL.getType(); |
| 3779 | if (getDerived().AlwaysRebuild() || |
| 3780 | ElementType != T->getElementType()) { |
| 3781 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3782 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3783 | T->getIndexTypeCVRQualifiers(), |
| 3784 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3785 | if (Result.isNull()) |
| 3786 | return QualType(); |
| 3787 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3788 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3789 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3790 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3791 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3792 | NewTL.setSizeExpr(0); |
| 3793 | |
| 3794 | return Result; |
| 3795 | } |
| 3796 | |
| 3797 | template<typename Derived> |
| 3798 | QualType |
| 3799 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3800 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3801 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3802 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3803 | if (ElementType.isNull()) |
| 3804 | return QualType(); |
| 3805 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3806 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3807 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3808 | if (SizeResult.isInvalid()) |
| 3809 | return QualType(); |
| 3810 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3811 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3812 | |
| 3813 | QualType Result = TL.getType(); |
| 3814 | if (getDerived().AlwaysRebuild() || |
| 3815 | ElementType != T->getElementType() || |
| 3816 | Size != T->getSizeExpr()) { |
| 3817 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3818 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3819 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3820 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3821 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3822 | if (Result.isNull()) |
| 3823 | return QualType(); |
| 3824 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3825 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3826 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3827 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3828 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3829 | NewTL.setSizeExpr(Size); |
| 3830 | |
| 3831 | return Result; |
| 3832 | } |
| 3833 | |
| 3834 | template<typename Derived> |
| 3835 | QualType |
| 3836 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3837 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3838 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3839 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3840 | if (ElementType.isNull()) |
| 3841 | return QualType(); |
| 3842 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3843 | // Array bounds are constant expressions. |
| 3844 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3845 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3846 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3847 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3848 | Expr *origSize = TL.getSizeExpr(); |
| 3849 | if (!origSize) origSize = T->getSizeExpr(); |
| 3850 | |
| 3851 | ExprResult sizeResult |
| 3852 | = getDerived().TransformExpr(origSize); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3853 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3854 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3855 | return QualType(); |
| 3856 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3857 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3858 | |
| 3859 | QualType Result = TL.getType(); |
| 3860 | if (getDerived().AlwaysRebuild() || |
| 3861 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3862 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3863 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3864 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3865 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3866 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3867 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3868 | if (Result.isNull()) |
| 3869 | return QualType(); |
| 3870 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3871 | |
| 3872 | // We might have any sort of array type now, but fortunately they |
| 3873 | // all have the same location layout. |
| 3874 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3875 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3876 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3877 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3878 | |
| 3879 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3880 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3881 | |
| 3882 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3883 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3884 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3885 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3886 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3887 | |
| 3888 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3889 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3890 | if (ElementType.isNull()) |
| 3891 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3892 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3893 | // Vector sizes are constant expressions. |
| 3894 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3895 | Sema::ConstantEvaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3896 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3897 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3898 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3899 | if (Size.isInvalid()) |
| 3900 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3902 | QualType Result = TL.getType(); |
| 3903 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3904 | ElementType != T->getElementType() || |
| 3905 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3906 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3907 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3908 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3909 | if (Result.isNull()) |
| 3910 | return QualType(); |
| 3911 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3912 | |
| 3913 | // Result might be dependent or not. |
| 3914 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3915 | DependentSizedExtVectorTypeLoc NewTL |
| 3916 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3917 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3918 | } else { |
| 3919 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3920 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3921 | } |
| 3922 | |
| 3923 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3924 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3925 | |
| 3926 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3927 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3928 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3929 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3930 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3931 | if (ElementType.isNull()) |
| 3932 | return QualType(); |
| 3933 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3934 | QualType Result = TL.getType(); |
| 3935 | if (getDerived().AlwaysRebuild() || |
| 3936 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3937 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3938 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3939 | if (Result.isNull()) |
| 3940 | return QualType(); |
| 3941 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3942 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3943 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3944 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3946 | return Result; |
| 3947 | } |
| 3948 | |
| 3949 | template<typename Derived> |
| 3950 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3951 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3952 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3953 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3954 | if (ElementType.isNull()) |
| 3955 | return QualType(); |
| 3956 | |
| 3957 | QualType Result = TL.getType(); |
| 3958 | if (getDerived().AlwaysRebuild() || |
| 3959 | ElementType != T->getElementType()) { |
| 3960 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3961 | T->getNumElements(), |
| 3962 | /*FIXME*/ SourceLocation()); |
| 3963 | if (Result.isNull()) |
| 3964 | return QualType(); |
| 3965 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3966 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3967 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3968 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3969 | |
| 3970 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3971 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3973 | template <typename Derived> |
| 3974 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 3975 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 3976 | bool ExpectParameterPack) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3977 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3978 | TypeSourceInfo *NewDI = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3980 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3981 | // 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] | 3982 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3983 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3984 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3985 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3986 | TypeLocBuilder TLB; |
| 3987 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3988 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3989 | |
| 3990 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3991 | OldExpansionTL.getPatternLoc()); |
| 3992 | if (Result.isNull()) |
| 3993 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3994 | |
| 3995 | Result = RebuildPackExpansionType(Result, |
| 3996 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3997 | OldExpansionTL.getEllipsisLoc(), |
| 3998 | NumExpansions); |
| 3999 | if (Result.isNull()) |
| 4000 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4001 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4002 | PackExpansionTypeLoc NewExpansionTL |
| 4003 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4004 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4005 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4006 | } else |
| 4007 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4008 | if (!NewDI) |
| 4009 | return 0; |
| 4010 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4011 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4012 | return OldParm; |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4013 | |
| 4014 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4015 | OldParm->getDeclContext(), |
| 4016 | OldParm->getInnerLocStart(), |
| 4017 | OldParm->getLocation(), |
| 4018 | OldParm->getIdentifier(), |
| 4019 | NewDI->getType(), |
| 4020 | NewDI, |
| 4021 | OldParm->getStorageClass(), |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4022 | /* DefArg */ NULL); |
| 4023 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4024 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4025 | return newParm; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | template<typename Derived> |
| 4029 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4030 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4031 | ParmVarDecl **Params, unsigned NumParams, |
| 4032 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4033 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4034 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4035 | int indexAdjustment = 0; |
| 4036 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4037 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4038 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4039 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4040 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4041 | Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4042 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4043 | if (OldParm->isParameterPack()) { |
| 4044 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4045 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4046 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4047 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4048 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4049 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4050 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4051 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4052 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4053 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4054 | // Determine whether we should expand the parameter packs. |
| 4055 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4056 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4057 | Optional<unsigned> OrigNumExpansions = |
| 4058 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4059 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4060 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4061 | Pattern.getSourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4062 | Unexpanded, |
| 4063 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4064 | RetainExpansion, |
| 4065 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4066 | return true; |
| 4067 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4069 | if (ShouldExpand) { |
| 4070 | // Expand the function parameter pack into multiple, separate |
| 4071 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4072 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4073 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4074 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4075 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4076 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4077 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4078 | OrigNumExpansions, |
| 4079 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4080 | if (!NewParm) |
| 4081 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +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 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4087 | |
| 4088 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4089 | // forgetting the partially-substituted parameter pack. |
| 4090 | if (RetainExpansion) { |
| 4091 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4092 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4093 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4094 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4095 | OrigNumExpansions, |
| 4096 | /*ExpectParameterPack=*/false); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4097 | if (!NewParm) |
| 4098 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4099 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4100 | OutParamTypes.push_back(NewParm->getType()); |
| 4101 | if (PVars) |
| 4102 | PVars->push_back(NewParm); |
| 4103 | } |
| 4104 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4105 | // The next parameter should have the same adjustment as the |
| 4106 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4107 | // on every push. Also, if we push nothing, the adjustment should |
| 4108 | // go down by one. |
| 4109 | indexAdjustment--; |
| 4110 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4111 | // We're done with the pack expansion. |
| 4112 | continue; |
| 4113 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4114 | |
| 4115 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4116 | // expansion. |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4117 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4118 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4119 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4120 | NumExpansions, |
| 4121 | /*ExpectParameterPack=*/true); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4122 | } else { |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4123 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4124 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4125 | } |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4126 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4127 | if (!NewParm) |
| 4128 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4129 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4130 | OutParamTypes.push_back(NewParm->getType()); |
| 4131 | if (PVars) |
| 4132 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4133 | continue; |
| 4134 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4135 | |
| 4136 | // Deal with the possibility that we don't have a parameter |
| 4137 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4138 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4139 | bool IsPackExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4140 | Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4141 | QualType NewType; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4142 | if (const PackExpansionType *Expansion |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4143 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4144 | // We have a function parameter pack that may need to be expanded. |
| 4145 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4146 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4147 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4148 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4149 | // Determine whether we should expand the parameter packs. |
| 4150 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4151 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4152 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4153 | Unexpanded, |
| 4154 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4155 | RetainExpansion, |
| 4156 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4157 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4158 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4159 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4160 | if (ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4161 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4162 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4163 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4164 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4165 | QualType NewType = getDerived().TransformType(Pattern); |
| 4166 | if (NewType.isNull()) |
| 4167 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4168 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4169 | OutParamTypes.push_back(NewType); |
| 4170 | if (PVars) |
| 4171 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4172 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4173 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4174 | // We're done with the pack expansion. |
| 4175 | continue; |
| 4176 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4177 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4178 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4179 | // forgetting the partially-substituted parameter pack. |
| 4180 | if (RetainExpansion) { |
| 4181 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4182 | QualType NewType = getDerived().TransformType(Pattern); |
| 4183 | if (NewType.isNull()) |
| 4184 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4185 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4186 | OutParamTypes.push_back(NewType); |
| 4187 | if (PVars) |
| 4188 | PVars->push_back(0); |
| 4189 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4190 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4191 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4192 | // expansion. |
| 4193 | OldType = Expansion->getPattern(); |
| 4194 | IsPackExpansion = true; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4195 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4196 | NewType = getDerived().TransformType(OldType); |
| 4197 | } else { |
| 4198 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4199 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4200 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4201 | if (NewType.isNull()) |
| 4202 | return true; |
| 4203 | |
| 4204 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4205 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4206 | NumExpansions); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4207 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4208 | OutParamTypes.push_back(NewType); |
| 4209 | if (PVars) |
| 4210 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4213 | #ifndef NDEBUG |
| 4214 | if (PVars) { |
| 4215 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4216 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4217 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4218 | } |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4219 | #endif |
| 4220 | |
| 4221 | return false; |
| 4222 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4223 | |
| 4224 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4226 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4227 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4228 | return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); |
| 4229 | } |
| 4230 | |
| 4231 | template<typename Derived> |
| 4232 | QualType |
| 4233 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4234 | FunctionProtoTypeLoc TL, |
| 4235 | CXXRecordDecl *ThisContext, |
| 4236 | unsigned ThisTypeQuals) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4237 | // Transform the parameters and return type. |
| 4238 | // |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4239 | // 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] | 4240 | // When the function has a trailing return type, we instantiate the |
| 4241 | // parameters before the return type, since the return type can then refer |
| 4242 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4243 | // |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4244 | SmallVector<QualType, 4> ParamTypes; |
| 4245 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4246 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4247 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4248 | QualType ResultType; |
| 4249 | |
Richard Smith | 9fbf327 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4250 | if (T->hasTrailingReturn()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4251 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4252 | TL.getParmArray(), |
| 4253 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4254 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4255 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4256 | return QualType(); |
| 4257 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4258 | { |
| 4259 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4260 | // If a declaration declares a member function or member function |
| 4261 | // template of a class X, the expression this is a prvalue of type |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4262 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4263 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4264 | // declarator. |
| 4265 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4266 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4267 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4268 | if (ResultType.isNull()) |
| 4269 | return QualType(); |
| 4270 | } |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4271 | } |
| 4272 | else { |
| 4273 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4274 | if (ResultType.isNull()) |
| 4275 | return QualType(); |
| 4276 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4277 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4278 | TL.getParmArray(), |
| 4279 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4280 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4281 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4282 | return QualType(); |
| 4283 | } |
| 4284 | |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4285 | // FIXME: Need to transform the exception-specification too. |
| 4286 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4287 | QualType Result = TL.getType(); |
| 4288 | if (getDerived().AlwaysRebuild() || |
| 4289 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4290 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4291 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 4292 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 4293 | T->getExtProtoInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4294 | if (Result.isNull()) |
| 4295 | return QualType(); |
| 4296 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4297 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4298 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4299 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4300 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4301 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4302 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4303 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4304 | NewTL.setArg(i, ParamDecls[i]); |
| 4305 | |
| 4306 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4307 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4308 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4309 | template<typename Derived> |
| 4310 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4311 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4312 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4313 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4314 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4315 | if (ResultType.isNull()) |
| 4316 | return QualType(); |
| 4317 | |
| 4318 | QualType Result = TL.getType(); |
| 4319 | if (getDerived().AlwaysRebuild() || |
| 4320 | ResultType != T->getResultType()) |
| 4321 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4322 | |
| 4323 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4324 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4325 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4326 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4327 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4328 | |
| 4329 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4330 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4331 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4332 | template<typename Derived> QualType |
| 4333 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4334 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4335 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4336 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4337 | if (!D) |
| 4338 | return QualType(); |
| 4339 | |
| 4340 | QualType Result = TL.getType(); |
| 4341 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4342 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4343 | if (Result.isNull()) |
| 4344 | return QualType(); |
| 4345 | } |
| 4346 | |
| 4347 | // We might get an arbitrary type spec type back. We should at |
| 4348 | // least always get a type spec type, though. |
| 4349 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4350 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4351 | |
| 4352 | return Result; |
| 4353 | } |
| 4354 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4355 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4356 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4357 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4358 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4359 | TypedefNameDecl *Typedef |
| 4360 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4361 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4362 | if (!Typedef) |
| 4363 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4364 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4365 | QualType Result = TL.getType(); |
| 4366 | if (getDerived().AlwaysRebuild() || |
| 4367 | Typedef != T->getDecl()) { |
| 4368 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4369 | if (Result.isNull()) |
| 4370 | return QualType(); |
| 4371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4372 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4373 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4374 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4375 | |
| 4376 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4377 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4379 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4380 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4381 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4382 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4383 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4384 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4386 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4387 | if (E.isInvalid()) |
| 4388 | return QualType(); |
| 4389 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4390 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4391 | if (E.isInvalid()) |
| 4392 | return QualType(); |
| 4393 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4394 | QualType Result = TL.getType(); |
| 4395 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4396 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4397 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4398 | if (Result.isNull()) |
| 4399 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4400 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4401 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4403 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4404 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4405 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4406 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4407 | |
| 4408 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4410 | |
| 4411 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4412 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4413 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4414 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4415 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4416 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4417 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4418 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4419 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4420 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4421 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4422 | if (Result.isNull()) |
| 4423 | return QualType(); |
| 4424 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4425 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4426 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4427 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4428 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4429 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4430 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4431 | |
| 4432 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4433 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4434 | |
| 4435 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4436 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4437 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4438 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4439 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4440 | // decltype expressions are not potentially evaluated contexts |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4441 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, |
| 4442 | /*IsDecltype=*/ true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4443 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4444 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4445 | if (E.isInvalid()) |
| 4446 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4447 | |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4448 | E = getSema().ActOnDecltypeExpression(E.take()); |
| 4449 | if (E.isInvalid()) |
| 4450 | return QualType(); |
| 4451 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4452 | QualType Result = TL.getType(); |
| 4453 | if (getDerived().AlwaysRebuild() || |
| 4454 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4455 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4456 | if (Result.isNull()) |
| 4457 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4458 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4459 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4460 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4461 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4462 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4463 | |
| 4464 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4468 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4469 | TypeLocBuilder &TLB, |
| 4470 | UnaryTransformTypeLoc TL) { |
| 4471 | QualType Result = TL.getType(); |
| 4472 | if (Result->isDependentType()) { |
| 4473 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4474 | QualType NewBase = |
| 4475 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4476 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4477 | T->getUTTKind(), |
| 4478 | TL.getKWLoc()); |
| 4479 | if (Result.isNull()) |
| 4480 | return QualType(); |
| 4481 | } |
| 4482 | |
| 4483 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4484 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4485 | NewTL.setParensRange(TL.getParensRange()); |
| 4486 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4487 | return Result; |
| 4488 | } |
| 4489 | |
| 4490 | template<typename Derived> |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4491 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4492 | AutoTypeLoc TL) { |
| 4493 | const AutoType *T = TL.getTypePtr(); |
| 4494 | QualType OldDeduced = T->getDeducedType(); |
| 4495 | QualType NewDeduced; |
| 4496 | if (!OldDeduced.isNull()) { |
| 4497 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4498 | if (NewDeduced.isNull()) |
| 4499 | return QualType(); |
| 4500 | } |
| 4501 | |
| 4502 | QualType Result = TL.getType(); |
| 4503 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4504 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4505 | if (Result.isNull()) |
| 4506 | return QualType(); |
| 4507 | } |
| 4508 | |
| 4509 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4510 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4511 | |
| 4512 | return Result; |
| 4513 | } |
| 4514 | |
| 4515 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4516 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4517 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4518 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4519 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4520 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4521 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4522 | if (!Record) |
| 4523 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4524 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4525 | QualType Result = TL.getType(); |
| 4526 | if (getDerived().AlwaysRebuild() || |
| 4527 | Record != T->getDecl()) { |
| 4528 | Result = getDerived().RebuildRecordType(Record); |
| 4529 | if (Result.isNull()) |
| 4530 | return QualType(); |
| 4531 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4533 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4534 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4535 | |
| 4536 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | |
| 4539 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4540 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4541 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4542 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4543 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4544 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4545 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4546 | if (!Enum) |
| 4547 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4548 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4549 | QualType Result = TL.getType(); |
| 4550 | if (getDerived().AlwaysRebuild() || |
| 4551 | Enum != T->getDecl()) { |
| 4552 | Result = getDerived().RebuildEnumType(Enum); |
| 4553 | if (Result.isNull()) |
| 4554 | return QualType(); |
| 4555 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4557 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4558 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4559 | |
| 4560 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4561 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4562 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4563 | template<typename Derived> |
| 4564 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4565 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4566 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4567 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4568 | TL.getTypePtr()->getDecl()); |
| 4569 | if (!D) return QualType(); |
| 4570 | |
| 4571 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4572 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4573 | return T; |
| 4574 | } |
| 4575 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4576 | template<typename Derived> |
| 4577 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4578 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4579 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4580 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4583 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4584 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4585 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4586 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4587 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4588 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4589 | // Substitute into the replacement type, which itself might involve something |
| 4590 | // that needs to be transformed. This only tends to occur with default |
| 4591 | // template arguments of template template parameters. |
| 4592 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4593 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4594 | if (Replacement.isNull()) |
| 4595 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4596 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4597 | // Always canonicalize the replacement type. |
| 4598 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4599 | QualType Result |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4600 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4601 | Replacement); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4602 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4603 | // Propagate type-source information. |
| 4604 | SubstTemplateTypeParmTypeLoc NewTL |
| 4605 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4606 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4607 | return Result; |
| 4608 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4609 | } |
| 4610 | |
| 4611 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4612 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4613 | TypeLocBuilder &TLB, |
| 4614 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4615 | return TransformTypeSpecType(TLB, TL); |
| 4616 | } |
| 4617 | |
| 4618 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4619 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4620 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4621 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4622 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4623 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4624 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4625 | // because we can't have a dependent nested-name-specifier anyway. |
| 4626 | CXXScopeSpec SS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4627 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4628 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4629 | TL.getTemplateNameLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4630 | if (Template.isNull()) |
| 4631 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4632 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4633 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4634 | } |
| 4635 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4636 | template<typename Derived> |
| 4637 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4638 | AtomicTypeLoc TL) { |
| 4639 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4640 | if (ValueType.isNull()) |
| 4641 | return QualType(); |
| 4642 | |
| 4643 | QualType Result = TL.getType(); |
| 4644 | if (getDerived().AlwaysRebuild() || |
| 4645 | ValueType != TL.getValueLoc().getType()) { |
| 4646 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4647 | if (Result.isNull()) |
| 4648 | return QualType(); |
| 4649 | } |
| 4650 | |
| 4651 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4652 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4653 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4654 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4655 | |
| 4656 | return Result; |
| 4657 | } |
| 4658 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4659 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4660 | /// container that provides a \c getArgLoc() member function. |
| 4661 | /// |
| 4662 | /// This iterator is intended to be used with the iterator form of |
| 4663 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4664 | template<typename ArgLocContainer> |
| 4665 | class TemplateArgumentLocContainerIterator { |
| 4666 | ArgLocContainer *Container; |
| 4667 | unsigned Index; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4668 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4669 | public: |
| 4670 | typedef TemplateArgumentLoc value_type; |
| 4671 | typedef TemplateArgumentLoc reference; |
| 4672 | typedef int difference_type; |
| 4673 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4674 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4675 | class pointer { |
| 4676 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4677 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4678 | public: |
| 4679 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4680 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4681 | const TemplateArgumentLoc *operator->() const { |
| 4682 | return &Arg; |
| 4683 | } |
| 4684 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4685 | |
| 4686 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4687 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4688 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4689 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4690 | unsigned Index) |
| 4691 | : Container(&Container), Index(Index) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4692 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4693 | TemplateArgumentLocContainerIterator &operator++() { |
| 4694 | ++Index; |
| 4695 | return *this; |
| 4696 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4697 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4698 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4699 | TemplateArgumentLocContainerIterator Old(*this); |
| 4700 | ++(*this); |
| 4701 | return Old; |
| 4702 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4703 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4704 | TemplateArgumentLoc operator*() const { |
| 4705 | return Container->getArgLoc(Index); |
| 4706 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4707 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4708 | pointer operator->() const { |
| 4709 | return pointer(Container->getArgLoc(Index)); |
| 4710 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4711 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4712 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4713 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4714 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4715 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4716 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4717 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4718 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4719 | return !(X == Y); |
| 4720 | } |
| 4721 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4722 | |
| 4723 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4724 | template <typename Derived> |
| 4725 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4726 | TypeLocBuilder &TLB, |
| 4727 | TemplateSpecializationTypeLoc TL, |
| 4728 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4729 | TemplateArgumentListInfo NewTemplateArgs; |
| 4730 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4731 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4732 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4733 | ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4734 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4735 | ArgIterator(TL, TL.getNumArgs()), |
| 4736 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4737 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4738 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4739 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4740 | |
| 4741 | QualType Result = |
| 4742 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4743 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4744 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4745 | |
| 4746 | if (!Result.isNull()) { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4747 | // Specializations of template template parameters are represented as |
| 4748 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4749 | // within a dependent context can transform them into |
| 4750 | // DependentTemplateSpecializationTypes. |
| 4751 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4752 | DependentTemplateSpecializationTypeLoc NewTL |
| 4753 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4754 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4755 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4756 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4757 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4758 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4759 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4760 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4761 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4762 | return Result; |
| 4763 | } |
| 4764 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4765 | TemplateSpecializationTypeLoc NewTL |
| 4766 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4767 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4768 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4769 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4770 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4771 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4772 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4773 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4774 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4775 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4776 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4777 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4778 | template <typename Derived> |
| 4779 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4780 | TypeLocBuilder &TLB, |
| 4781 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4782 | TemplateName Template, |
| 4783 | CXXScopeSpec &SS) { |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4784 | TemplateArgumentListInfo NewTemplateArgs; |
| 4785 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4786 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4787 | typedef TemplateArgumentLocContainerIterator< |
| 4788 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4789 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4790 | ArgIterator(TL, TL.getNumArgs()), |
| 4791 | NewTemplateArgs)) |
| 4792 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4793 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4794 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4795 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4796 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4797 | QualType Result |
| 4798 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4799 | TL.getTypePtr()->getKeyword(), |
| 4800 | DTN->getQualifier(), |
| 4801 | DTN->getIdentifier(), |
| 4802 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4803 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4804 | DependentTemplateSpecializationTypeLoc NewTL |
| 4805 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4806 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4807 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4808 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4809 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4810 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4811 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4812 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4813 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4814 | return Result; |
| 4815 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4816 | |
| 4817 | QualType Result |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4818 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4819 | TL.getTemplateNameLoc(), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4820 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4821 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4822 | if (!Result.isNull()) { |
| 4823 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4824 | TemplateSpecializationTypeLoc NewTL |
| 4825 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4826 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4827 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4828 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4829 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4830 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4831 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4832 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4833 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4834 | return Result; |
| 4835 | } |
| 4836 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4838 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4839 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4840 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4841 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4842 | |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4843 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4844 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4845 | if (TL.getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4846 | QualifierLoc |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4847 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4848 | if (!QualifierLoc) |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4849 | return QualType(); |
| 4850 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4851 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4852 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4853 | if (NamedT.isNull()) |
| 4854 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4855 | |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4856 | // C++0x [dcl.type.elab]p2: |
| 4857 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4858 | // resolves to an alias template specialization, the |
| 4859 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 1804174 | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 4860 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 4861 | if (const TemplateSpecializationType *TST = |
| 4862 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4863 | TemplateName Template = TST->getTemplateName(); |
| 4864 | if (TypeAliasTemplateDecl *TAT = |
| 4865 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4866 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4867 | diag::err_tag_reference_non_tag) << 4; |
| 4868 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4869 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4870 | } |
| 4871 | } |
| 4872 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4873 | QualType Result = TL.getType(); |
| 4874 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4875 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4876 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4877 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4878 | T->getKeyword(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4879 | QualifierLoc, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4880 | if (Result.isNull()) |
| 4881 | return QualType(); |
| 4882 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4883 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4884 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4885 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4886 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4887 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4888 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4889 | |
| 4890 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4891 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4892 | TypeLocBuilder &TLB, |
| 4893 | AttributedTypeLoc TL) { |
| 4894 | const AttributedType *oldType = TL.getTypePtr(); |
| 4895 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4896 | if (modifiedType.isNull()) |
| 4897 | return QualType(); |
| 4898 | |
| 4899 | QualType result = TL.getType(); |
| 4900 | |
| 4901 | // FIXME: dependent operand expressions? |
| 4902 | if (getDerived().AlwaysRebuild() || |
| 4903 | modifiedType != oldType->getModifiedType()) { |
| 4904 | // TODO: this is really lame; we should really be rebuilding the |
| 4905 | // equivalent type from first principles. |
| 4906 | QualType equivalentType |
| 4907 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4908 | if (equivalentType.isNull()) |
| 4909 | return QualType(); |
| 4910 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4911 | modifiedType, |
| 4912 | equivalentType); |
| 4913 | } |
| 4914 | |
| 4915 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4916 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4917 | if (TL.hasAttrOperand()) |
| 4918 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4919 | if (TL.hasAttrExprOperand()) |
| 4920 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4921 | else if (TL.hasAttrEnumOperand()) |
| 4922 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4923 | |
| 4924 | return result; |
| 4925 | } |
| 4926 | |
| 4927 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4928 | QualType |
| 4929 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4930 | ParenTypeLoc TL) { |
| 4931 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4932 | if (Inner.isNull()) |
| 4933 | return QualType(); |
| 4934 | |
| 4935 | QualType Result = TL.getType(); |
| 4936 | if (getDerived().AlwaysRebuild() || |
| 4937 | Inner != TL.getInnerLoc().getType()) { |
| 4938 | Result = getDerived().RebuildParenType(Inner); |
| 4939 | if (Result.isNull()) |
| 4940 | return QualType(); |
| 4941 | } |
| 4942 | |
| 4943 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4944 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4945 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4946 | return Result; |
| 4947 | } |
| 4948 | |
| 4949 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4950 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4951 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4952 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4953 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4954 | NestedNameSpecifierLoc QualifierLoc |
| 4955 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4956 | if (!QualifierLoc) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4957 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4958 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4959 | QualType Result |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4960 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4961 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4962 | QualifierLoc, |
| 4963 | T->getIdentifier(), |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4964 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4965 | if (Result.isNull()) |
| 4966 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4967 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4968 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4969 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4970 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4971 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4972 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4973 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4974 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4975 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4976 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4977 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4978 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4979 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4980 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4981 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4982 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4983 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4984 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4985 | QualType TreeTransform<Derived>:: |
| 4986 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4987 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4988 | NestedNameSpecifierLoc QualifierLoc; |
| 4989 | if (TL.getQualifierLoc()) { |
| 4990 | QualifierLoc |
| 4991 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4992 | if (!QualifierLoc) |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4993 | return QualType(); |
| 4994 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4995 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4996 | return getDerived() |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4997 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | template<typename Derived> |
| 5001 | QualType TreeTransform<Derived>:: |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5002 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5003 | DependentTemplateSpecializationTypeLoc TL, |
| 5004 | NestedNameSpecifierLoc QualifierLoc) { |
| 5005 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5006 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5007 | TemplateArgumentListInfo NewTemplateArgs; |
| 5008 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5009 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5010 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5011 | typedef TemplateArgumentLocContainerIterator< |
| 5012 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5013 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5014 | ArgIterator(TL, TL.getNumArgs()), |
| 5015 | NewTemplateArgs)) |
| 5016 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5017 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5018 | QualType Result |
| 5019 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5020 | QualifierLoc, |
| 5021 | T->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5022 | TL.getTemplateNameLoc(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5023 | NewTemplateArgs); |
| 5024 | if (Result.isNull()) |
| 5025 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5026 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5027 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5028 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5029 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5030 | // Copy information relevant to the template specialization. |
| 5031 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5032 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5033 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5034 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5035 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5036 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5037 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5038 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5039 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5040 | // Copy information relevant to the elaborated type. |
| 5041 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5042 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5043 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5044 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5045 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5046 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5047 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5048 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5049 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5050 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5051 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5052 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5053 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5054 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5055 | } else { |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5056 | TemplateSpecializationTypeLoc SpecTL |
| 5057 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5058 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5059 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5060 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5061 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5062 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5063 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5064 | } |
| 5065 | return Result; |
| 5066 | } |
| 5067 | |
| 5068 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5069 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5070 | PackExpansionTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5071 | QualType Pattern |
| 5072 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5073 | if (Pattern.isNull()) |
| 5074 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5075 | |
| 5076 | QualType Result = TL.getType(); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5077 | if (getDerived().AlwaysRebuild() || |
| 5078 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5079 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5080 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5081 | TL.getEllipsisLoc(), |
| 5082 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5083 | if (Result.isNull()) |
| 5084 | return QualType(); |
| 5085 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5086 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5087 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5088 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5089 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5090 | } |
| 5091 | |
| 5092 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5093 | QualType |
| 5094 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5095 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5096 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5097 | TLB.pushFullCopy(TL); |
| 5098 | return TL.getType(); |
| 5099 | } |
| 5100 | |
| 5101 | template<typename Derived> |
| 5102 | QualType |
| 5103 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5104 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5105 | // ObjCObjectType is never dependent. |
| 5106 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5107 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5108 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | |
| 5110 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5111 | QualType |
| 5112 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5113 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5114 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5115 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5116 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5117 | } |
| 5118 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5119 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5120 | // Statement transformation |
| 5121 | //===----------------------------------------------------------------------===// |
| 5122 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5123 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5124 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5125 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5129 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5130 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5131 | return getDerived().TransformCompoundStmt(S, false); |
| 5132 | } |
| 5133 | |
| 5134 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5135 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5136 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5137 | bool IsStmtExpr) { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5138 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5139 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5140 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5141 | bool SubStmtChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5142 | SmallVector<Stmt*, 8> Statements; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5143 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 5144 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5145 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5146 | if (Result.isInvalid()) { |
| 5147 | // Immediately fail if this was a DeclStmt, since it's very |
| 5148 | // likely that this will cause problems for future statements. |
| 5149 | if (isa<DeclStmt>(*B)) |
| 5150 | return StmtError(); |
| 5151 | |
| 5152 | // Otherwise, just keep processing substatements and fail later. |
| 5153 | SubStmtInvalid = true; |
| 5154 | continue; |
| 5155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5156 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5157 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 5158 | Statements.push_back(Result.takeAs<Stmt>()); |
| 5159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5160 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5161 | if (SubStmtInvalid) |
| 5162 | return StmtError(); |
| 5163 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5164 | if (!getDerived().AlwaysRebuild() && |
| 5165 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5166 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5167 | |
| 5168 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5169 | Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5170 | S->getRBracLoc(), |
| 5171 | IsStmtExpr); |
| 5172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5173 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5174 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5175 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5177 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5178 | { |
Eli Friedman | 6b3014b | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5179 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5180 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5181 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5182 | // Transform the left-hand case value. |
| 5183 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5184 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5185 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5186 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5187 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5188 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5189 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5190 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5191 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5192 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5193 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5195 | // Build the case statement. |
| 5196 | // Case statements are always rebuilt so that they will attached to their |
| 5197 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5198 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5199 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5200 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5201 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5202 | S->getColonLoc()); |
| 5203 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5204 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5205 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5206 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5207 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5208 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5209 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5210 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5211 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5212 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5216 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5218 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5219 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5220 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5221 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5222 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5223 | // Default statements are always rebuilt |
| 5224 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5225 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5226 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5227 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5228 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5229 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5231 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5232 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5233 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5234 | |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5235 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5236 | S->getDecl()); |
| 5237 | if (!LD) |
| 5238 | return StmtError(); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5239 | |
| 5240 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5241 | // FIXME: Pass the real colon location in. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5242 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5243 | cast<LabelDecl>(LD), SourceLocation(), |
| 5244 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5245 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5246 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5247 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5248 | StmtResult |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5249 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5250 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5251 | if (SubStmt.isInvalid()) |
| 5252 | return StmtError(); |
| 5253 | |
| 5254 | // TODO: transform attributes |
| 5255 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5256 | return S; |
| 5257 | |
| 5258 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5259 | S->getAttrs(), |
| 5260 | SubStmt.get()); |
| 5261 | } |
| 5262 | |
| 5263 | template<typename Derived> |
| 5264 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5265 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5266 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5267 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5268 | VarDecl *ConditionVar = 0; |
| 5269 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5270 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5271 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5272 | getDerived().TransformDefinition( |
| 5273 | S->getConditionVariable()->getLocation(), |
| 5274 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5275 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5276 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5277 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5278 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5279 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5280 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5281 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5282 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5283 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5284 | if (S->getCond()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5285 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5286 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5287 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5288 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5289 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5290 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5291 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5292 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5293 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5294 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5295 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5296 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5297 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5298 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5299 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5300 | if (Then.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5301 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5302 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5303 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5304 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5305 | if (Else.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5306 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5307 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5308 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5309 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5310 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5311 | Then.get() == S->getThen() && |
| 5312 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5313 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5314 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5315 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5316 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5317 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5321 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5322 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5323 | // Transform the condition. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5324 | ExprResult Cond; |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5325 | VarDecl *ConditionVar = 0; |
| 5326 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5327 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5328 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5329 | getDerived().TransformDefinition( |
| 5330 | S->getConditionVariable()->getLocation(), |
| 5331 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5332 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5333 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5334 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5335 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5336 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5337 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5338 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5339 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5340 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5341 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5342 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5343 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5344 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5345 | if (Switch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5346 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5347 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5348 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5349 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5350 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5351 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5352 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5353 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5354 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5355 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5356 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5357 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5358 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5359 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5360 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5361 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5362 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5363 | VarDecl *ConditionVar = 0; |
| 5364 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5365 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5366 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5367 | getDerived().TransformDefinition( |
| 5368 | S->getConditionVariable()->getLocation(), |
| 5369 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5370 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5371 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5372 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5373 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5374 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5375 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5376 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5377 | |
| 5378 | if (S->getCond()) { |
| 5379 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5380 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5381 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5382 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5383 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5384 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5385 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5386 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5387 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5388 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5389 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5390 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5391 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5392 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5393 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5394 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5395 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5396 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5397 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5398 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5399 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5400 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5401 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5402 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5403 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5404 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5406 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5407 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5408 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5409 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5410 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5411 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5412 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5413 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5414 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5415 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5416 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5417 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5418 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5419 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5420 | if (!getDerived().AlwaysRebuild() && |
| 5421 | Cond.get() == S->getCond() && |
| 5422 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5423 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5425 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5426 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5427 | S->getRParenLoc()); |
| 5428 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5429 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5430 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5431 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5432 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5433 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5434 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5435 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5436 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5437 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5438 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5439 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5440 | VarDecl *ConditionVar = 0; |
| 5441 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5442 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5443 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5444 | getDerived().TransformDefinition( |
| 5445 | S->getConditionVariable()->getLocation(), |
| 5446 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5447 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5448 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5449 | } else { |
| 5450 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5451 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5452 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5453 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5454 | |
| 5455 | if (S->getCond()) { |
| 5456 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5457 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5458 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5459 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5460 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5461 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5462 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5463 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5464 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5466 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5467 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5468 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5469 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5470 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5471 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5472 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5473 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5474 | |
Richard Smith | 4195637 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 5475 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5476 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5477 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5478 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5479 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5480 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5481 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5482 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5483 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5484 | if (!getDerived().AlwaysRebuild() && |
| 5485 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5486 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5487 | Inc.get() == S->getInc() && |
| 5488 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5489 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5490 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5491 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5492 | Init.get(), FullCond, ConditionVar, |
| 5493 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5497 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5498 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5499 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5500 | S->getLabel()); |
| 5501 | if (!LD) |
| 5502 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5503 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5504 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5505 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5506 | cast<LabelDecl>(LD)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5510 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5511 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5512 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5513 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5514 | return StmtError(); |
Eli Friedman | d29975f | 2012-01-31 22:47:07 +0000 | [diff] [blame] | 5515 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5516 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5517 | if (!getDerived().AlwaysRebuild() && |
| 5518 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5519 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5520 | |
| 5521 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5522 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5526 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5527 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5528 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5529 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5531 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5532 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5533 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5534 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5536 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5537 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5538 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5539 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5540 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5541 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5542 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5543 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5544 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5545 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5546 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5547 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5548 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5549 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5550 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5551 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5552 | bool DeclChanged = false; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5553 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5554 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5555 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5556 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5557 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5558 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5559 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5560 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5561 | if (Transformed != *D) |
| 5562 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5563 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5564 | Decls.push_back(Transformed); |
| 5565 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5566 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5567 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5568 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5569 | |
| 5570 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5571 | S->getStartLoc(), S->getEndLoc()); |
| 5572 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5573 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5574 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5575 | StmtResult |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5576 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5577 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5578 | SmallVector<Expr*, 8> Constraints; |
| 5579 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5580 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5581 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5582 | ExprResult AsmString; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5583 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5584 | |
| 5585 | bool ExprsChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5586 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5587 | // Go through the outputs. |
| 5588 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5589 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5590 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5591 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5592 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5593 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5594 | // Transform the output expr. |
| 5595 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5596 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5597 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5598 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5599 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5600 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5601 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5602 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5603 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5604 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5605 | // Go through the inputs. |
| 5606 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5607 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5608 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5609 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5610 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5611 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5612 | // Transform the input expr. |
| 5613 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5614 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5615 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5616 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5617 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5618 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5619 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5620 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5621 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5622 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5623 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5624 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5625 | |
| 5626 | // Go through the clobbers. |
| 5627 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | 5c7f594 | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5628 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5629 | |
| 5630 | // No need to transform the asm string literal. |
| 5631 | AsmString = SemaRef.Owned(S->getAsmString()); |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5632 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5633 | S->isVolatile(), S->getNumOutputs(), |
| 5634 | S->getNumInputs(), Names.data(), |
| 5635 | Constraints, Exprs, AsmString.get(), |
| 5636 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5637 | } |
| 5638 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5639 | template<typename Derived> |
| 5640 | StmtResult |
| 5641 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5642 | ArrayRef<Token> AsmToks = |
| 5643 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 62f22b8 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5644 | |
Chad Rosier | 7bd092b | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 5645 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
| 5646 | AsmToks, S->getEndLoc()); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5647 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5648 | |
| 5649 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5650 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5651 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5652 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5653 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5654 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5655 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5656 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5657 | // Transform the @catch statements (if present). |
| 5658 | bool AnyCatchChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5659 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5660 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5661 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5662 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5663 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5664 | if (Catch.get() != S->getCatchStmt(I)) |
| 5665 | AnyCatchChanged = true; |
| 5666 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5667 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5668 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5669 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5670 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5671 | if (S->getFinallyStmt()) { |
| 5672 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5673 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5674 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | // If nothing changed, just retain this statement. |
| 5678 | if (!getDerived().AlwaysRebuild() && |
| 5679 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5680 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5681 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5682 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5683 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5684 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5685 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5686 | CatchStmts, Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5687 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5688 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5689 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5690 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5691 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5692 | // Transform the @catch parameter, if there is one. |
| 5693 | VarDecl *Var = 0; |
| 5694 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5695 | TypeSourceInfo *TSInfo = 0; |
| 5696 | if (FromVar->getTypeSourceInfo()) { |
| 5697 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5698 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5699 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5700 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5701 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5702 | QualType T; |
| 5703 | if (TSInfo) |
| 5704 | T = TSInfo->getType(); |
| 5705 | else { |
| 5706 | T = getDerived().TransformType(FromVar->getType()); |
| 5707 | if (T.isNull()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5708 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5709 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5710 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5711 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5712 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5713 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5714 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5715 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5716 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5717 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5718 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5719 | |
| 5720 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5721 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5722 | Var, Body.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 |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5727 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5728 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5729 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5730 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5731 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5732 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5733 | // If nothing changed, just retain this statement. |
| 5734 | if (!getDerived().AlwaysRebuild() && |
| 5735 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5736 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5737 | |
| 5738 | // Build a new statement. |
| 5739 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5740 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5741 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5742 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5743 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5744 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5745 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5746 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5747 | if (S->getThrowExpr()) { |
| 5748 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5749 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5750 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5751 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5752 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5753 | if (!getDerived().AlwaysRebuild() && |
| 5754 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5755 | return getSema().Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5756 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5757 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5758 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5759 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5760 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5761 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5762 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5763 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5764 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5765 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5766 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5767 | return StmtError(); |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5768 | Object = |
| 5769 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5770 | Object.get()); |
| 5771 | if (Object.isInvalid()) |
| 5772 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5773 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5774 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5775 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5776 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5777 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5778 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5779 | // If nothing change, just retain the current statement. |
| 5780 | if (!getDerived().AlwaysRebuild() && |
| 5781 | Object.get() == S->getSynchExpr() && |
| 5782 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5783 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5784 | |
| 5785 | // Build a new statement. |
| 5786 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5787 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5791 | StmtResult |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5792 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5793 | ObjCAutoreleasePoolStmt *S) { |
| 5794 | // Transform the body. |
| 5795 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5796 | if (Body.isInvalid()) |
| 5797 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5798 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5799 | // If nothing changed, just retain this statement. |
| 5800 | if (!getDerived().AlwaysRebuild() && |
| 5801 | Body.get() == S->getSubStmt()) |
| 5802 | return SemaRef.Owned(S); |
| 5803 | |
| 5804 | // Build a new statement. |
| 5805 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5806 | S->getAtLoc(), Body.get()); |
| 5807 | } |
| 5808 | |
| 5809 | template<typename Derived> |
| 5810 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5811 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5812 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5813 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5814 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5815 | if (Element.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5816 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5817 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5818 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5819 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5820 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5821 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5822 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5823 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5824 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5825 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5826 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5827 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5828 | // If nothing changed, just retain this statement. |
| 5829 | if (!getDerived().AlwaysRebuild() && |
| 5830 | Element.get() == S->getElement() && |
| 5831 | Collection.get() == S->getCollection() && |
| 5832 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5833 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5834 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5835 | // Build a new statement. |
| 5836 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5837 | Element.get(), |
| 5838 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5839 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5840 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5841 | } |
| 5842 | |
| 5843 | |
| 5844 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5845 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5846 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5847 | // Transform the exception declaration, if any. |
| 5848 | VarDecl *Var = 0; |
| 5849 | if (S->getExceptionDecl()) { |
| 5850 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5851 | TypeSourceInfo *T = getDerived().TransformType( |
| 5852 | ExceptionDecl->getTypeSourceInfo()); |
| 5853 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5854 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5855 | |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5856 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 5857 | ExceptionDecl->getInnerLocStart(), |
| 5858 | ExceptionDecl->getLocation(), |
| 5859 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5860 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5861 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5862 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5863 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5864 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5865 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5866 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5867 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5868 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5869 | if (!getDerived().AlwaysRebuild() && |
| 5870 | !Var && |
| 5871 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5872 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5873 | |
| 5874 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5875 | Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5876 | Handler.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5877 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5878 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5879 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5880 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5881 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5882 | // Transform the try block itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5883 | StmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5884 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5885 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5886 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5887 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5888 | // Transform the handlers. |
| 5889 | bool HandlerChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5890 | SmallVector<Stmt*, 8> Handlers; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5891 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5892 | StmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5893 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5894 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5895 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5896 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5897 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5898 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5899 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5900 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5901 | if (!getDerived().AlwaysRebuild() && |
| 5902 | TryBlock.get() == S->getTryBlock() && |
| 5903 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5904 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5905 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5906 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5907 | Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5908 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5909 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5910 | template<typename Derived> |
| 5911 | StmtResult |
| 5912 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5913 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 5914 | if (Range.isInvalid()) |
| 5915 | return StmtError(); |
| 5916 | |
| 5917 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 5918 | if (BeginEnd.isInvalid()) |
| 5919 | return StmtError(); |
| 5920 | |
| 5921 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 5922 | if (Cond.isInvalid()) |
| 5923 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 5924 | if (Cond.get()) |
| 5925 | Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); |
| 5926 | if (Cond.isInvalid()) |
| 5927 | return StmtError(); |
| 5928 | if (Cond.get()) |
| 5929 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5930 | |
| 5931 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 5932 | if (Inc.isInvalid()) |
| 5933 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 5934 | if (Inc.get()) |
| 5935 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5936 | |
| 5937 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 5938 | if (LoopVar.isInvalid()) |
| 5939 | return StmtError(); |
| 5940 | |
| 5941 | StmtResult NewStmt = S; |
| 5942 | if (getDerived().AlwaysRebuild() || |
| 5943 | Range.get() != S->getRangeStmt() || |
| 5944 | BeginEnd.get() != S->getBeginEndStmt() || |
| 5945 | Cond.get() != S->getCond() || |
| 5946 | Inc.get() != S->getInc() || |
| 5947 | LoopVar.get() != S->getLoopVarStmt()) |
| 5948 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5949 | S->getColonLoc(), Range.get(), |
| 5950 | BeginEnd.get(), Cond.get(), |
| 5951 | Inc.get(), LoopVar.get(), |
| 5952 | S->getRParenLoc()); |
| 5953 | |
| 5954 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 5955 | if (Body.isInvalid()) |
| 5956 | return StmtError(); |
| 5957 | |
| 5958 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 5959 | // it now so we have a new statement to attach the body to. |
| 5960 | if (Body.get() != S->getBody() && NewStmt.get() == S) |
| 5961 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5962 | S->getColonLoc(), Range.get(), |
| 5963 | BeginEnd.get(), Cond.get(), |
| 5964 | Inc.get(), LoopVar.get(), |
| 5965 | S->getRParenLoc()); |
| 5966 | |
| 5967 | if (NewStmt.get() == S) |
| 5968 | return SemaRef.Owned(S); |
| 5969 | |
| 5970 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 5971 | } |
| 5972 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 5973 | template<typename Derived> |
| 5974 | StmtResult |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5975 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 5976 | MSDependentExistsStmt *S) { |
| 5977 | // Transform the nested-name-specifier, if any. |
| 5978 | NestedNameSpecifierLoc QualifierLoc; |
| 5979 | if (S->getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5980 | QualifierLoc |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5981 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 5982 | if (!QualifierLoc) |
| 5983 | return StmtError(); |
| 5984 | } |
| 5985 | |
| 5986 | // Transform the declaration name. |
| 5987 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 5988 | if (NameInfo.getName()) { |
| 5989 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5990 | if (!NameInfo.getName()) |
| 5991 | return StmtError(); |
| 5992 | } |
| 5993 | |
| 5994 | // Check whether anything changed. |
| 5995 | if (!getDerived().AlwaysRebuild() && |
| 5996 | QualifierLoc == S->getQualifierLoc() && |
| 5997 | NameInfo.getName() == S->getNameInfo().getName()) |
| 5998 | return S; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5999 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6000 | // Determine whether this name exists, if we can. |
| 6001 | CXXScopeSpec SS; |
| 6002 | SS.Adopt(QualifierLoc); |
| 6003 | bool Dependent = false; |
| 6004 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { |
| 6005 | case Sema::IER_Exists: |
| 6006 | if (S->isIfExists()) |
| 6007 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6008 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6009 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6010 | |
| 6011 | case Sema::IER_DoesNotExist: |
| 6012 | if (S->isIfNotExists()) |
| 6013 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6014 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6015 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6016 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6017 | case Sema::IER_Dependent: |
| 6018 | Dependent = true; |
| 6019 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6020 | |
Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6021 | case Sema::IER_Error: |
| 6022 | return StmtError(); |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6023 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6024 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6025 | // We need to continue with the instantiation, so do so now. |
| 6026 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6027 | if (SubStmt.isInvalid()) |
| 6028 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6029 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6030 | // If we have resolved the name, just transform to the substatement. |
| 6031 | if (!Dependent) |
| 6032 | return SubStmt; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6033 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6034 | // The name is still dependent, so build a dependent expression again. |
| 6035 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6036 | S->isIfExists(), |
| 6037 | QualifierLoc, |
| 6038 | NameInfo, |
| 6039 | SubStmt.get()); |
| 6040 | } |
| 6041 | |
| 6042 | template<typename Derived> |
John McCall | 76da55d | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6043 | ExprResult |
| 6044 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6045 | NestedNameSpecifierLoc QualifierLoc; |
| 6046 | if (E->getQualifierLoc()) { |
| 6047 | QualifierLoc |
| 6048 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6049 | if (!QualifierLoc) |
| 6050 | return ExprError(); |
| 6051 | } |
| 6052 | |
| 6053 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6054 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6055 | if (!PD) |
| 6056 | return ExprError(); |
| 6057 | |
| 6058 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6059 | if (Base.isInvalid()) |
| 6060 | return ExprError(); |
| 6061 | |
| 6062 | return new (SemaRef.getASTContext()) |
| 6063 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6064 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6065 | QualifierLoc, E->getMemberLoc()); |
| 6066 | } |
| 6067 | |
| 6068 | template<typename Derived> |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6069 | StmtResult |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6070 | TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 6071 | StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 6072 | if(TryBlock.isInvalid()) return StmtError(); |
| 6073 | |
| 6074 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 6075 | if(!getDerived().AlwaysRebuild() && |
| 6076 | TryBlock.get() == S->getTryBlock() && |
| 6077 | Handler.get() == S->getHandler()) |
| 6078 | return SemaRef.Owned(S); |
| 6079 | |
| 6080 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), |
| 6081 | S->getTryLoc(), |
| 6082 | TryBlock.take(), |
| 6083 | Handler.take()); |
| 6084 | } |
| 6085 | |
| 6086 | template<typename Derived> |
| 6087 | StmtResult |
| 6088 | TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 6089 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 6090 | if(Block.isInvalid()) return StmtError(); |
| 6091 | |
| 6092 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), |
| 6093 | Block.take()); |
| 6094 | } |
| 6095 | |
| 6096 | template<typename Derived> |
| 6097 | StmtResult |
| 6098 | TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 6099 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 6100 | if(FilterExpr.isInvalid()) return StmtError(); |
| 6101 | |
| 6102 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 6103 | if(Block.isInvalid()) return StmtError(); |
| 6104 | |
| 6105 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), |
| 6106 | FilterExpr.take(), |
| 6107 | Block.take()); |
| 6108 | } |
| 6109 | |
| 6110 | template<typename Derived> |
| 6111 | StmtResult |
| 6112 | TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6113 | if(isa<SEHFinallyStmt>(Handler)) |
| 6114 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6115 | else |
| 6116 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6117 | } |
| 6118 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6119 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6120 | // Expression transformation |
| 6121 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6122 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6123 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6124 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6125 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6127 | |
| 6128 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6129 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6130 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6131 | NestedNameSpecifierLoc QualifierLoc; |
| 6132 | if (E->getQualifierLoc()) { |
| 6133 | QualifierLoc |
| 6134 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6135 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6136 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6137 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6138 | |
| 6139 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6140 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6141 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6142 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6143 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6144 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6145 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6146 | if (NameInfo.getName()) { |
| 6147 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6148 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6149 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6150 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6151 | |
| 6152 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6153 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6154 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6155 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6156 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6157 | |
| 6158 | // Mark it referenced in the new context regardless. |
| 6159 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6160 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6161 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6162 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6163 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6164 | |
| 6165 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6166 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6167 | TemplateArgs = &TransArgs; |
| 6168 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6169 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6170 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6171 | E->getNumTemplateArgs(), |
| 6172 | TransArgs)) |
| 6173 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6174 | } |
| 6175 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6176 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6177 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6179 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6180 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6181 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6182 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6183 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6186 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6187 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6188 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6189 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6190 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6191 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6192 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6193 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6194 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6195 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6196 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6197 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6198 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6199 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6200 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6201 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6202 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6203 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6204 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6205 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6206 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6207 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6208 | } |
| 6209 | |
| 6210 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6211 | ExprResult |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6212 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 391ca9f | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 6213 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 6214 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6215 | return SemaRef.MaybeBindToTemporary(E); |
| 6216 | } |
| 6217 | |
| 6218 | template<typename Derived> |
| 6219 | ExprResult |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6220 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6221 | ExprResult ControllingExpr = |
| 6222 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6223 | if (ControllingExpr.isInvalid()) |
| 6224 | return ExprError(); |
| 6225 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6226 | SmallVector<Expr *, 4> AssocExprs; |
| 6227 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6228 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6229 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6230 | if (TS) { |
| 6231 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6232 | if (!AssocType) |
| 6233 | return ExprError(); |
| 6234 | AssocTypes.push_back(AssocType); |
| 6235 | } else { |
| 6236 | AssocTypes.push_back(0); |
| 6237 | } |
| 6238 | |
| 6239 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6240 | if (AssocExpr.isInvalid()) |
| 6241 | return ExprError(); |
| 6242 | AssocExprs.push_back(AssocExpr.release()); |
| 6243 | } |
| 6244 | |
| 6245 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6246 | E->getDefaultLoc(), |
| 6247 | E->getRParenLoc(), |
| 6248 | ControllingExpr.release(), |
| 6249 | AssocTypes.data(), |
| 6250 | AssocExprs.data(), |
| 6251 | E->getNumAssocs()); |
| 6252 | } |
| 6253 | |
| 6254 | template<typename Derived> |
| 6255 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6256 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6257 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6258 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6259 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6260 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6261 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6262 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6263 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6264 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6265 | E->getRParen()); |
| 6266 | } |
| 6267 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6268 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 6269 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 6270 | /// object available. |
| 6271 | template<typename Derived> |
| 6272 | ExprResult |
| 6273 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 6274 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| 6275 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true); |
| 6276 | else |
| 6277 | return getDerived().TransformExpr(E); |
| 6278 | } |
| 6279 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6280 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6281 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6282 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6283 | ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6284 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6285 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6286 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6287 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6288 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6289 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6290 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 6291 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6292 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6293 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6294 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6295 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6296 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6297 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 6298 | // Transform the type. |
| 6299 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6300 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6301 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6302 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6303 | // Transform all of the components into components similar to what the |
| 6304 | // parser uses. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6305 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 6306 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 6307 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6308 | // template code that we don't care. |
| 6309 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6310 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6311 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6312 | SmallVector<Component, 4> Components; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6313 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 6314 | const Node &ON = E->getComponent(I); |
| 6315 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 6316 | Comp.isBrackets = true; |
Abramo Bagnara | 06dec89 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 6317 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 6318 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6319 | switch (ON.getKind()) { |
| 6320 | case Node::Array: { |
| 6321 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6322 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6323 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6324 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6325 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6326 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 6327 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6328 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6329 | break; |
| 6330 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6331 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6332 | case Node::Field: |
| 6333 | case Node::Identifier: |
| 6334 | Comp.isBrackets = false; |
| 6335 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 6336 | if (!Comp.U.IdentInfo) |
| 6337 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6338 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6339 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6340 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 6341 | case Node::Base: |
| 6342 | // Will be recomputed during the rebuild. |
| 6343 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6344 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6345 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6346 | Components.push_back(Comp); |
| 6347 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6348 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6349 | // If nothing changed, retain the existing expression. |
| 6350 | if (!getDerived().AlwaysRebuild() && |
| 6351 | Type == E->getTypeSourceInfo() && |
| 6352 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6353 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6354 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6355 | // Build a new offsetof expression. |
| 6356 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 6357 | Components.data(), Components.size(), |
| 6358 | E->getRParenLoc()); |
| 6359 | } |
| 6360 | |
| 6361 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6362 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 6363 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6364 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 6365 | "opaque value expression requires transformation"); |
| 6366 | return SemaRef.Owned(E); |
| 6367 | } |
| 6368 | |
| 6369 | template<typename Derived> |
| 6370 | ExprResult |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6371 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | 01e19be | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 6372 | // Rebuild the syntactic form. The original syntactic form has |
| 6373 | // opaque-value expressions in it, so strip those away and rebuild |
| 6374 | // the result. This is a really awful way of doing this, but the |
| 6375 | // better solution (rebuilding the semantic expressions and |
| 6376 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 6377 | // TreeTransform to not strip away implicit conversions. |
| 6378 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 6379 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6380 | if (result.isInvalid()) return ExprError(); |
| 6381 | |
| 6382 | // If that gives us a pseudo-object result back, the pseudo-object |
| 6383 | // expression must have been an lvalue-to-rvalue conversion which we |
| 6384 | // should reapply. |
| 6385 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 6386 | result = SemaRef.checkPseudoObjectRValue(result.take()); |
| 6387 | |
| 6388 | return result; |
| 6389 | } |
| 6390 | |
| 6391 | template<typename Derived> |
| 6392 | ExprResult |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6393 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 6394 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6395 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6396 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6397 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6398 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6399 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6400 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6401 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6402 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6403 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6404 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6405 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 6406 | E->getKind(), |
| 6407 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6409 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6410 | // C++0x [expr.sizeof]p1: |
| 6411 | // The operand is either an expression, which is an unevaluated operand |
| 6412 | // [...] |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 6413 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 6414 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6415 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6416 | ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 6417 | if (SubExpr.isInvalid()) |
| 6418 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6419 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6420 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 6421 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6422 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6423 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6424 | E->getOperatorLoc(), |
| 6425 | E->getKind(), |
| 6426 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6428 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6429 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6430 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6431 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6432 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6433 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6434 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6435 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6436 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6437 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6438 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6439 | |
| 6440 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6441 | if (!getDerived().AlwaysRebuild() && |
| 6442 | LHS.get() == E->getLHS() && |
| 6443 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6444 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6445 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6446 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6447 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6448 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6449 | E->getRBracketLoc()); |
| 6450 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6451 | |
| 6452 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6453 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6454 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6455 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6456 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6457 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6458 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6459 | |
| 6460 | // Transform arguments. |
| 6461 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6462 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6463 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6464 | &ArgChanged)) |
| 6465 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6466 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6467 | if (!getDerived().AlwaysRebuild() && |
| 6468 | Callee.get() == E->getCallee() && |
| 6469 | !ArgChanged) |
Dmitri Gribenko | 1ad23d6 | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 6470 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6471 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6472 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6473 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6474 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6475 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6476 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6477 | E->getRParenLoc()); |
| 6478 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6479 | |
| 6480 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6481 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6482 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6483 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6484 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6485 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6486 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6487 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6488 | if (E->hasQualifier()) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6489 | QualifierLoc |
| 6490 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6491 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6492 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6493 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6494 | } |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6495 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6496 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6497 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6498 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6499 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6500 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6501 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6502 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6503 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6504 | if (FoundDecl == E->getMemberDecl()) { |
| 6505 | FoundDecl = Member; |
| 6506 | } else { |
| 6507 | FoundDecl = cast_or_null<NamedDecl>( |
| 6508 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6509 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6510 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6511 | } |
| 6512 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6513 | if (!getDerived().AlwaysRebuild() && |
| 6514 | Base.get() == E->getBase() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6515 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6516 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6517 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6518 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6519 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6520 | // Mark it referenced in the new context regardless. |
| 6521 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6522 | SemaRef.MarkMemberReferenced(E); |
| 6523 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6524 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6525 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6526 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6527 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6528 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6529 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6530 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6531 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6532 | E->getNumTemplateArgs(), |
| 6533 | TransArgs)) |
| 6534 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6535 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6536 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6537 | // FIXME: Bogus source location for the operator |
| 6538 | SourceLocation FakeOperatorLoc |
| 6539 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6540 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6541 | // FIXME: to do this check properly, we will need to preserve the |
| 6542 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6543 | // base (and therefore couldn't do the check) and a |
| 6544 | // nested-name-qualifier (and therefore could do the lookup). |
| 6545 | NamedDecl *FirstQualifierInScope = 0; |
| 6546 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6547 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6548 | E->isArrow(), |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6549 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6550 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6551 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6552 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6553 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6554 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6555 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6556 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6558 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6559 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6560 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6561 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6562 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6563 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6564 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6565 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6566 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6567 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6568 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6569 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6570 | if (!getDerived().AlwaysRebuild() && |
| 6571 | LHS.get() == E->getLHS() && |
| 6572 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6573 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6574 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 6575 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 6576 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 6577 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6578 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6579 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6580 | } |
| 6581 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6582 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6583 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6584 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6585 | CompoundAssignOperator *E) { |
| 6586 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6587 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6588 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6589 | template<typename Derived> |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6590 | ExprResult TreeTransform<Derived>:: |
| 6591 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6592 | // Just rebuild the common and RHS expressions and see whether we |
| 6593 | // get any changes. |
| 6594 | |
| 6595 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6596 | if (commonExpr.isInvalid()) |
| 6597 | return ExprError(); |
| 6598 | |
| 6599 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6600 | if (rhs.isInvalid()) |
| 6601 | return ExprError(); |
| 6602 | |
| 6603 | if (!getDerived().AlwaysRebuild() && |
| 6604 | commonExpr.get() == e->getCommon() && |
| 6605 | rhs.get() == e->getFalseExpr()) |
| 6606 | return SemaRef.Owned(e); |
| 6607 | |
| 6608 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6609 | e->getQuestionLoc(), |
| 6610 | 0, |
| 6611 | e->getColonLoc(), |
| 6612 | rhs.get()); |
| 6613 | } |
| 6614 | |
| 6615 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6616 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6617 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6618 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6619 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6620 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6621 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6622 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6623 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6624 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6625 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6626 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6627 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6628 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6629 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6630 | if (!getDerived().AlwaysRebuild() && |
| 6631 | Cond.get() == E->getCond() && |
| 6632 | LHS.get() == E->getLHS() && |
| 6633 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6634 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6635 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6636 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6637 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6638 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6639 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6640 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6641 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6642 | |
| 6643 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6644 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6645 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6646 | // Implicit casts are eliminated during transformation, since they |
| 6647 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6648 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6649 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6651 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6652 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6653 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6654 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6655 | if (!Type) |
| 6656 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6657 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6658 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6659 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6660 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6661 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6662 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6663 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6664 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6665 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6666 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6667 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6668 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6669 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6670 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6671 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6672 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6673 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6674 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6675 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6676 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6677 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6678 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6679 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6680 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6681 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6682 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6683 | if (Init.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 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6686 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6687 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6688 | Init.get() == E->getInitializer()) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6689 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6690 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6691 | // Note: the expression type doesn't necessarily match the |
| 6692 | // type-as-written, but that's okay, because it should always be |
| 6693 | // derivable from the initializer. |
| 6694 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6695 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6696 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6697 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6698 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6699 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6700 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6701 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6702 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6703 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6704 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6705 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6706 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6707 | if (!getDerived().AlwaysRebuild() && |
| 6708 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6709 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6710 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6711 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6712 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6713 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6714 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6715 | E->getAccessorLoc(), |
| 6716 | E->getAccessor()); |
| 6717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6718 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6719 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6720 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6721 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6722 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6723 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6724 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6725 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6726 | Inits, &InitChanged)) |
| 6727 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6728 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6729 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6730 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6731 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6732 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6733 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6735 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6736 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6737 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6738 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6739 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6740 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6741 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6742 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6743 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6744 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6745 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6746 | // transform the designators. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6747 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6748 | bool ExprChanged = false; |
| 6749 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6750 | DEnd = E->designators_end(); |
| 6751 | D != DEnd; ++D) { |
| 6752 | if (D->isFieldDesignator()) { |
| 6753 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6754 | D->getDotLoc(), |
| 6755 | D->getFieldLoc())); |
| 6756 | continue; |
| 6757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6758 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6759 | if (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6760 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6761 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6762 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6763 | |
| 6764 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6765 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6766 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6767 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6768 | ArrayExprs.push_back(Index.release()); |
| 6769 | continue; |
| 6770 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6771 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6772 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6773 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6774 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6775 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6776 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6777 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6778 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6779 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6780 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6781 | |
| 6782 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6783 | End.get(), |
| 6784 | D->getLBracketLoc(), |
| 6785 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6786 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6787 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6788 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6789 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6790 | ArrayExprs.push_back(Start.release()); |
| 6791 | ArrayExprs.push_back(End.release()); |
| 6792 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6793 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6794 | if (!getDerived().AlwaysRebuild() && |
| 6795 | Init.get() == E->getInit() && |
| 6796 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6797 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6798 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6799 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6800 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6801 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6802 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6803 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6804 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6805 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6806 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6807 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6808 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6809 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6810 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6811 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6812 | QualType T = getDerived().TransformType(E->getType()); |
| 6813 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6814 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6815 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6816 | if (!getDerived().AlwaysRebuild() && |
| 6817 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6818 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6819 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6820 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6821 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6822 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6823 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6824 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6825 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6826 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6827 | if (!TInfo) |
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 SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6831 | if (SubExpr.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() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6835 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6836 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6837 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6838 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6839 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6840 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6841 | } |
| 6842 | |
| 6843 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6844 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6845 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6846 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6847 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6848 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6849 | &ArgumentChanged)) |
| 6850 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6851 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6852 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6853 | Inits, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6854 | E->getRParenLoc()); |
| 6855 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6856 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6857 | /// \brief Transform an address-of-label expression. |
| 6858 | /// |
| 6859 | /// By default, the transformation of an address-of-label expression always |
| 6860 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6861 | /// the corresponding label statement by semantic analysis. |
| 6862 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6863 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6864 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6865 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6866 | E->getLabel()); |
| 6867 | if (!LD) |
| 6868 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6869 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6870 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6871 | cast<LabelDecl>(LD)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6872 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6873 | |
| 6874 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6875 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6876 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6877 | SemaRef.ActOnStartStmtExpr(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6878 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6879 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6880 | if (SubStmt.isInvalid()) { |
| 6881 | SemaRef.ActOnStmtExprError(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6882 | return ExprError(); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6883 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6884 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6885 | if (!getDerived().AlwaysRebuild() && |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6886 | SubStmt.get() == E->getSubStmt()) { |
| 6887 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 6888 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6889 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6890 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6891 | |
| 6892 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6893 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6894 | E->getRParenLoc()); |
| 6895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6896 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6897 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6898 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6899 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6900 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6901 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6902 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6903 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6904 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6905 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6906 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6907 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6908 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6909 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6910 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6911 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6912 | if (!getDerived().AlwaysRebuild() && |
| 6913 | Cond.get() == E->getCond() && |
| 6914 | LHS.get() == E->getLHS() && |
| 6915 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6916 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6917 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6918 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6919 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6920 | E->getRParenLoc()); |
| 6921 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6924 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6925 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6926 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6927 | } |
| 6928 | |
| 6929 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6930 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6931 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6932 | switch (E->getOperator()) { |
| 6933 | case OO_New: |
| 6934 | case OO_Delete: |
| 6935 | case OO_Array_New: |
| 6936 | case OO_Array_Delete: |
| 6937 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6938 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6939 | case OO_Call: { |
| 6940 | // This is a call to an object's operator(). |
| 6941 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6942 | |
| 6943 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6944 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6945 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6946 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6947 | |
| 6948 | // FIXME: Poor location information |
| 6949 | SourceLocation FakeLParenLoc |
| 6950 | = SemaRef.PP.getLocForEndOfToken( |
| 6951 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6952 | |
| 6953 | // Transform the call arguments. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6954 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6955 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6956 | Args)) |
| 6957 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6958 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6959 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6960 | Args, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6961 | E->getLocEnd()); |
| 6962 | } |
| 6963 | |
| 6964 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6965 | case OO_##Name: |
| 6966 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6967 | #include "clang/Basic/OperatorKinds.def" |
| 6968 | case OO_Subscript: |
| 6969 | // Handled below. |
| 6970 | break; |
| 6971 | |
| 6972 | case OO_Conditional: |
| 6973 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6974 | |
| 6975 | case OO_None: |
| 6976 | case NUM_OVERLOADED_OPERATORS: |
| 6977 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6978 | } |
| 6979 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6980 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6981 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6982 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6983 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6984 | ExprResult First; |
| 6985 | if (E->getOperator() == OO_Amp) |
| 6986 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 6987 | else |
| 6988 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6989 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6990 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6991 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6992 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6993 | if (E->getNumArgs() == 2) { |
| 6994 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6995 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6996 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6997 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6998 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6999 | if (!getDerived().AlwaysRebuild() && |
| 7000 | Callee.get() == E->getCallee() && |
| 7001 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7002 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7003 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7004 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7005 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7006 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7007 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7008 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 7009 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7010 | Callee.get(), |
| 7011 | First.get(), |
| 7012 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7013 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7015 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7016 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7017 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7018 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7019 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7020 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7021 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7022 | ExprResult |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7023 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 7024 | // Transform the callee. |
| 7025 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 7026 | if (Callee.isInvalid()) |
| 7027 | return ExprError(); |
| 7028 | |
| 7029 | // Transform exec config. |
| 7030 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 7031 | if (EC.isInvalid()) |
| 7032 | return ExprError(); |
| 7033 | |
| 7034 | // Transform arguments. |
| 7035 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7036 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7037 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7038 | &ArgChanged)) |
| 7039 | return ExprError(); |
| 7040 | |
| 7041 | if (!getDerived().AlwaysRebuild() && |
| 7042 | Callee.get() == E->getCallee() && |
| 7043 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7044 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7045 | |
| 7046 | // FIXME: Wrong source location information for the '('. |
| 7047 | SourceLocation FakeLParenLoc |
| 7048 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 7049 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7050 | Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7051 | E->getRParenLoc(), EC.get()); |
| 7052 | } |
| 7053 | |
| 7054 | template<typename Derived> |
| 7055 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7056 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7057 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7058 | if (!Type) |
| 7059 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7060 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7061 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7062 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7063 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7064 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7065 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7066 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7067 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7068 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7069 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7070 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7071 | E->getStmtClass(), |
Fariborz Jahanian | f799ae1 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7072 | E->getAngleBrackets().getBegin(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7073 | Type, |
Fariborz Jahanian | f799ae1 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7074 | E->getAngleBrackets().getEnd(), |
| 7075 | // FIXME. this should be '(' location |
| 7076 | E->getAngleBrackets().getEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7077 | SubExpr.get(), |
Abramo Bagnara | 6cf7d7d | 2012-10-15 21:08:58 +0000 | [diff] [blame] | 7078 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7079 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7082 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7083 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 7084 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7085 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7086 | |
| 7087 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7088 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7089 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 7090 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7091 | } |
| 7092 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7093 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7094 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7095 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7096 | CXXReinterpretCastExpr *E) { |
| 7097 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7098 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7099 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7100 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7101 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7102 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 7103 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7104 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7105 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7106 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7107 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7108 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7109 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7110 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7111 | if (!Type) |
| 7112 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7113 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7114 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7115 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7116 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7117 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7118 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7119 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7120 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7121 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7122 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7123 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7124 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7125 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7126 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7127 | E->getRParenLoc()); |
| 7128 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7129 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7130 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7131 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7132 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7133 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7134 | TypeSourceInfo *TInfo |
| 7135 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7136 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7137 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7140 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7141 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7142 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7143 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7144 | E->getLocStart(), |
| 7145 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7146 | E->getLocEnd()); |
| 7147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7148 | |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7149 | // We don't know whether the subexpression is potentially evaluated until |
| 7150 | // after we perform semantic analysis. We speculatively assume it is |
| 7151 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7152 | // potentially evaluated. |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7153 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7154 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7155 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7156 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7157 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7158 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7159 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7160 | if (!getDerived().AlwaysRebuild() && |
| 7161 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7162 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7163 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7164 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7165 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7166 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7167 | E->getLocEnd()); |
| 7168 | } |
| 7169 | |
| 7170 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7171 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7172 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7173 | if (E->isTypeOperand()) { |
| 7174 | TypeSourceInfo *TInfo |
| 7175 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7176 | if (!TInfo) |
| 7177 | return ExprError(); |
| 7178 | |
| 7179 | if (!getDerived().AlwaysRebuild() && |
| 7180 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7181 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7182 | |
Douglas Gregor | 3c52a21 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7183 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7184 | E->getLocStart(), |
| 7185 | TInfo, |
| 7186 | E->getLocEnd()); |
| 7187 | } |
| 7188 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7189 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7190 | |
| 7191 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7192 | if (SubExpr.isInvalid()) |
| 7193 | return ExprError(); |
| 7194 | |
| 7195 | if (!getDerived().AlwaysRebuild() && |
| 7196 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7197 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7198 | |
| 7199 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7200 | E->getLocStart(), |
| 7201 | SubExpr.get(), |
| 7202 | E->getLocEnd()); |
| 7203 | } |
| 7204 | |
| 7205 | template<typename Derived> |
| 7206 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7207 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7208 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7209 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7210 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7211 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7212 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7213 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7214 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7215 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7216 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7218 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7219 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7220 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7221 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 7222 | QualType T; |
| 7223 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) |
| 7224 | T = MD->getThisType(getSema().Context); |
Douglas Gregor | e4743be | 2013-03-08 22:43:48 +0000 | [diff] [blame] | 7225 | else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) { |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 7226 | T = getSema().Context.getPointerType( |
Douglas Gregor | e4743be | 2013-03-08 22:43:48 +0000 | [diff] [blame] | 7227 | getSema().Context.getRecordType(Record)); |
| 7228 | } else { |
| 7229 | assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() && |
| 7230 | "this in the wrong scope?"); |
| 7231 | return ExprError(); |
| 7232 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7233 | |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7234 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7235 | // Make sure that we capture 'this'. |
| 7236 | getSema().CheckCXXThisCapture(E->getLocStart()); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7237 | return SemaRef.Owned(E); |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7238 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7239 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7240 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7241 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7242 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7243 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7244 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7245 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7246 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7247 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7248 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7249 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7250 | if (!getDerived().AlwaysRebuild() && |
| 7251 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7252 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7253 | |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7254 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7255 | E->isThrownVariableInScope()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7256 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7257 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7258 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7259 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7260 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7261 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7262 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7263 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7264 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7265 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7266 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7267 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7268 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7269 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7270 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7271 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7272 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7273 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7274 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7275 | ExprResult |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 7276 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7277 | FieldDecl *Field |
| 7278 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7279 | E->getField())); |
| 7280 | if (!Field) |
| 7281 | return ExprError(); |
| 7282 | |
| 7283 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
| 7284 | return SemaRef.Owned(E); |
| 7285 | |
| 7286 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 7287 | } |
| 7288 | |
| 7289 | template<typename Derived> |
| 7290 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7291 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 7292 | CXXScalarValueInitExpr *E) { |
| 7293 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7294 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7295 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7296 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7297 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7298 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7299 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7300 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7301 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7302 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 7303 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7305 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7306 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7307 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7308 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7309 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7310 | TypeSourceInfo *AllocTypeInfo |
| 7311 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 7312 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7313 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7314 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7315 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7316 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7317 | if (ArraySize.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7318 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7319 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7320 | // Transform the placement arguments (if any). |
| 7321 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7322 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7323 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7324 | E->getNumPlacementArgs(), true, |
| 7325 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7326 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7327 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7328 | // Transform the initializer (if any). |
| 7329 | Expr *OldInit = E->getInitializer(); |
| 7330 | ExprResult NewInit; |
| 7331 | if (OldInit) |
| 7332 | NewInit = getDerived().TransformExpr(OldInit); |
| 7333 | if (NewInit.isInvalid()) |
| 7334 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7335 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7336 | // Transform new operator and delete operator. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7337 | FunctionDecl *OperatorNew = 0; |
| 7338 | if (E->getOperatorNew()) { |
| 7339 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7340 | getDerived().TransformDecl(E->getLocStart(), |
| 7341 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7342 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7343 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7344 | } |
| 7345 | |
| 7346 | FunctionDecl *OperatorDelete = 0; |
| 7347 | if (E->getOperatorDelete()) { |
| 7348 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7349 | getDerived().TransformDecl(E->getLocStart(), |
| 7350 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7351 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7352 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7353 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7354 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7355 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7356 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7357 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7358 | NewInit.get() == OldInit && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7359 | OperatorNew == E->getOperatorNew() && |
| 7360 | OperatorDelete == E->getOperatorDelete() && |
| 7361 | !ArgumentChanged) { |
| 7362 | // Mark any declarations we need as referenced. |
| 7363 | // FIXME: instantiation-specific. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7364 | if (OperatorNew) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7365 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7366 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7367 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7368 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7369 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7370 | QualType ElementType |
| 7371 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 7372 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 7373 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 7374 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7375 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7376 | } |
| 7377 | } |
| 7378 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7379 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7380 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7381 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7382 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7383 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7384 | if (!ArraySize.get()) { |
| 7385 | // If no array size was specified, but the new expression was |
| 7386 | // instantiated with an array type (e.g., "new T" where T is |
| 7387 | // instantiated with "int[4]"), extract the outer bound from the |
| 7388 | // array type as our array size. We do this with constant and |
| 7389 | // dependently-sized array types. |
| 7390 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 7391 | if (!ArrayT) { |
| 7392 | // Do nothing |
| 7393 | } else if (const ConstantArrayType *ConsArrayT |
| 7394 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7395 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7396 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7397 | ConsArrayT->getSize(), |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7398 | SemaRef.Context.getSizeType(), |
| 7399 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7400 | AllocType = ConsArrayT->getElementType(); |
| 7401 | } else if (const DependentSizedArrayType *DepArrayT |
| 7402 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 7403 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7404 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7405 | AllocType = DepArrayT->getElementType(); |
| 7406 | } |
| 7407 | } |
| 7408 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7409 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7410 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 7411 | E->isGlobalNew(), |
| 7412 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7413 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7414 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 7415 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7416 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7417 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7418 | ArraySize.get(), |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7419 | E->getDirectInitRange(), |
| 7420 | NewInit.take()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7421 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7422 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7423 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7424 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7425 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7426 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7427 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7428 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7429 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7430 | // Transform the delete operator, if known. |
| 7431 | FunctionDecl *OperatorDelete = 0; |
| 7432 | if (E->getOperatorDelete()) { |
| 7433 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7434 | getDerived().TransformDecl(E->getLocStart(), |
| 7435 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7436 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7437 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7438 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7439 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7440 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7441 | Operand.get() == E->getArgument() && |
| 7442 | OperatorDelete == E->getOperatorDelete()) { |
| 7443 | // Mark any declarations we need as referenced. |
| 7444 | // FIXME: instantiation-specific. |
| 7445 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7446 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7447 | |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7448 | if (!E->getArgument()->isTypeDependent()) { |
| 7449 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7450 | E->getDestroyedType()); |
| 7451 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7452 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7453 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7454 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7455 | } |
| 7456 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7457 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7458 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7459 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7460 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7461 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7462 | E->isGlobalDelete(), |
| 7463 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7464 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7465 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7466 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7467 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7468 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7469 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7470 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7471 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7472 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7473 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7474 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7475 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7476 | bool MayBePseudoDestructor = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7477 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7478 | E->getOperatorLoc(), |
| 7479 | E->isArrow()? tok::arrow : tok::period, |
| 7480 | ObjectTypePtr, |
| 7481 | MayBePseudoDestructor); |
| 7482 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7483 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7484 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7485 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7486 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7487 | if (QualifierLoc) { |
| 7488 | QualifierLoc |
| 7489 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7490 | if (!QualifierLoc) |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7491 | return ExprError(); |
| 7492 | } |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7493 | CXXScopeSpec SS; |
| 7494 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7495 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7496 | PseudoDestructorTypeStorage Destroyed; |
| 7497 | if (E->getDestroyedTypeInfo()) { |
| 7498 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7499 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7500 | ObjectType, 0, SS); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7501 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7502 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7503 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 7504 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7505 | // We aren't likely to be able to resolve the identifier down to a type |
| 7506 | // now anyway, so just retain the identifier. |
| 7507 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7508 | E->getDestroyedTypeLoc()); |
| 7509 | } else { |
| 7510 | // Look for a destructor known with the given name. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7511 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7512 | *E->getDestroyedTypeIdentifier(), |
| 7513 | E->getDestroyedTypeLoc(), |
| 7514 | /*Scope=*/0, |
| 7515 | SS, ObjectTypePtr, |
| 7516 | false); |
| 7517 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7518 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7519 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7520 | Destroyed |
| 7521 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7522 | E->getDestroyedTypeLoc()); |
| 7523 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7524 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7525 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7526 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 303b96f | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 7527 | CXXScopeSpec EmptySS; |
| 7528 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| 7529 | E->getScopeTypeInfo(), ObjectType, 0, EmptySS); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7530 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7531 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7532 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7533 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7534 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7535 | E->getOperatorLoc(), |
| 7536 | E->isArrow(), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7537 | SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7538 | ScopeTypeInfo, |
| 7539 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7540 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7541 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7543 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7544 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7545 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7546 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7547 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7548 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7549 | Sema::LookupOrdinaryName); |
| 7550 | |
| 7551 | // Transform all the decls. |
| 7552 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7553 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7554 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7555 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7556 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7557 | if (!InstD) { |
| 7558 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7559 | // This can happen because of dependent hiding. |
| 7560 | if (isa<UsingShadowDecl>(*I)) |
| 7561 | continue; |
| 7562 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7563 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7564 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7565 | |
| 7566 | // Expand using declarations. |
| 7567 | if (isa<UsingDecl>(InstD)) { |
| 7568 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7569 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7570 | E = UD->shadow_end(); I != E; ++I) |
| 7571 | R.addDecl(*I); |
| 7572 | continue; |
| 7573 | } |
| 7574 | |
| 7575 | R.addDecl(InstD); |
| 7576 | } |
| 7577 | |
| 7578 | // Resolve a kind, but don't do any further analysis. If it's |
| 7579 | // ambiguous, the callee needs to deal with it. |
| 7580 | R.resolveKind(); |
| 7581 | |
| 7582 | // Rebuild the nested-name qualifier, if present. |
| 7583 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7584 | if (Old->getQualifierLoc()) { |
| 7585 | NestedNameSpecifierLoc QualifierLoc |
| 7586 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7587 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7588 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7589 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7590 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7591 | } |
| 7592 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7593 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7594 | CXXRecordDecl *NamingClass |
| 7595 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7596 | Old->getNameLoc(), |
| 7597 | Old->getNamingClass())); |
| 7598 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7599 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7600 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7601 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7602 | } |
| 7603 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7604 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7605 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7606 | // If we have neither explicit template arguments, nor the template keyword, |
| 7607 | // it's a normal declaration name. |
| 7608 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7609 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7610 | |
| 7611 | // If we have template arguments, rebuild them, then rebuild the |
| 7612 | // templateid expression. |
| 7613 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 02e221b | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 7614 | if (Old->hasExplicitTemplateArgs() && |
| 7615 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7616 | Old->getNumTemplateArgs(), |
| 7617 | TransArgs)) |
| 7618 | return ExprError(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7619 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7620 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7621 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7622 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7624 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7625 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7626 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7627 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7628 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7629 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7630 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7631 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7632 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7633 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7634 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7635 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7636 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7637 | T, |
| 7638 | E->getLocEnd()); |
| 7639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7640 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7641 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7642 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7643 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7644 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7645 | if (!LhsT) |
| 7646 | return ExprError(); |
| 7647 | |
| 7648 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7649 | if (!RhsT) |
| 7650 | return ExprError(); |
| 7651 | |
| 7652 | if (!getDerived().AlwaysRebuild() && |
| 7653 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7654 | return SemaRef.Owned(E); |
| 7655 | |
| 7656 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7657 | E->getLocStart(), |
| 7658 | LhsT, RhsT, |
| 7659 | E->getLocEnd()); |
| 7660 | } |
| 7661 | |
| 7662 | template<typename Derived> |
| 7663 | ExprResult |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7664 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 7665 | bool ArgChanged = false; |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7666 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7667 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 7668 | TypeSourceInfo *From = E->getArg(I); |
| 7669 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7670 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7671 | TypeLocBuilder TLB; |
| 7672 | TLB.reserve(FromTL.getFullDataSize()); |
| 7673 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 7674 | if (To.isNull()) |
| 7675 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7676 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7677 | if (To == From->getType()) |
| 7678 | Args.push_back(From); |
| 7679 | else { |
| 7680 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7681 | ArgChanged = true; |
| 7682 | } |
| 7683 | continue; |
| 7684 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7685 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7686 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7687 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7688 | // We have a pack expansion. Instantiate it. |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7689 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7690 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 7691 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7692 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7693 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7694 | // Determine whether the set of unexpanded parameter packs can and should |
| 7695 | // be expanded. |
| 7696 | bool Expand = true; |
| 7697 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 7698 | Optional<unsigned> OrigNumExpansions = |
| 7699 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 7700 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7701 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 7702 | PatternTL.getSourceRange(), |
| 7703 | Unexpanded, |
| 7704 | Expand, RetainExpansion, |
| 7705 | NumExpansions)) |
| 7706 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7707 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7708 | if (!Expand) { |
| 7709 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7710 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7711 | // expansion. |
| 7712 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7713 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7714 | TypeLocBuilder TLB; |
| 7715 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 7716 | |
| 7717 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7718 | if (To.isNull()) |
| 7719 | return ExprError(); |
| 7720 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7721 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7722 | PatternTL.getSourceRange(), |
| 7723 | ExpansionTL.getEllipsisLoc(), |
| 7724 | NumExpansions); |
| 7725 | if (To.isNull()) |
| 7726 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7727 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7728 | PackExpansionTypeLoc ToExpansionTL |
| 7729 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7730 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7731 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7732 | continue; |
| 7733 | } |
| 7734 | |
| 7735 | // Expand the pack expansion by substituting for each argument in the |
| 7736 | // pack(s). |
| 7737 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7738 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 7739 | TypeLocBuilder TLB; |
| 7740 | TLB.reserve(PatternTL.getFullDataSize()); |
| 7741 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7742 | if (To.isNull()) |
| 7743 | return ExprError(); |
| 7744 | |
| 7745 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7746 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7747 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7748 | if (!RetainExpansion) |
| 7749 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7750 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7751 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 7752 | // forgetting the partially-substituted parameter pack. |
| 7753 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 7754 | |
| 7755 | TypeLocBuilder TLB; |
| 7756 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7757 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7758 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7759 | if (To.isNull()) |
| 7760 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7761 | |
| 7762 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7763 | PatternTL.getSourceRange(), |
| 7764 | ExpansionTL.getEllipsisLoc(), |
| 7765 | NumExpansions); |
| 7766 | if (To.isNull()) |
| 7767 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7768 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7769 | PackExpansionTypeLoc ToExpansionTL |
| 7770 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7771 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7772 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7773 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7774 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7775 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 7776 | return SemaRef.Owned(E); |
| 7777 | |
| 7778 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 7779 | E->getLocStart(), |
| 7780 | Args, |
| 7781 | E->getLocEnd()); |
| 7782 | } |
| 7783 | |
| 7784 | template<typename Derived> |
| 7785 | ExprResult |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 7786 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 7787 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7788 | if (!T) |
| 7789 | return ExprError(); |
| 7790 | |
| 7791 | if (!getDerived().AlwaysRebuild() && |
| 7792 | T == E->getQueriedTypeSourceInfo()) |
| 7793 | return SemaRef.Owned(E); |
| 7794 | |
| 7795 | ExprResult SubExpr; |
| 7796 | { |
| 7797 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7798 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 7799 | if (SubExpr.isInvalid()) |
| 7800 | return ExprError(); |
| 7801 | |
| 7802 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 7803 | return SemaRef.Owned(E); |
| 7804 | } |
| 7805 | |
| 7806 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 7807 | E->getLocStart(), |
| 7808 | T, |
| 7809 | SubExpr.get(), |
| 7810 | E->getLocEnd()); |
| 7811 | } |
| 7812 | |
| 7813 | template<typename Derived> |
| 7814 | ExprResult |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 7815 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 7816 | ExprResult SubExpr; |
| 7817 | { |
| 7818 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7819 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 7820 | if (SubExpr.isInvalid()) |
| 7821 | return ExprError(); |
| 7822 | |
| 7823 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 7824 | return SemaRef.Owned(E); |
| 7825 | } |
| 7826 | |
| 7827 | return getDerived().RebuildExpressionTrait( |
| 7828 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 7829 | } |
| 7830 | |
| 7831 | template<typename Derived> |
| 7832 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7833 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7834 | DependentScopeDeclRefExpr *E) { |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7835 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false); |
| 7836 | } |
| 7837 | |
| 7838 | template<typename Derived> |
| 7839 | ExprResult |
| 7840 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 7841 | DependentScopeDeclRefExpr *E, |
| 7842 | bool IsAddressOfOperand) { |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7843 | NestedNameSpecifierLoc QualifierLoc |
| 7844 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7845 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7846 | return ExprError(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7847 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7848 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7849 | // TODO: If this is a conversion-function-id, verify that the |
| 7850 | // destination type name (if present) resolves the same way after |
| 7851 | // instantiation as it did in the local scope. |
| 7852 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7853 | DeclarationNameInfo NameInfo |
| 7854 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 7855 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7856 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7857 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7858 | if (!E->hasExplicitTemplateArgs()) { |
| 7859 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7860 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7861 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 7862 | // if name has not changed, DNLoc has not changed either. |
| 7863 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7864 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7865 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7866 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7867 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7868 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7869 | /*TemplateArgs*/ 0, |
| 7870 | IsAddressOfOperand); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 7871 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7872 | |
| 7873 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7874 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7875 | E->getNumTemplateArgs(), |
| 7876 | TransArgs)) |
| 7877 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7878 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7879 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7880 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7881 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7882 | &TransArgs, |
| 7883 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7884 | } |
| 7885 | |
| 7886 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7887 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7888 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 7889 | // CXXConstructExprs other than for list-initialization and |
| 7890 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 7891 | // a 1-argument construction we just transform that argument. |
Richard Smith | 73ed67c | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 7892 | if ((E->getNumArgs() == 1 || |
| 7893 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 7894 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 7895 | !E->isListInitialization()) |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 7896 | return getDerived().TransformExpr(E->getArg(0)); |
| 7897 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7898 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 7899 | |
| 7900 | QualType T = getDerived().TransformType(E->getType()); |
| 7901 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7902 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7903 | |
| 7904 | CXXConstructorDecl *Constructor |
| 7905 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7906 | getDerived().TransformDecl(E->getLocStart(), |
| 7907 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7908 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7909 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7910 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7911 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7912 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7913 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7914 | &ArgumentChanged)) |
| 7915 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7916 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7917 | if (!getDerived().AlwaysRebuild() && |
| 7918 | T == E->getType() && |
| 7919 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7920 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7921 | // Mark the constructor as referenced. |
| 7922 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7923 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7924 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7925 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7926 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 7927 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 7928 | Constructor, E->isElidable(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7929 | Args, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 7930 | E->hadMultipleCandidates(), |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 7931 | E->isListInitialization(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7932 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 7933 | E->getConstructionKind(), |
| 7934 | E->getParenRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7935 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7936 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7937 | /// \brief Transform a C++ temporary-binding expression. |
| 7938 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7939 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 7940 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7941 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7942 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7943 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7944 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7945 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7946 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7947 | /// \brief Transform a C++ expression that contains cleanups that should |
| 7948 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7949 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7950 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7951 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7952 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7953 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7954 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7955 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7956 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7957 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7958 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7959 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7960 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7961 | CXXTemporaryObjectExpr *E) { |
| 7962 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7963 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7964 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7965 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7966 | CXXConstructorDecl *Constructor |
| 7967 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7968 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7969 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7970 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7971 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7972 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7973 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7974 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7975 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7976 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7977 | &ArgumentChanged)) |
| 7978 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7979 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7980 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7981 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7982 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7983 | !ArgumentChanged) { |
| 7984 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7985 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7986 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7987 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7988 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 7989 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7990 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 7991 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7992 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7993 | E->getLocEnd()); |
| 7994 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7995 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7996 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7997 | ExprResult |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 7998 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7999 | // Transform the type of the lambda parameters and start the definition of |
| 8000 | // the lambda itself. |
| 8001 | TypeSourceInfo *MethodTy |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8002 | = TransformType(E->getCallOperator()->getTypeSourceInfo()); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8003 | if (!MethodTy) |
| 8004 | return ExprError(); |
| 8005 | |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8006 | // Create the local class that will describe the lambda. |
| 8007 | CXXRecordDecl *Class |
| 8008 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| 8009 | MethodTy, |
| 8010 | /*KnownDependent=*/false); |
| 8011 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 8012 | |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8013 | // Transform lambda parameters. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8014 | SmallVector<QualType, 4> ParamTypes; |
| 8015 | SmallVector<ParmVarDecl *, 4> Params; |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8016 | if (getDerived().TransformFunctionTypeParams(E->getLocStart(), |
| 8017 | E->getCallOperator()->param_begin(), |
| 8018 | E->getCallOperator()->param_size(), |
| 8019 | 0, ParamTypes, &Params)) |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8020 | return ExprError(); |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8021 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8022 | // Build the call operator. |
| 8023 | CXXMethodDecl *CallOperator |
| 8024 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8025 | MethodTy, |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8026 | E->getCallOperator()->getLocEnd(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8027 | Params); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8028 | getDerived().transformAttrs(E->getCallOperator(), CallOperator); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8029 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8030 | return getDerived().TransformLambdaScope(E, CallOperator); |
| 8031 | } |
| 8032 | |
| 8033 | template<typename Derived> |
| 8034 | ExprResult |
| 8035 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
| 8036 | CXXMethodDecl *CallOperator) { |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8037 | // Introduce the context of the call operator. |
| 8038 | Sema::ContextRAII SavedContext(getSema(), CallOperator); |
| 8039 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8040 | // Enter the scope of the lambda. |
| 8041 | sema::LambdaScopeInfo *LSI |
| 8042 | = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(), |
| 8043 | E->getCaptureDefault(), |
| 8044 | E->hasExplicitParameters(), |
| 8045 | E->hasExplicitResultType(), |
| 8046 | E->isMutable()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8047 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8048 | // Transform captures. |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8049 | bool Invalid = false; |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8050 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8051 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8052 | CEnd = E->capture_end(); |
| 8053 | C != CEnd; ++C) { |
| 8054 | // When we hit the first implicit capture, tell Sema that we've finished |
| 8055 | // the list of explicit captures. |
| 8056 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 8057 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8058 | FinishedExplicitCaptures = true; |
| 8059 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8060 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8061 | // Capturing 'this' is trivial. |
| 8062 | if (C->capturesThis()) { |
| 8063 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 8064 | continue; |
| 8065 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8066 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8067 | // Determine the capture kind for Sema. |
| 8068 | Sema::TryCaptureKind Kind |
| 8069 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 8070 | : C->getCaptureKind() == LCK_ByCopy |
| 8071 | ? Sema::TryCapture_ExplicitByVal |
| 8072 | : Sema::TryCapture_ExplicitByRef; |
| 8073 | SourceLocation EllipsisLoc; |
| 8074 | if (C->isPackExpansion()) { |
| 8075 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 8076 | bool ShouldExpand = false; |
| 8077 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8078 | Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8079 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 8080 | C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8081 | Unexpanded, |
| 8082 | ShouldExpand, RetainExpansion, |
| 8083 | NumExpansions)) |
| 8084 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8085 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8086 | if (ShouldExpand) { |
| 8087 | // The transform has determined that we should perform an expansion; |
| 8088 | // transform and capture each of the arguments. |
| 8089 | // expansion of the pattern. Do so. |
| 8090 | VarDecl *Pack = C->getCapturedVar(); |
| 8091 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8092 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8093 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8094 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8095 | Pack)); |
| 8096 | if (!CapturedVar) { |
| 8097 | Invalid = true; |
| 8098 | continue; |
| 8099 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8100 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8101 | // Capture the transformed variable. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8102 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 8103 | } |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8104 | continue; |
| 8105 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8106 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8107 | EllipsisLoc = C->getEllipsisLoc(); |
| 8108 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8109 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8110 | // Transform the captured variable. |
| 8111 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8112 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8113 | C->getCapturedVar())); |
| 8114 | if (!CapturedVar) { |
| 8115 | Invalid = true; |
| 8116 | continue; |
| 8117 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8118 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8119 | // Capture the transformed variable. |
Douglas Gregor | 999713e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 8120 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8121 | } |
| 8122 | if (!FinishedExplicitCaptures) |
| 8123 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8124 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8125 | |
| 8126 | // Enter a new evaluation context to insulate the lambda from any |
| 8127 | // cleanups from the enclosing full-expression. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8128 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8129 | |
| 8130 | if (Invalid) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8131 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8132 | /*IsInstantiation=*/true); |
| 8133 | return ExprError(); |
| 8134 | } |
| 8135 | |
| 8136 | // Instantiate the body of the lambda expression. |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8137 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 8138 | if (Body.isInvalid()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8139 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8140 | /*IsInstantiation=*/true); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8141 | return ExprError(); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8142 | } |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 8143 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8144 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 8145 | /*CurScope=*/0, /*IsInstantiation=*/true); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8146 | } |
| 8147 | |
| 8148 | template<typename Derived> |
| 8149 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8150 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8151 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8152 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8153 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8154 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8155 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8156 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8157 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8158 | Args.reserve(E->arg_size()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8159 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8160 | &ArgumentChanged)) |
| 8161 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8162 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8163 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8164 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8165 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8166 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8167 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8168 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8169 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8170 | E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8171 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8172 | E->getRParenLoc()); |
| 8173 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8174 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8175 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8176 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8177 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8178 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8179 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8180 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8181 | Expr *OldBase; |
| 8182 | QualType BaseType; |
| 8183 | QualType ObjectType; |
| 8184 | if (!E->isImplicitAccess()) { |
| 8185 | OldBase = E->getBase(); |
| 8186 | Base = getDerived().TransformExpr(OldBase); |
| 8187 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8188 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8189 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8190 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8191 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8192 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8193 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8194 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8195 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8196 | ObjectTy, |
| 8197 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8198 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8199 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8200 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8201 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8202 | BaseType = ((Expr*) Base.get())->getType(); |
| 8203 | } else { |
| 8204 | OldBase = 0; |
| 8205 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 8206 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 8207 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8208 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8209 | // Transform the first part of the nested-name-specifier that qualifies |
| 8210 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 8211 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8212 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8213 | E->getFirstQualifierFoundInScope(), |
| 8214 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8215 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8216 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8217 | if (E->getQualifier()) { |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8218 | QualifierLoc |
| 8219 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 8220 | ObjectType, |
| 8221 | FirstQualifierInScope); |
| 8222 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8223 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8225 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8226 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 8227 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8228 | // TODO: If this is a conversion-function-id, verify that the |
| 8229 | // destination type name (if present) resolves the same way after |
| 8230 | // instantiation as it did in the local scope. |
| 8231 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8232 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8233 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8234 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8235 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8236 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8237 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8238 | // This is a reference to a member without an explicitly-specified |
| 8239 | // template argument list. Optimize for this common case. |
| 8240 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8241 | Base.get() == OldBase && |
| 8242 | BaseType == E->getBaseType() && |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8243 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8244 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8245 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8246 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8247 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8248 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8249 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8250 | E->isArrow(), |
| 8251 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8252 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8253 | TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8254 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8255 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8256 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8257 | } |
| 8258 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8259 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8260 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8261 | E->getNumTemplateArgs(), |
| 8262 | TransArgs)) |
| 8263 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8264 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8265 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8266 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8267 | E->isArrow(), |
| 8268 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8269 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8270 | TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8271 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8272 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8273 | &TransArgs); |
| 8274 | } |
| 8275 | |
| 8276 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8277 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8278 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8279 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8280 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8281 | QualType BaseType; |
| 8282 | if (!Old->isImplicitAccess()) { |
| 8283 | Base = getDerived().TransformExpr(Old->getBase()); |
| 8284 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8285 | return ExprError(); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 8286 | Base = getSema().PerformMemberExprBaseConversion(Base.take(), |
| 8287 | Old->isArrow()); |
| 8288 | if (Base.isInvalid()) |
| 8289 | return ExprError(); |
| 8290 | BaseType = Base.get()->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8291 | } else { |
| 8292 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 8293 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8294 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8295 | NestedNameSpecifierLoc QualifierLoc; |
| 8296 | if (Old->getQualifierLoc()) { |
| 8297 | QualifierLoc |
| 8298 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8299 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8300 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8301 | } |
| 8302 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8303 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8304 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8305 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8306 | Sema::LookupOrdinaryName); |
| 8307 | |
| 8308 | // Transform all the decls. |
| 8309 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 8310 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8311 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8312 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 8313 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8314 | if (!InstD) { |
| 8315 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8316 | // This can happen because of dependent hiding. |
| 8317 | if (isa<UsingShadowDecl>(*I)) |
| 8318 | continue; |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8319 | else { |
| 8320 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8321 | return ExprError(); |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8322 | } |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8323 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8324 | |
| 8325 | // Expand using declarations. |
| 8326 | if (isa<UsingDecl>(InstD)) { |
| 8327 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 8328 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 8329 | E = UD->shadow_end(); I != E; ++I) |
| 8330 | R.addDecl(*I); |
| 8331 | continue; |
| 8332 | } |
| 8333 | |
| 8334 | R.addDecl(InstD); |
| 8335 | } |
| 8336 | |
| 8337 | R.resolveKind(); |
| 8338 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8339 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 8340 | if (Old->getNamingClass()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8341 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8342 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8343 | Old->getMemberLoc(), |
| 8344 | Old->getNamingClass())); |
| 8345 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8346 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8347 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8348 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8349 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8350 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8351 | TemplateArgumentListInfo TransArgs; |
| 8352 | if (Old->hasExplicitTemplateArgs()) { |
| 8353 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 8354 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8355 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 8356 | Old->getNumTemplateArgs(), |
| 8357 | TransArgs)) |
| 8358 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8359 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8360 | |
| 8361 | // FIXME: to do this check properly, we will need to preserve the |
| 8362 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8363 | // base (and therefore couldn't do the check) and a |
| 8364 | // nested-name-qualifier (and therefore could do the lookup). |
| 8365 | NamedDecl *FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8366 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8367 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8368 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8369 | Old->getOperatorLoc(), |
| 8370 | Old->isArrow(), |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8371 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8372 | TemplateKWLoc, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8373 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8374 | R, |
| 8375 | (Old->hasExplicitTemplateArgs() |
| 8376 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8377 | } |
| 8378 | |
| 8379 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8380 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8381 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Sean Hunt | eea06c6 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 8382 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8383 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 8384 | if (SubExpr.isInvalid()) |
| 8385 | return ExprError(); |
| 8386 | |
| 8387 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8388 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8389 | |
| 8390 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 8391 | } |
| 8392 | |
| 8393 | template<typename Derived> |
| 8394 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8395 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8396 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 8397 | if (Pattern.isInvalid()) |
| 8398 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8399 | |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8400 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 8401 | return SemaRef.Owned(E); |
| 8402 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 8403 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 8404 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8405 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8406 | |
| 8407 | template<typename Derived> |
| 8408 | ExprResult |
| 8409 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 8410 | // If E is not value-dependent, then nothing will change when we transform it. |
| 8411 | // Note: This is an instantiation-centric view. |
| 8412 | if (!E->isValueDependent()) |
| 8413 | return SemaRef.Owned(E); |
| 8414 | |
| 8415 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 8416 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8417 | // so |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8418 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 8419 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8420 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8421 | Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8422 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 8423 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8424 | ShouldExpand, RetainExpansion, |
| 8425 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8426 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8427 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8428 | if (RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8429 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8430 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8431 | NamedDecl *Pack = E->getPack(); |
| 8432 | if (!ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8433 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8434 | Pack)); |
| 8435 | if (!Pack) |
| 8436 | return ExprError(); |
| 8437 | } |
| 8438 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8439 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8440 | // We now know the length of the parameter pack, so build a new expression |
| 8441 | // that stores that length. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8442 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 8443 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8444 | NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8445 | } |
| 8446 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8447 | template<typename Derived> |
| 8448 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 8449 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 8450 | SubstNonTypeTemplateParmPackExpr *E) { |
| 8451 | // Default behavior is to do nothing with this transformation. |
| 8452 | return SemaRef.Owned(E); |
| 8453 | } |
| 8454 | |
| 8455 | template<typename Derived> |
| 8456 | ExprResult |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 8457 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 8458 | SubstNonTypeTemplateParmExpr *E) { |
| 8459 | // Default behavior is to do nothing with this transformation. |
| 8460 | return SemaRef.Owned(E); |
| 8461 | } |
| 8462 | |
| 8463 | template<typename Derived> |
| 8464 | ExprResult |
Richard Smith | 9a4db03 | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 8465 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 8466 | // Default behavior is to do nothing with this transformation. |
| 8467 | return SemaRef.Owned(E); |
| 8468 | } |
| 8469 | |
| 8470 | template<typename Derived> |
| 8471 | ExprResult |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8472 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 8473 | MaterializeTemporaryExpr *E) { |
| 8474 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 8475 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8476 | |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8477 | template<typename Derived> |
| 8478 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8479 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8480 | return SemaRef.MaybeBindToTemporary(E); |
| 8481 | } |
| 8482 | |
| 8483 | template<typename Derived> |
| 8484 | ExprResult |
| 8485 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Jordy Rose | d8b5ca1 | 2012-03-12 17:53:02 +0000 | [diff] [blame] | 8486 | return SemaRef.Owned(E); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8487 | } |
| 8488 | |
| 8489 | template<typename Derived> |
| 8490 | ExprResult |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 8491 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 8492 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 8493 | if (SubExpr.isInvalid()) |
| 8494 | return ExprError(); |
| 8495 | |
| 8496 | if (!getDerived().AlwaysRebuild() && |
| 8497 | SubExpr.get() == E->getSubExpr()) |
| 8498 | return SemaRef.Owned(E); |
| 8499 | |
| 8500 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8501 | } |
| 8502 | |
| 8503 | template<typename Derived> |
| 8504 | ExprResult |
| 8505 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 8506 | // Transform each of the elements. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8507 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8508 | bool ArgChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8509 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8510 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 8511 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8512 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8513 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8514 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8515 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8516 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 8517 | Elements.data(), |
| 8518 | Elements.size()); |
| 8519 | } |
| 8520 | |
| 8521 | template<typename Derived> |
| 8522 | ExprResult |
| 8523 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8524 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8525 | // Transform each of the elements. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8526 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8527 | bool ArgChanged = false; |
| 8528 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 8529 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8530 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8531 | if (OrigElement.isPackExpansion()) { |
| 8532 | // This key/value element is a pack expansion. |
| 8533 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8534 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 8535 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 8536 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 8537 | |
| 8538 | // Determine whether the set of unexpanded parameter packs can |
| 8539 | // and should be expanded. |
| 8540 | bool Expand = true; |
| 8541 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8542 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 8543 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8544 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 8545 | OrigElement.Value->getLocEnd()); |
| 8546 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 8547 | PatternRange, |
| 8548 | Unexpanded, |
| 8549 | Expand, RetainExpansion, |
| 8550 | NumExpansions)) |
| 8551 | return ExprError(); |
| 8552 | |
| 8553 | if (!Expand) { |
| 8554 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8555 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8556 | // expansion. |
| 8557 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 8558 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8559 | if (Key.isInvalid()) |
| 8560 | return ExprError(); |
| 8561 | |
| 8562 | if (Key.get() != OrigElement.Key) |
| 8563 | ArgChanged = true; |
| 8564 | |
| 8565 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8566 | if (Value.isInvalid()) |
| 8567 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8568 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8569 | if (Value.get() != OrigElement.Value) |
| 8570 | ArgChanged = true; |
| 8571 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8572 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8573 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 8574 | }; |
| 8575 | Elements.push_back(Expansion); |
| 8576 | continue; |
| 8577 | } |
| 8578 | |
| 8579 | // Record right away that the argument was changed. This needs |
| 8580 | // to happen even if the array expands to nothing. |
| 8581 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8582 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8583 | // The transform has determined that we should perform an elementwise |
| 8584 | // expansion of the pattern. Do so. |
| 8585 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8586 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8587 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8588 | if (Key.isInvalid()) |
| 8589 | return ExprError(); |
| 8590 | |
| 8591 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8592 | if (Value.isInvalid()) |
| 8593 | return ExprError(); |
| 8594 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8595 | ObjCDictionaryElement Element = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8596 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 8597 | }; |
| 8598 | |
| 8599 | // If any unexpanded parameter packs remain, we still have a |
| 8600 | // pack expansion. |
| 8601 | if (Key.get()->containsUnexpandedParameterPack() || |
| 8602 | Value.get()->containsUnexpandedParameterPack()) |
| 8603 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8604 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8605 | Elements.push_back(Element); |
| 8606 | } |
| 8607 | |
| 8608 | // We've finished with this pack expansion. |
| 8609 | continue; |
| 8610 | } |
| 8611 | |
| 8612 | // Transform and check key. |
| 8613 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8614 | if (Key.isInvalid()) |
| 8615 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8616 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8617 | if (Key.get() != OrigElement.Key) |
| 8618 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8619 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8620 | // Transform and check value. |
| 8621 | ExprResult Value |
| 8622 | = getDerived().TransformExpr(OrigElement.Value); |
| 8623 | if (Value.isInvalid()) |
| 8624 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8625 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8626 | if (Value.get() != OrigElement.Value) |
| 8627 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8628 | |
| 8629 | ObjCDictionaryElement Element = { |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 8630 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8631 | }; |
| 8632 | Elements.push_back(Element); |
| 8633 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8634 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8635 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8636 | return SemaRef.MaybeBindToTemporary(E); |
| 8637 | |
| 8638 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 8639 | Elements.data(), |
| 8640 | Elements.size()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8641 | } |
| 8642 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8643 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8644 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8645 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8646 | TypeSourceInfo *EncodedTypeInfo |
| 8647 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 8648 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8649 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8651 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8652 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8653 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8654 | |
| 8655 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8656 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8657 | E->getRParenLoc()); |
| 8658 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8659 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8660 | template<typename Derived> |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8661 | ExprResult TreeTransform<Derived>:: |
| 8662 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | 93b6457 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 8663 | // This is a kind of implicit conversion, and it needs to get dropped |
| 8664 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 8665 | // do, as well a more specific one: this expression is only valid when |
| 8666 | // it appears *immediately* as an argument expression. |
| 8667 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8668 | } |
| 8669 | |
| 8670 | template<typename Derived> |
| 8671 | ExprResult TreeTransform<Derived>:: |
| 8672 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8673 | TypeSourceInfo *TSInfo |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8674 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8675 | if (!TSInfo) |
| 8676 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8677 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8678 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8679 | if (Result.isInvalid()) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8680 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8681 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8682 | if (!getDerived().AlwaysRebuild() && |
| 8683 | TSInfo == E->getTypeInfoAsWritten() && |
| 8684 | Result.get() == E->getSubExpr()) |
| 8685 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8686 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8687 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8688 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8689 | Result.get()); |
| 8690 | } |
| 8691 | |
| 8692 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8693 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8694 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8695 | // Transform arguments. |
| 8696 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8697 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8698 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8699 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8700 | &ArgChanged)) |
| 8701 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8702 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8703 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 8704 | // Class message: transform the receiver type. |
| 8705 | TypeSourceInfo *ReceiverTypeInfo |
| 8706 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 8707 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8708 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8709 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8710 | // If nothing changed, just retain the existing message send. |
| 8711 | if (!getDerived().AlwaysRebuild() && |
| 8712 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8713 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8714 | |
| 8715 | // Build a new class message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8716 | SmallVector<SourceLocation, 16> SelLocs; |
| 8717 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8718 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 8719 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8720 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8721 | E->getMethodDecl(), |
| 8722 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8723 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8724 | E->getRightLoc()); |
| 8725 | } |
| 8726 | |
| 8727 | // Instance message: transform the receiver |
| 8728 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 8729 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8730 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8731 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 8732 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8733 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8734 | |
| 8735 | // If nothing changed, just retain the existing message send. |
| 8736 | if (!getDerived().AlwaysRebuild() && |
| 8737 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8738 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8739 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8740 | // Build a new instance message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8741 | SmallVector<SourceLocation, 16> SelLocs; |
| 8742 | E->getSelectorLocs(SelLocs); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8743 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8744 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8745 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8746 | E->getMethodDecl(), |
| 8747 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8748 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8749 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8750 | } |
| 8751 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8752 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8753 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8754 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8755 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8756 | } |
| 8757 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8758 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8759 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8760 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8761 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8762 | } |
| 8763 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8764 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8765 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8766 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8767 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8768 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8769 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8770 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8771 | |
| 8772 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8773 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8774 | // If nothing changed, just retain the existing expression. |
| 8775 | if (!getDerived().AlwaysRebuild() && |
| 8776 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8777 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8778 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8779 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8780 | E->getLocation(), |
| 8781 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8782 | } |
| 8783 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8784 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8785 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8786 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8787 | // 'super' and types never change. Property never changes. Just |
| 8788 | // retain the existing expression. |
| 8789 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8790 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8791 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8792 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8793 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8794 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8795 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8796 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8797 | // We don't need to transform the property; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8798 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8799 | // If nothing changed, just retain the existing expression. |
| 8800 | if (!getDerived().AlwaysRebuild() && |
| 8801 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8802 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8803 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8804 | if (E->isExplicitProperty()) |
| 8805 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 8806 | E->getExplicitProperty(), |
| 8807 | E->getLocation()); |
| 8808 | |
| 8809 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 8810 | SemaRef.Context.PseudoObjectTy, |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8811 | E->getImplicitPropertyGetter(), |
| 8812 | E->getImplicitPropertySetter(), |
| 8813 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8814 | } |
| 8815 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8816 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8817 | ExprResult |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8818 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 8819 | // Transform the base expression. |
| 8820 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 8821 | if (Base.isInvalid()) |
| 8822 | return ExprError(); |
| 8823 | |
| 8824 | // Transform the key expression. |
| 8825 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 8826 | if (Key.isInvalid()) |
| 8827 | return ExprError(); |
| 8828 | |
| 8829 | // If nothing changed, just retain the existing expression. |
| 8830 | if (!getDerived().AlwaysRebuild() && |
| 8831 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 8832 | return SemaRef.Owned(E); |
| 8833 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8834 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8835 | Base.get(), Key.get(), |
| 8836 | E->getAtIndexMethodDecl(), |
| 8837 | E->setAtIndexMethodDecl()); |
| 8838 | } |
| 8839 | |
| 8840 | template<typename Derived> |
| 8841 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8842 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8843 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8844 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8845 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8846 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8847 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8848 | // If nothing changed, just retain the existing expression. |
| 8849 | if (!getDerived().AlwaysRebuild() && |
| 8850 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8851 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8852 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8853 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 8854 | E->getOpLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8855 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8856 | } |
| 8857 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8858 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8859 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8860 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8861 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8862 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8863 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8864 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8865 | SubExprs, &ArgumentChanged)) |
| 8866 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8867 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8868 | if (!getDerived().AlwaysRebuild() && |
| 8869 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8870 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8871 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8872 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8873 | SubExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8874 | E->getRParenLoc()); |
| 8875 | } |
| 8876 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8877 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8878 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8879 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8880 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8881 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8882 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 8883 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 8884 | |
| 8885 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 0586520 | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 8886 | blockScope->TheDecl->setBlockMissingReturnType( |
| 8887 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8888 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 8889 | SmallVector<ParmVarDecl*, 4> params; |
| 8890 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8891 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8892 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8893 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 8894 | oldBlock->param_begin(), |
| 8895 | oldBlock->param_size(), |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8896 | 0, paramTypes, ¶ms)) { |
| 8897 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8898 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8899 | } |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8900 | |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 8901 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8902 | QualType exprResultType = |
| 8903 | getDerived().TransformType(exprFunctionType->getResultType()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8904 | |
| 8905 | // Don't allow returning a objc interface by value. |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8906 | if (exprResultType->isObjCObjectType()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8907 | getSema().Diag(E->getCaretLocation(), |
| 8908 | diag::err_object_cannot_be_passed_returned_by_value) |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8909 | << 0 << exprResultType; |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8910 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8911 | return ExprError(); |
| 8912 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8913 | |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 8914 | QualType functionType = |
| 8915 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 8916 | exprFunctionType->getExtProtoInfo()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8917 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8918 | |
| 8919 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8920 | if (!params.empty()) |
David Blaikie | 4278c65 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 8921 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8922 | |
| 8923 | if (!oldBlock->blockMissingReturnType()) { |
| 8924 | blockScope->HasImplicitReturnType = false; |
| 8925 | blockScope->ReturnType = exprResultType; |
| 8926 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8927 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8928 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8929 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8930 | if (body.isInvalid()) { |
| 8931 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8932 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8933 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8934 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8935 | #ifndef NDEBUG |
| 8936 | // In builds with assertions, make sure that we captured everything we |
| 8937 | // captured before. |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8938 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 8939 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 8940 | e = oldBlock->capture_end(); i != e; ++i) { |
| 8941 | VarDecl *oldCapture = i->getVariable(); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8942 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8943 | // Ignore parameter packs. |
| 8944 | if (isa<ParmVarDecl>(oldCapture) && |
| 8945 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 8946 | continue; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8947 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8948 | VarDecl *newCapture = |
| 8949 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 8950 | oldCapture)); |
| 8951 | assert(blockScope->CaptureMap.count(newCapture)); |
| 8952 | } |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8953 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8954 | } |
| 8955 | #endif |
| 8956 | |
| 8957 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 8958 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8959 | } |
| 8960 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8961 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8962 | ExprResult |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8963 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 8964 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8965 | } |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 8966 | |
| 8967 | template<typename Derived> |
| 8968 | ExprResult |
| 8969 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 8970 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 8971 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8972 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 8973 | SubExprs.reserve(E->getNumSubExprs()); |
| 8974 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 8975 | SubExprs, &ArgumentChanged)) |
| 8976 | return ExprError(); |
| 8977 | |
| 8978 | if (!getDerived().AlwaysRebuild() && |
| 8979 | !ArgumentChanged) |
| 8980 | return SemaRef.Owned(E); |
| 8981 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8982 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 8983 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 8984 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8985 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8986 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8987 | // Type reconstruction |
| 8988 | //===----------------------------------------------------------------------===// |
| 8989 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8990 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8991 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 8992 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8993 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8994 | getDerived().getBaseEntity()); |
| 8995 | } |
| 8996 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8997 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8998 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 8999 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9000 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9001 | getDerived().getBaseEntity()); |
| 9002 | } |
| 9003 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9004 | template<typename Derived> |
| 9005 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9006 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 9007 | bool WrittenAsLValue, |
| 9008 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9009 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9010 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9011 | } |
| 9012 | |
| 9013 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9014 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9015 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 9016 | QualType ClassType, |
| 9017 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9018 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9019 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9020 | } |
| 9021 | |
| 9022 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9023 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9024 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 9025 | ArrayType::ArraySizeModifier SizeMod, |
| 9026 | const llvm::APInt *Size, |
| 9027 | Expr *SizeExpr, |
| 9028 | unsigned IndexTypeQuals, |
| 9029 | SourceRange BracketsRange) { |
| 9030 | if (SizeExpr || !Size) |
| 9031 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 9032 | IndexTypeQuals, BracketsRange, |
| 9033 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9034 | |
| 9035 | QualType Types[] = { |
| 9036 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 9037 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 9038 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9039 | }; |
| 9040 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 9041 | QualType SizeType; |
| 9042 | for (unsigned I = 0; I != NumTypes; ++I) |
| 9043 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 9044 | SizeType = Types[I]; |
| 9045 | break; |
| 9046 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9047 | |
Eli Friedman | 01f276d | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 9048 | // Note that we can return a VariableArrayType here in the case where |
| 9049 | // the element type was a dependent VariableArrayType. |
| 9050 | IntegerLiteral *ArraySize |
| 9051 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 9052 | /*FIXME*/BracketsRange.getBegin()); |
| 9053 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9054 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9055 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9056 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9057 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9058 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9059 | QualType |
| 9060 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9061 | ArrayType::ArraySizeModifier SizeMod, |
| 9062 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9063 | unsigned IndexTypeQuals, |
| 9064 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9065 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9066 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9067 | } |
| 9068 | |
| 9069 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9070 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9071 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9072 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9073 | unsigned IndexTypeQuals, |
| 9074 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9075 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9076 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9078 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9079 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9080 | QualType |
| 9081 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9082 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9083 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9084 | unsigned IndexTypeQuals, |
| 9085 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9086 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9087 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9088 | IndexTypeQuals, BracketsRange); |
| 9089 | } |
| 9090 | |
| 9091 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9092 | QualType |
| 9093 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9094 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9095 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9096 | unsigned IndexTypeQuals, |
| 9097 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9098 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9099 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9100 | IndexTypeQuals, BracketsRange); |
| 9101 | } |
| 9102 | |
| 9103 | template<typename Derived> |
| 9104 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9105 | unsigned NumElements, |
| 9106 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9107 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9108 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9109 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9110 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9111 | template<typename Derived> |
| 9112 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 9113 | unsigned NumElements, |
| 9114 | SourceLocation AttributeLoc) { |
| 9115 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 9116 | NumElements, true); |
| 9117 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 9118 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 9119 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9120 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9121 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9122 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9123 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9124 | QualType |
| 9125 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9126 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9127 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9128 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9129 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9130 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9131 | template<typename Derived> |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9132 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 9133 | QualType T, |
| 9134 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9135 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 9136 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9137 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9138 | getDerived().getBaseEntity(), |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9139 | EPI); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9140 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9141 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9142 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 9143 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 9144 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 9145 | } |
| 9146 | |
| 9147 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9148 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 9149 | assert(D && "no decl found"); |
| 9150 | if (D->isInvalidDecl()) return QualType(); |
| 9151 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9152 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9153 | TypeDecl *Ty; |
| 9154 | if (isa<UsingDecl>(D)) { |
| 9155 | UsingDecl *Using = cast<UsingDecl>(D); |
| 9156 | assert(Using->isTypeName() && |
| 9157 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 9158 | |
| 9159 | // A valid resolved using typename decl points to exactly one type decl. |
| 9160 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 9161 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9162 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9163 | } else { |
| 9164 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 9165 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 9166 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 9167 | } |
| 9168 | |
| 9169 | return SemaRef.Context.getTypeDeclType(Ty); |
| 9170 | } |
| 9171 | |
| 9172 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9173 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 9174 | SourceLocation Loc) { |
| 9175 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9176 | } |
| 9177 | |
| 9178 | template<typename Derived> |
| 9179 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 9180 | return SemaRef.Context.getTypeOfType(Underlying); |
| 9181 | } |
| 9182 | |
| 9183 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9184 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 9185 | SourceLocation Loc) { |
| 9186 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9187 | } |
| 9188 | |
| 9189 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 9190 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 9191 | UnaryTransformType::UTTKind UKind, |
| 9192 | SourceLocation Loc) { |
| 9193 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 9194 | } |
| 9195 | |
| 9196 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9197 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 9198 | TemplateName Template, |
| 9199 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 9200 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9201 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9202 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9203 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 9204 | template<typename Derived> |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 9205 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 9206 | SourceLocation KWLoc) { |
| 9207 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 9208 | } |
| 9209 | |
| 9210 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9211 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9212 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9213 | bool TemplateKW, |
| 9214 | TemplateDecl *Template) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9215 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9216 | Template); |
| 9217 | } |
| 9218 | |
| 9219 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9220 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9221 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 9222 | const IdentifierInfo &Name, |
| 9223 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9224 | QualType ObjectType, |
| 9225 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9226 | UnqualifiedId TemplateName; |
| 9227 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9228 | Sema::TemplateTy Template; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9229 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9230 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9231 | SS, TemplateKWLoc, TemplateName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9232 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9233 | /*EnteringContext=*/false, |
| 9234 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9235 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9236 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9237 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9238 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9239 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9240 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9241 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9242 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9243 | QualType ObjectType) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9244 | UnqualifiedId Name; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9245 | // FIXME: Bogus location information. |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9246 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9247 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9248 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9249 | Sema::TemplateTy Template; |
| 9250 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9251 | SS, TemplateKWLoc, Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9252 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9253 | /*EnteringContext=*/false, |
| 9254 | Template); |
| 9255 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9256 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9257 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9258 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9259 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9260 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 9261 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9262 | Expr *OrigCallee, |
| 9263 | Expr *First, |
| 9264 | Expr *Second) { |
| 9265 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 9266 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9267 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9268 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9269 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9270 | if (!First->getType()->isOverloadableType() && |
| 9271 | !Second->getType()->isOverloadableType()) |
| 9272 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 9273 | Callee->getLocStart(), |
| 9274 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 9275 | } else if (Op == OO_Arrow) { |
| 9276 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9277 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 9278 | } else if (Second == 0 || isPostIncDec) { |
| 9279 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9280 | // The argument is not of overloadable type, so try to create a |
| 9281 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9282 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9283 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9284 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9285 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9286 | } |
| 9287 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9288 | if (!First->getType()->isOverloadableType() && |
| 9289 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9290 | // Neither of the arguments is an overloadable type, so try to |
| 9291 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9292 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9293 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9294 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9295 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9296 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9297 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9298 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9299 | } |
| 9300 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9301 | |
| 9302 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9303 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9304 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9305 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9306 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9307 | assert(ULE->requiresADL()); |
| 9308 | |
| 9309 | // FIXME: Do we have to check |
| 9310 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9311 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9312 | } else { |
Richard Smith | f641166 | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 9313 | // If we've resolved this to a particular non-member function, just call |
| 9314 | // that function. If we resolved it to a member function, |
| 9315 | // CreateOverloaded* will find that function for us. |
| 9316 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 9317 | if (!isa<CXXMethodDecl>(ND)) |
| 9318 | Functions.addDecl(ND); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9319 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9320 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9321 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9322 | Expr *Args[2] = { First, Second }; |
| 9323 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9324 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9325 | // Create the overloaded operator invocation for unary operators. |
| 9326 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9327 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9328 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9329 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9330 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9331 | |
Douglas Gregor | 5b8968c | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 9332 | if (Op == OO_Subscript) { |
| 9333 | SourceLocation LBrace; |
| 9334 | SourceLocation RBrace; |
| 9335 | |
| 9336 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 9337 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 9338 | LBrace = SourceLocation::getFromRawEncoding( |
| 9339 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 9340 | RBrace = SourceLocation::getFromRawEncoding( |
| 9341 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 9342 | } else { |
| 9343 | LBrace = Callee->getLocStart(); |
| 9344 | RBrace = OpLoc; |
| 9345 | } |
| 9346 | |
| 9347 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 9348 | First, Second); |
| 9349 | } |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9350 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9351 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9352 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9353 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9354 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 9355 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9356 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9357 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9358 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9359 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9360 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9361 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9362 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9363 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9364 | SourceLocation OperatorLoc, |
| 9365 | bool isArrow, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9366 | CXXScopeSpec &SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9367 | TypeSourceInfo *ScopeType, |
| 9368 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9369 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9370 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9371 | QualType BaseType = Base->getType(); |
| 9372 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9373 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9374 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 9375 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 9376 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9377 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9378 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9379 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9380 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9381 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9382 | /*FIXME?*/true); |
| 9383 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9384 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9385 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9386 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 9387 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 9388 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 9389 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 9390 | |
Richard Smith | 6314db9 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 9391 | // The scope type is now known to be a valid nested name specifier |
| 9392 | // component. Tack it on to the end of the nested name specifier. |
| 9393 | if (ScopeType) |
| 9394 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 9395 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9396 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9397 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9398 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9399 | OperatorLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9400 | SS, TemplateKWLoc, |
| 9401 | /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9402 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9403 | /*TemplateArgs*/ 0); |
| 9404 | } |
| 9405 | |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9406 | template<typename Derived> |
| 9407 | StmtResult |
| 9408 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
| 9409 | llvm_unreachable("not implement yet"); |
| 9410 | } |
| 9411 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9412 | } // end namespace clang |
| 9413 | |
| 9414 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |