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" |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/AST/StmtOpenMP.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 28 | #include "clang/Lex/Preprocessor.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Designator.h" |
| 30 | #include "clang/Sema/Lookup.h" |
| 31 | #include "clang/Sema/Ownership.h" |
| 32 | #include "clang/Sema/ParsedTemplate.h" |
| 33 | #include "clang/Sema/ScopeInfo.h" |
| 34 | #include "clang/Sema/SemaDiagnostic.h" |
| 35 | #include "clang/Sema/SemaInternal.h" |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/ArrayRef.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 37 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 38 | #include <algorithm> |
| 39 | |
| 40 | namespace clang { |
John McCall | 781472f | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 41 | using namespace sema; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 43 | /// \brief A semantic tree transformation that allows one to transform one |
| 44 | /// abstract syntax tree into another. |
| 45 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 46 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 47 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 48 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// instantiation is implemented as a tree transformation where the |
| 50 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 51 | /// template arguments for their corresponding template parameters; a similar |
| 52 | /// transformation is performed for non-type template parameters and |
| 53 | /// template template parameters. |
| 54 | /// |
| 55 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 57 | /// override any of the transformation or rebuild operators by providing an |
| 58 | /// operation with the same signature as the default implementation. The |
| 59 | /// overridding function should not be virtual. |
| 60 | /// |
| 61 | /// Semantic tree transformations are split into two stages, either of which |
| 62 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 63 | /// or the parts of an AST node using the various transformation functions, |
| 64 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 65 | /// node of the appropriate kind from the pieces. The default transformation |
| 66 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 67 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 68 | /// were changed by the transformation, invokes the rebuild operation to create |
| 69 | /// a new AST node. |
| 70 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 72 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 9151c11 | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 73 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 75 | /// new implementations. |
| 76 | /// |
| 77 | /// For more fine-grained transformations, subclasses can replace any of the |
| 78 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 79 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 80 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 83 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 84 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 85 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 86 | /// be able to use more efficient rebuild steps. |
| 87 | /// |
| 88 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 90 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 91 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 92 | /// default locations and entity names used for type-checking |
| 93 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 94 | template<typename Derived> |
| 95 | class TreeTransform { |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 96 | /// \brief Private RAII object that helps us forget and then re-remember |
| 97 | /// the template argument corresponding to a partially-substituted parameter |
| 98 | /// pack. |
| 99 | class ForgetPartiallySubstitutedPackRAII { |
| 100 | Derived &Self; |
| 101 | TemplateArgument Old; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 103 | public: |
| 104 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 105 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 106 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 107 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 108 | ~ForgetPartiallySubstitutedPackRAII() { |
| 109 | Self.RememberPartiallySubstitutedPack(Old); |
| 110 | } |
| 111 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 113 | protected: |
| 114 | Sema &SemaRef; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 116 | /// \brief The set of local declarations that have been transformed, for |
| 117 | /// cases where we are forced to build new declarations within the transformer |
| 118 | /// rather than in the subclass (e.g., lambda closure types). |
| 119 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 120 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | public: |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 123 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 125 | /// \brief Retrieves a reference to the derived class. |
| 126 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 127 | |
| 128 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | const Derived &getDerived() const { |
| 130 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 131 | } |
| 132 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 133 | static inline ExprResult Owned(Expr *E) { return E; } |
| 134 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 135 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 136 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 137 | /// this tree transform. |
| 138 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 140 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 141 | /// if none of the children have changed. |
| 142 | /// |
| 143 | /// Subclasses may override this function to specify when the transformation |
| 144 | /// should rebuild all AST nodes. |
| 145 | bool AlwaysRebuild() { return false; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 147 | /// \brief Returns the location of the entity being transformed, if that |
| 148 | /// information was not available elsewhere in the AST. |
| 149 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 151 | /// provide an alternative implementation that provides better location |
| 152 | /// information. |
| 153 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 154 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 155 | /// \brief Returns the name of the entity being transformed, if that |
| 156 | /// information was not available elsewhere in the AST. |
| 157 | /// |
| 158 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 159 | /// implementation with a more precise name. |
| 160 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 161 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 162 | /// \brief Sets the "base" location and entity when that |
| 163 | /// information is known based on another transformation. |
| 164 | /// |
| 165 | /// By default, the source location and entity are ignored. Subclasses can |
| 166 | /// override this function to provide a customized implementation. |
| 167 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 169 | /// \brief RAII object that temporarily sets the base location and entity |
| 170 | /// used for reporting diagnostics in types. |
| 171 | class TemporaryBase { |
| 172 | TreeTransform &Self; |
| 173 | SourceLocation OldLocation; |
| 174 | DeclarationName OldEntity; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 176 | public: |
| 177 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 179 | OldLocation = Self.getDerived().getBaseLocation(); |
| 180 | OldEntity = Self.getDerived().getBaseEntity(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 181 | |
Douglas Gregor | ae201f7 | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 182 | if (Location.isValid()) |
| 183 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 186 | ~TemporaryBase() { |
| 187 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 188 | } |
| 189 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 190 | |
| 191 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// transformed. |
| 193 | /// |
| 194 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | /// 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] | 196 | /// not change. For example, template instantiation need not traverse |
| 197 | /// non-dependent types. |
| 198 | bool AlreadyTransformed(QualType T) { |
| 199 | return T.isNull(); |
| 200 | } |
| 201 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 202 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 203 | /// because it is a default argument. |
| 204 | /// |
| 205 | /// Subclasses can provide an alternative implementation of this routine to |
| 206 | /// determine which kinds of call arguments get dropped. By default, |
| 207 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 208 | bool DropCallArgument(Expr *E) { |
| 209 | return E->isDefaultArgument(); |
| 210 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 211 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 212 | /// \brief Determine whether we should expand a pack expansion with the |
| 213 | /// given set of parameter packs into separate arguments by repeatedly |
| 214 | /// transforming the pattern. |
| 215 | /// |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 216 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 217 | /// Subclasses can override this routine to provide different behavior. |
| 218 | /// |
| 219 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 220 | /// pack expansion. |
| 221 | /// |
| 222 | /// \param PatternRange The source range that covers the entire pattern of |
| 223 | /// the pack expansion. |
| 224 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 225 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 226 | /// pattern. |
| 227 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 228 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 229 | /// expand the corresponding pack expansions into separate arguments. When |
| 230 | /// set, \c NumExpansions must also be set. |
| 231 | /// |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 232 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 233 | /// pack expansion after all of the expanded arguments. This is used |
| 234 | /// when extending explicitly-specified template argument packs per |
| 235 | /// C++0x [temp.arg.explicit]p9. |
| 236 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 237 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 238 | /// the expanded form of the corresponding pack expansion. This is both an |
| 239 | /// input and an output parameter, which can be set by the caller if the |
| 240 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 241 | /// and will be set by the callee when the number of expansions is known. |
| 242 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 243 | /// set this value in other cases. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 244 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 245 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 246 | /// are to be instantiated with arguments of different lengths), false |
| 247 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 248 | /// must be set. |
| 249 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 250 | SourceRange PatternRange, |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 251 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 252 | bool &ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 253 | bool &RetainExpansion, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 254 | Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 255 | ShouldExpand = false; |
| 256 | return false; |
| 257 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 258 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 259 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 260 | /// when performing an instantiation that must preserve the parameter pack |
| 261 | /// use. |
| 262 | /// |
| 263 | /// This routine is meant to be overridden by the template instantiator. |
| 264 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 265 | return TemplateArgument(); |
| 266 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 267 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 268 | /// \brief "Remember" the partially-substituted pack template argument |
| 269 | /// after performing an instantiation that must preserve the parameter pack |
| 270 | /// use. |
| 271 | /// |
| 272 | /// This routine is meant to be overridden by the template instantiator. |
| 273 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 274 | |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 275 | /// \brief Note to the derived class when a function parameter pack is |
| 276 | /// being expanded. |
| 277 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 279 | /// \brief Transforms the given type into another type. |
| 280 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 281 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 282 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 283 | /// function. This is expensive, but we don't mind, because |
| 284 | /// this method is deprecated anyway; all users should be |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 285 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 286 | /// |
| 287 | /// \returns the transformed type. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 288 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 290 | /// \brief Transforms the given type-with-location into a new |
| 291 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 292 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 293 | /// By default, this routine transforms a type by delegating to the |
| 294 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 295 | /// may override this function (to take over all type |
| 296 | /// transformations) or some set of the TransformXXXType functions |
| 297 | /// to alter the transformation. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 298 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 299 | |
| 300 | /// \brief Transform the given type-with-location into a new |
| 301 | /// type, collecting location information in the given builder |
| 302 | /// as necessary. |
| 303 | /// |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 304 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 306 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 307 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 309 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 310 | /// statement or the TransformExpr() function to transform an expression. |
| 311 | /// Subclasses may override this function to transform statements using some |
| 312 | /// other mechanism. |
| 313 | /// |
| 314 | /// \returns the transformed statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 315 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 316 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 317 | /// \brief Transform the given statement. |
| 318 | /// |
| 319 | /// By default, this routine transforms a statement by delegating to the |
| 320 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 321 | /// of clause. Subclasses may override this function to transform statements |
| 322 | /// using some other mechanism. |
| 323 | /// |
| 324 | /// \returns the transformed OpenMP clause. |
| 325 | OMPClause *TransformOMPClause(OMPClause *S); |
| 326 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 327 | /// \brief Transform the given expression. |
| 328 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 329 | /// By default, this routine transforms an expression by delegating to the |
| 330 | /// appropriate TransformXXXExpr function to build a new expression. |
| 331 | /// Subclasses may override this function to transform expressions using some |
| 332 | /// other mechanism. |
| 333 | /// |
| 334 | /// \returns the transformed expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 335 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 336 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 337 | /// \brief Transform the given initializer. |
| 338 | /// |
| 339 | /// By default, this routine transforms an initializer by stripping off the |
| 340 | /// semantic nodes added by initialization, then passing the result to |
| 341 | /// TransformExpr or TransformExprs. |
| 342 | /// |
| 343 | /// \returns the transformed initializer. |
| 344 | ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit); |
| 345 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 346 | /// \brief Transform the given list of expressions. |
| 347 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 348 | /// This routine transforms a list of expressions by invoking |
| 349 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 350 | /// support for variadic templates by expanding any pack expansions (if the |
| 351 | /// derived class permits such expansion) along the way. When pack expansions |
| 352 | /// are present, the number of outputs may not equal the number of inputs. |
| 353 | /// |
| 354 | /// \param Inputs The set of expressions to be transformed. |
| 355 | /// |
| 356 | /// \param NumInputs The number of expressions in \c Inputs. |
| 357 | /// |
| 358 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 359 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 360 | /// be. |
| 361 | /// |
| 362 | /// \param Outputs The transformed input expressions will be added to this |
| 363 | /// vector. |
| 364 | /// |
| 365 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 366 | /// due to transformation. |
| 367 | /// |
| 368 | /// \returns true if an error occurred, false otherwise. |
| 369 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 370 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 371 | bool *ArgChanged = 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 372 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 373 | /// \brief Transform the given declaration, which is referenced from a type |
| 374 | /// or expression. |
| 375 | /// |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 376 | /// By default, acts as the identity function on declarations, unless the |
| 377 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 378 | /// may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 379 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 380 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 381 | = TransformedLocalDecls.find(D); |
| 382 | if (Known != TransformedLocalDecls.end()) |
| 383 | return Known->second; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 384 | |
| 385 | return D; |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 386 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 387 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 388 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 389 | /// place them on the new declaration. |
| 390 | /// |
| 391 | /// By default, this operation does nothing. Subclasses may override this |
| 392 | /// behavior to transform attributes. |
| 393 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 394 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 395 | /// \brief Note that a local declaration has been transformed by this |
| 396 | /// transformer. |
| 397 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 398 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 399 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 400 | /// the transformer itself has to transform the declarations. This routine |
| 401 | /// can be overridden by a subclass that keeps track of such mappings. |
| 402 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 403 | TransformedLocalDecls[Old] = New; |
| 404 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 405 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 406 | /// \brief Transform the definition of the given declaration. |
| 407 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 409 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 410 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 411 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 412 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 414 | /// \brief Transform the given declaration, which was the first part of a |
| 415 | /// nested-name-specifier in a member access expression. |
| 416 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 417 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 418 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 419 | /// the \c T in \c x->T::member |
| 420 | /// |
| 421 | /// By default, invokes TransformDecl() to transform the declaration. |
| 422 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 423 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 424 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 425 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 426 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 427 | /// \brief Transform the given nested-name-specifier with source-location |
| 428 | /// information. |
| 429 | /// |
| 430 | /// By default, transforms all of the types and declarations within the |
| 431 | /// nested-name-specifier. Subclasses may override this function to provide |
| 432 | /// alternate behavior. |
| 433 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 434 | NestedNameSpecifierLoc NNS, |
| 435 | QualType ObjectType = QualType(), |
| 436 | NamedDecl *FirstQualifierInScope = 0); |
| 437 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 438 | /// \brief Transform the given declaration name. |
| 439 | /// |
| 440 | /// By default, transforms the types of conversion function, constructor, |
| 441 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 442 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 443 | /// override this function to provide alternate behavior. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 444 | DeclarationNameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 445 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 447 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 448 | /// |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 449 | /// \param SS The nested-name-specifier that qualifies the template |
| 450 | /// name. This nested-name-specifier must already have been transformed. |
| 451 | /// |
| 452 | /// \param Name The template name to transform. |
| 453 | /// |
| 454 | /// \param NameLoc The source location of the template name. |
| 455 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 456 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 457 | /// access expression, this is the type of the object whose member template |
| 458 | /// is being referenced. |
| 459 | /// |
| 460 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 461 | /// also refers to a name within the current (lexical) scope, this is the |
| 462 | /// declaration it refers to. |
| 463 | /// |
| 464 | /// By default, transforms the template name by transforming the declarations |
| 465 | /// and nested-name-specifiers that occur within the template name. |
| 466 | /// Subclasses may override this function to provide alternate behavior. |
| 467 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 468 | TemplateName Name, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 469 | SourceLocation NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 470 | QualType ObjectType = QualType(), |
| 471 | NamedDecl *FirstQualifierInScope = 0); |
| 472 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 473 | /// \brief Transform the given template argument. |
| 474 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | /// By default, this operation transforms the type, expression, or |
| 476 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 477 | /// new template argument from the transformed result. Subclasses may |
| 478 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 479 | /// |
| 480 | /// Returns true if there was an error. |
| 481 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 482 | TemplateArgumentLoc &Output); |
| 483 | |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 484 | /// \brief Transform the given set of template arguments. |
| 485 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 486 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 487 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 488 | /// the transformed arguments to the output list. |
| 489 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 490 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 491 | /// a convenience function. Subclasses that wish to override this behavior |
| 492 | /// should override the iterator-based member template version. |
| 493 | /// |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 494 | /// \param Inputs The set of template arguments to be transformed. |
| 495 | /// |
| 496 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 497 | /// |
| 498 | /// \param Outputs The set of transformed template arguments output by this |
| 499 | /// routine. |
| 500 | /// |
| 501 | /// Returns true if an error occurred. |
| 502 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 503 | unsigned NumInputs, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 504 | TemplateArgumentListInfo &Outputs) { |
| 505 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 506 | } |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 507 | |
| 508 | /// \brief Transform the given set of template arguments. |
| 509 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 510 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 511 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 512 | /// the transformed arguments to the output list. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 513 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 514 | /// \param First An iterator to the first template argument. |
| 515 | /// |
| 516 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 517 | /// |
| 518 | /// \param Outputs The set of transformed template arguments output by this |
| 519 | /// routine. |
| 520 | /// |
| 521 | /// Returns true if an error occurred. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 522 | template<typename InputIterator> |
| 523 | bool TransformTemplateArguments(InputIterator First, |
| 524 | InputIterator Last, |
| 525 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 526 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 527 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 528 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 529 | TemplateArgumentLoc &ArgLoc); |
| 530 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 531 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 532 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 533 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 534 | getDerived().getBaseLocation()); |
| 535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 537 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 538 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 539 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 540 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 541 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 542 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 543 | FunctionProtoTypeLoc TL, |
| 544 | CXXRecordDecl *ThisContext, |
| 545 | unsigned ThisTypeQuals); |
| 546 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 547 | StmtResult |
| 548 | TransformSEHHandler(Stmt *Handler); |
| 549 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 550 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 551 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 552 | TemplateSpecializationTypeLoc TL, |
| 553 | TemplateName Template); |
| 554 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 555 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 556 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 557 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 558 | TemplateName Template, |
| 559 | CXXScopeSpec &SS); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 560 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 561 | QualType |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 562 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 563 | DependentTemplateSpecializationTypeLoc TL, |
| 564 | NestedNameSpecifierLoc QualifierLoc); |
| 565 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 566 | /// \brief Transforms the parameters of a function type into the |
| 567 | /// given vectors. |
| 568 | /// |
| 569 | /// The result vectors should be kept in sync; null entries in the |
| 570 | /// variables vector are acceptable. |
| 571 | /// |
| 572 | /// Return true on error. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 573 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 574 | ParmVarDecl **Params, unsigned NumParams, |
| 575 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 576 | SmallVectorImpl<QualType> &PTypes, |
| 577 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 578 | |
| 579 | /// \brief Transforms a single function-type parameter. Return null |
| 580 | /// on error. |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 581 | /// |
| 582 | /// \param indexAdjustment - A number to add to the parameter's |
| 583 | /// scope index; can be negative |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 584 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 585 | int indexAdjustment, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 586 | Optional<unsigned> NumExpansions, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 587 | bool ExpectParameterPack); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 588 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 589 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 590 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 591 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 592 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 594 | /// \brief Transform the captures and body of a lambda expression. |
| 595 | ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator); |
| 596 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 597 | ExprResult TransformAddressOfOperand(Expr *E); |
| 598 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| 599 | bool IsAddressOfOperand); |
| 600 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 601 | #define STMT(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 602 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 603 | #define EXPR(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 604 | ExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 605 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 606 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 608 | #define OPENMP_CLAUSE(Name, Class) \ |
| 609 | OMPClause *Transform ## Class(Class *S); |
| 610 | #include "clang/Basic/OpenMPKinds.def" |
| 611 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 612 | /// \brief Build a new pointer type given its pointee type. |
| 613 | /// |
| 614 | /// By default, performs semantic analysis when building the pointer type. |
| 615 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 616 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 617 | |
| 618 | /// \brief Build a new block pointer type given its pointee type. |
| 619 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 620 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 621 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 622 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 623 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 624 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 625 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 626 | /// By default, performs semantic analysis when building the |
| 627 | /// reference type. Subclasses may override this routine to provide |
| 628 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 629 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 630 | /// \param LValue whether the type was written with an lvalue sigil |
| 631 | /// or an rvalue sigil. |
| 632 | QualType RebuildReferenceType(QualType ReferentType, |
| 633 | bool LValue, |
| 634 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 636 | /// \brief Build a new member pointer type given the pointee type and the |
| 637 | /// class type it refers into. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis when building the member pointer |
| 640 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 641 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 642 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 644 | /// \brief Build a new array type given the element type, size |
| 645 | /// modifier, size of the array (if known), size expression, and index type |
| 646 | /// qualifiers. |
| 647 | /// |
| 648 | /// By default, performs semantic analysis when building the array type. |
| 649 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 651 | QualType RebuildArrayType(QualType ElementType, |
| 652 | ArrayType::ArraySizeModifier SizeMod, |
| 653 | const llvm::APInt *Size, |
| 654 | Expr *SizeExpr, |
| 655 | unsigned IndexTypeQuals, |
| 656 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 658 | /// \brief Build a new constant array type given the element type, size |
| 659 | /// modifier, (known) size of the array, and index type qualifiers. |
| 660 | /// |
| 661 | /// By default, performs semantic analysis when building the array type. |
| 662 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 664 | ArrayType::ArraySizeModifier SizeMod, |
| 665 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 666 | unsigned IndexTypeQuals, |
| 667 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 668 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 669 | /// \brief Build a new incomplete array type given the element type, size |
| 670 | /// modifier, and index type qualifiers. |
| 671 | /// |
| 672 | /// By default, performs semantic analysis when building the array type. |
| 673 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 675 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 676 | unsigned IndexTypeQuals, |
| 677 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 678 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 680 | /// size modifier, size expression, and index type qualifiers. |
| 681 | /// |
| 682 | /// By default, performs semantic analysis when building the array type. |
| 683 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 685 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 686 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 687 | unsigned IndexTypeQuals, |
| 688 | SourceRange BracketsRange); |
| 689 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 691 | /// size modifier, size expression, and index type qualifiers. |
| 692 | /// |
| 693 | /// By default, performs semantic analysis when building the array type. |
| 694 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 696 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 697 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 698 | unsigned IndexTypeQuals, |
| 699 | SourceRange BracketsRange); |
| 700 | |
| 701 | /// \brief Build a new vector type given the element type and |
| 702 | /// number of elements. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis when building the vector type. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 706 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 707 | VectorType::VectorKind VecKind); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 709 | /// \brief Build a new extended vector type given the element type and |
| 710 | /// number of elements. |
| 711 | /// |
| 712 | /// By default, performs semantic analysis when building the vector type. |
| 713 | /// Subclasses may override this routine to provide different behavior. |
| 714 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 715 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 716 | |
| 717 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 718 | /// given the element type and number of elements. |
| 719 | /// |
| 720 | /// By default, performs semantic analysis when building the vector type. |
| 721 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 723 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 724 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 726 | /// \brief Build a new function type. |
| 727 | /// |
| 728 | /// By default, performs semantic analysis when building the function type. |
| 729 | /// Subclasses may override this routine to provide different behavior. |
| 730 | QualType RebuildFunctionProtoType(QualType T, |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 731 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 732 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 734 | /// \brief Build a new unprototyped function type. |
| 735 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 736 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 737 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 738 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 739 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 740 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 741 | /// \brief Build a new typedef type. |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 742 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 743 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 744 | } |
| 745 | |
| 746 | /// \brief Build a new class/struct/union type. |
| 747 | QualType RebuildRecordType(RecordDecl *Record) { |
| 748 | return SemaRef.Context.getTypeDeclType(Record); |
| 749 | } |
| 750 | |
| 751 | /// \brief Build a new Enum type. |
| 752 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 753 | return SemaRef.Context.getTypeDeclType(Enum); |
| 754 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 755 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 757 | /// |
| 758 | /// By default, performs semantic analysis when building the typeof type. |
| 759 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 760 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 761 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 763 | /// |
| 764 | /// By default, builds a new TypeOfType with the given underlying type. |
| 765 | QualType RebuildTypeOfType(QualType Underlying); |
| 766 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 767 | /// \brief Build a new unary transform type. |
| 768 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 769 | UnaryTransformType::UTTKind UKind, |
| 770 | SourceLocation Loc); |
| 771 | |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 772 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 773 | /// |
| 774 | /// By default, performs semantic analysis when building the decltype type. |
| 775 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 776 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 778 | /// \brief Build a new C++11 auto type. |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 779 | /// |
| 780 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 781 | QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) { |
Richard Smith | dc7a4f5 | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 782 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 783 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 784 | // that we'll retry deduction after the transformation. |
Faisal Vali | ecb5819 | 2013-08-22 01:49:11 +0000 | [diff] [blame] | 785 | // FIXME: Can we assume the same about IsParameterPack? |
| 786 | return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto, |
| 787 | /*IsDependent*/ false, |
| 788 | /*IsParameterPack*/ false); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 791 | /// \brief Build a new template specialization type. |
| 792 | /// |
| 793 | /// By default, performs semantic analysis when building the template |
| 794 | /// specialization type. Subclasses may override this routine to provide |
| 795 | /// different behavior. |
| 796 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 797 | SourceLocation TemplateLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 798 | TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 800 | /// \brief Build a new parenthesized type. |
| 801 | /// |
| 802 | /// By default, builds a new ParenType type from the inner type. |
| 803 | /// Subclasses may override this routine to provide different behavior. |
| 804 | QualType RebuildParenType(QualType InnerType) { |
| 805 | return SemaRef.Context.getParenType(InnerType); |
| 806 | } |
| 807 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 808 | /// \brief Build a new qualified name type. |
| 809 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 810 | /// By default, builds a new ElaboratedType type from the keyword, |
| 811 | /// the nested-name-specifier and the named type. |
| 812 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 813 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 814 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 815 | NestedNameSpecifierLoc QualifierLoc, |
| 816 | QualType Named) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 817 | return SemaRef.Context.getElaboratedType(Keyword, |
| 818 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 819 | Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 820 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 821 | |
| 822 | /// \brief Build a new typename type that refers to a template-id. |
| 823 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 824 | /// By default, builds a new DependentNameType type from the |
| 825 | /// nested-name-specifier and the given type. Subclasses may override |
| 826 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 827 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 828 | ElaboratedTypeKeyword Keyword, |
| 829 | NestedNameSpecifierLoc QualifierLoc, |
| 830 | const IdentifierInfo *Name, |
| 831 | SourceLocation NameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 832 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 833 | // Rebuild the template name. |
| 834 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 835 | CXXScopeSpec SS; |
| 836 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 837 | TemplateName InstName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 838 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 839 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 840 | if (InstName.isNull()) |
| 841 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 842 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 843 | // If it's still dependent, make a dependent specialization. |
| 844 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 845 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 846 | QualifierLoc.getNestedNameSpecifier(), |
| 847 | Name, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 848 | Args); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 849 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 850 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 851 | // specialization. |
| 852 | QualType T = |
| 853 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 854 | if (T.isNull()) return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 855 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 856 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 857 | return T; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 858 | |
| 859 | return SemaRef.Context.getElaboratedType(Keyword, |
| 860 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 861 | T); |
| 862 | } |
| 863 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 864 | /// \brief Build a new typename type that refers to an identifier. |
| 865 | /// |
| 866 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 867 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 868 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 869 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 870 | SourceLocation KeywordLoc, |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 871 | NestedNameSpecifierLoc QualifierLoc, |
| 872 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 873 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 874 | CXXScopeSpec SS; |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 875 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 876 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 877 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 878 | // If the name is still dependent, just build a new dependent name type. |
| 879 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 880 | return SemaRef.Context.getDependentNameType(Keyword, |
| 881 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 882 | Id); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 885 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 886 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | e29425b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 887 | *Id, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 888 | |
| 889 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 890 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 891 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 892 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 893 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 894 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 895 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 896 | if (!DC) |
| 897 | return QualType(); |
| 898 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 899 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 900 | return QualType(); |
| 901 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 902 | TagDecl *Tag = 0; |
| 903 | SemaRef.LookupQualifiedName(Result, DC); |
| 904 | switch (Result.getResultKind()) { |
| 905 | case LookupResult::NotFound: |
| 906 | case LookupResult::NotFoundInCurrentInstantiation: |
| 907 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 908 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 909 | case LookupResult::Found: |
| 910 | Tag = Result.getAsSingle<TagDecl>(); |
| 911 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 912 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 913 | case LookupResult::FoundOverloaded: |
| 914 | case LookupResult::FoundUnresolvedValue: |
| 915 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 916 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 917 | case LookupResult::Ambiguous: |
| 918 | // Let the LookupResult structure handle ambiguities. |
| 919 | return QualType(); |
| 920 | } |
| 921 | |
| 922 | if (!Tag) { |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 923 | // Check where the name exists but isn't a tag type and use that to emit |
| 924 | // better diagnostics. |
| 925 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 926 | SemaRef.LookupQualifiedName(Result, DC); |
| 927 | switch (Result.getResultKind()) { |
| 928 | case LookupResult::Found: |
| 929 | case LookupResult::FoundOverloaded: |
| 930 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 931 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 932 | unsigned Kind = 0; |
| 933 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 934 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 935 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 936 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 937 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 938 | break; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 939 | } |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 940 | default: |
| 941 | // FIXME: Would be nice to highlight just the source range. |
| 942 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 943 | << Kind << Id << DC; |
| 944 | break; |
| 945 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 946 | return QualType(); |
| 947 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 948 | |
Richard Trieu | bbf34c0 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 949 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 950 | IdLoc, *Id)) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 951 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 952 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 953 | return QualType(); |
| 954 | } |
| 955 | |
| 956 | // Build the elaborated-type-specifier type. |
| 957 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 958 | return SemaRef.Context.getElaboratedType(Keyword, |
| 959 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 960 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 961 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 962 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 963 | /// \brief Build a new pack expansion type. |
| 964 | /// |
| 965 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 966 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 967 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 968 | SourceRange PatternRange, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 969 | SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 970 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 971 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 972 | NumExpansions); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 973 | } |
| 974 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 975 | /// \brief Build a new atomic type given its value type. |
| 976 | /// |
| 977 | /// By default, performs semantic analysis when building the atomic type. |
| 978 | /// Subclasses may override this routine to provide different behavior. |
| 979 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 980 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 981 | /// \brief Build a new template name given a nested name specifier, a flag |
| 982 | /// indicating whether the "template" keyword was provided, and the template |
| 983 | /// that the template name refers to. |
| 984 | /// |
| 985 | /// By default, builds the new template name directly. Subclasses may override |
| 986 | /// this routine to provide different behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 987 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 988 | bool TemplateKW, |
| 989 | TemplateDecl *Template); |
| 990 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 991 | /// \brief Build a new template name given a nested name specifier and the |
| 992 | /// name that is referred to as a template. |
| 993 | /// |
| 994 | /// By default, performs semantic analysis to determine whether the name can |
| 995 | /// be resolved to a specific template, then builds the appropriate kind of |
| 996 | /// template name. Subclasses may override this routine to provide different |
| 997 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 998 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 999 | const IdentifierInfo &Name, |
| 1000 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1001 | QualType ObjectType, |
| 1002 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1003 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1004 | /// \brief Build a new template name given a nested name specifier and the |
| 1005 | /// overloaded operator name that is referred to as a template. |
| 1006 | /// |
| 1007 | /// By default, performs semantic analysis to determine whether the name can |
| 1008 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1009 | /// template name. Subclasses may override this routine to provide different |
| 1010 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1011 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1012 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1013 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1014 | QualType ObjectType); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1015 | |
| 1016 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1017 | /// and the |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1018 | /// |
| 1019 | /// By default, performs semantic analysis to determine whether the name can |
| 1020 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1021 | /// template name. Subclasses may override this routine to provide different |
| 1022 | /// behavior. |
| 1023 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1024 | const TemplateArgument &ArgPack) { |
| 1025 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1026 | } |
| 1027 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1028 | /// \brief Build a new compound statement. |
| 1029 | /// |
| 1030 | /// By default, performs semantic analysis to build the new statement. |
| 1031 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1032 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1033 | MultiStmtArg Statements, |
| 1034 | SourceLocation RBraceLoc, |
| 1035 | bool IsStmtExpr) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1036 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1037 | IsStmtExpr); |
| 1038 | } |
| 1039 | |
| 1040 | /// \brief Build a new case statement. |
| 1041 | /// |
| 1042 | /// By default, performs semantic analysis to build the new statement. |
| 1043 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1044 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1045 | Expr *LHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1046 | SourceLocation EllipsisLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1047 | Expr *RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1048 | SourceLocation ColonLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1049 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1050 | ColonLoc); |
| 1051 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1052 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1053 | /// \brief Attach the body to a new case statement. |
| 1054 | /// |
| 1055 | /// By default, performs semantic analysis to build the new statement. |
| 1056 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1057 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1058 | getSema().ActOnCaseStmtBody(S, Body); |
| 1059 | return S; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1060 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1062 | /// \brief Build a new default statement. |
| 1063 | /// |
| 1064 | /// By default, performs semantic analysis to build the new statement. |
| 1065 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1066 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1067 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1068 | Stmt *SubStmt) { |
| 1069 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1070 | /*CurScope=*/0); |
| 1071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1073 | /// \brief Build a new label statement. |
| 1074 | /// |
| 1075 | /// By default, performs semantic analysis to build the new statement. |
| 1076 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1077 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1078 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1079 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1080 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1082 | /// \brief Build a new label statement. |
| 1083 | /// |
| 1084 | /// By default, performs semantic analysis to build the new statement. |
| 1085 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1086 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1087 | ArrayRef<const Attr*> Attrs, |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1088 | Stmt *SubStmt) { |
| 1089 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1090 | } |
| 1091 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1092 | /// \brief Build a new "if" statement. |
| 1093 | /// |
| 1094 | /// By default, performs semantic analysis to build the new statement. |
| 1095 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1096 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1097 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1098 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1099 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1100 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1102 | /// \brief Start building a new switch statement. |
| 1103 | /// |
| 1104 | /// By default, performs semantic analysis to build the new statement. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1106 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1107 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1108 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1109 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1110 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1112 | /// \brief Attach the body to the switch statement. |
| 1113 | /// |
| 1114 | /// By default, performs semantic analysis to build the new statement. |
| 1115 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1116 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1117 | Stmt *Switch, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1118 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | /// \brief Build a new while statement. |
| 1122 | /// |
| 1123 | /// By default, performs semantic analysis to build the new statement. |
| 1124 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1125 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1126 | VarDecl *CondVar, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1127 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1128 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1130 | /// \brief Build a new do-while statement. |
| 1131 | /// |
| 1132 | /// By default, performs semantic analysis to build the new statement. |
| 1133 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1134 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1135 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1136 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1137 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1138 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /// \brief Build a new for statement. |
| 1142 | /// |
| 1143 | /// By default, performs semantic analysis to build the new statement. |
| 1144 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1145 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1146 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1147 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1148 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1149 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1150 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1151 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1152 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1153 | /// \brief Build a new goto statement. |
| 1154 | /// |
| 1155 | /// By default, performs semantic analysis to build the new statement. |
| 1156 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1157 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1158 | LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1159 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /// \brief Build a new indirect goto statement. |
| 1163 | /// |
| 1164 | /// By default, performs semantic analysis to build the new statement. |
| 1165 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1166 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1167 | SourceLocation StarLoc, |
| 1168 | Expr *Target) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1169 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1170 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1171 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1172 | /// \brief Build a new return statement. |
| 1173 | /// |
| 1174 | /// By default, performs semantic analysis to build the new statement. |
| 1175 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1176 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1177 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1180 | /// \brief Build a new declaration statement. |
| 1181 | /// |
| 1182 | /// By default, performs semantic analysis to build the new statement. |
| 1183 | /// Subclasses may override this routine to provide different behavior. |
Rafael Espindola | 4549d7f | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1184 | StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls, |
| 1185 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1186 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 406c38e | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1187 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1188 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1189 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1190 | /// \brief Build a new inline asm statement. |
| 1191 | /// |
| 1192 | /// By default, performs semantic analysis to build the new statement. |
| 1193 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1194 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1195 | bool IsVolatile, unsigned NumOutputs, |
| 1196 | unsigned NumInputs, IdentifierInfo **Names, |
| 1197 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1198 | Expr *AsmString, MultiExprArg Clobbers, |
| 1199 | SourceLocation RParenLoc) { |
| 1200 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1201 | NumInputs, Names, Constraints, Exprs, |
| 1202 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1203 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1204 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1205 | /// \brief Build a new MS style inline asm statement. |
| 1206 | /// |
| 1207 | /// By default, performs semantic analysis to build the new statement. |
| 1208 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1209 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1210 | ArrayRef<Token> AsmToks, |
| 1211 | StringRef AsmString, |
| 1212 | unsigned NumOutputs, unsigned NumInputs, |
| 1213 | ArrayRef<StringRef> Constraints, |
| 1214 | ArrayRef<StringRef> Clobbers, |
| 1215 | ArrayRef<Expr*> Exprs, |
| 1216 | SourceLocation EndLoc) { |
| 1217 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1218 | NumOutputs, NumInputs, |
| 1219 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1222 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1223 | /// |
| 1224 | /// By default, performs semantic analysis to build the new statement. |
| 1225 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1226 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1227 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1228 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1229 | Stmt *Finally) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1230 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1231 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1234 | /// \brief Rebuild an Objective-C exception declaration. |
| 1235 | /// |
| 1236 | /// By default, performs semantic analysis to build the new declaration. |
| 1237 | /// Subclasses may override this routine to provide different behavior. |
| 1238 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1239 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1240 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1241 | ExceptionDecl->getInnerLocStart(), |
| 1242 | ExceptionDecl->getLocation(), |
| 1243 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1244 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1245 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1246 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1247 | /// |
| 1248 | /// By default, performs semantic analysis to build the new statement. |
| 1249 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1250 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1251 | SourceLocation RParenLoc, |
| 1252 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1253 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1254 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1255 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1256 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1257 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1258 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1259 | /// |
| 1260 | /// By default, performs semantic analysis to build the new statement. |
| 1261 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1262 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1263 | Stmt *Body) { |
| 1264 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1265 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1266 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1267 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1268 | /// |
| 1269 | /// By default, performs semantic analysis to build the new statement. |
| 1270 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1271 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1272 | Expr *Operand) { |
| 1273 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1274 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1275 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1276 | /// \brief Build a new OpenMP parallel directive. |
| 1277 | /// |
| 1278 | /// By default, performs semantic analysis to build the new statement. |
| 1279 | /// Subclasses may override this routine to provide different behavior. |
| 1280 | StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 1281 | Stmt *AStmt, |
| 1282 | SourceLocation StartLoc, |
| 1283 | SourceLocation EndLoc) { |
| 1284 | return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt, |
| 1285 | StartLoc, EndLoc); |
| 1286 | } |
| 1287 | |
| 1288 | /// \brief Build a new OpenMP 'default' clause. |
| 1289 | /// |
| 1290 | /// By default, performs semantic analysis to build the new statement. |
| 1291 | /// Subclasses may override this routine to provide different behavior. |
| 1292 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1293 | SourceLocation KindKwLoc, |
| 1294 | SourceLocation StartLoc, |
| 1295 | SourceLocation LParenLoc, |
| 1296 | SourceLocation EndLoc) { |
| 1297 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1298 | StartLoc, LParenLoc, EndLoc); |
| 1299 | } |
| 1300 | |
| 1301 | /// \brief Build a new OpenMP 'private' clause. |
| 1302 | /// |
| 1303 | /// By default, performs semantic analysis to build the new statement. |
| 1304 | /// Subclasses may override this routine to provide different behavior. |
| 1305 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1306 | SourceLocation StartLoc, |
| 1307 | SourceLocation LParenLoc, |
| 1308 | SourceLocation EndLoc) { |
| 1309 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1310 | EndLoc); |
| 1311 | } |
| 1312 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1313 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1314 | /// |
| 1315 | /// By default, performs semantic analysis to build the new statement. |
| 1316 | /// Subclasses may override this routine to provide different behavior. |
| 1317 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1318 | Expr *object) { |
| 1319 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1320 | } |
| 1321 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1322 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1323 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1324 | /// By default, performs semantic analysis to build the new statement. |
| 1325 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1326 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1327 | Expr *Object, Stmt *Body) { |
| 1328 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1329 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1330 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1331 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1332 | /// |
| 1333 | /// By default, performs semantic analysis to build the new statement. |
| 1334 | /// Subclasses may override this routine to provide different behavior. |
| 1335 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1336 | Stmt *Body) { |
| 1337 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1338 | } |
John McCall | 990567c | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1339 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1340 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1341 | /// |
| 1342 | /// By default, performs semantic analysis to build the new statement. |
| 1343 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1344 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1345 | Stmt *Element, |
| 1346 | Expr *Collection, |
| 1347 | SourceLocation RParenLoc, |
| 1348 | Stmt *Body) { |
Sam Panzer | bc20bbb | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1349 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1350 | Element, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1351 | Collection, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1352 | RParenLoc); |
| 1353 | if (ForEachStmt.isInvalid()) |
| 1354 | return StmtError(); |
| 1355 | |
| 1356 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1357 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1358 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1359 | /// \brief Build a new C++ exception declaration. |
| 1360 | /// |
| 1361 | /// By default, performs semantic analysis to build the new decaration. |
| 1362 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1363 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1364 | TypeSourceInfo *Declarator, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1365 | SourceLocation StartLoc, |
| 1366 | SourceLocation IdLoc, |
| 1367 | IdentifierInfo *Id) { |
Douglas Gregor | efdf988 | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1368 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1369 | StartLoc, IdLoc, Id); |
| 1370 | if (Var) |
| 1371 | getSema().CurContext->addDecl(Var); |
| 1372 | return Var; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | /// \brief Build a new C++ catch statement. |
| 1376 | /// |
| 1377 | /// By default, performs semantic analysis to build the new statement. |
| 1378 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1379 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1380 | VarDecl *ExceptionDecl, |
| 1381 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1382 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1383 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1384 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1386 | /// \brief Build a new C++ try statement. |
| 1387 | /// |
| 1388 | /// By default, performs semantic analysis to build the new statement. |
| 1389 | /// Subclasses may override this routine to provide different behavior. |
Robert Wilhelm | 21adb0c | 2013-08-22 09:20:03 +0000 | [diff] [blame^] | 1390 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 1391 | ArrayRef<Stmt *> Handlers) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1392 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1393 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1394 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1395 | /// \brief Build a new C++0x range-based for statement. |
| 1396 | /// |
| 1397 | /// By default, performs semantic analysis to build the new statement. |
| 1398 | /// Subclasses may override this routine to provide different behavior. |
| 1399 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1400 | SourceLocation ColonLoc, |
| 1401 | Stmt *Range, Stmt *BeginEnd, |
| 1402 | Expr *Cond, Expr *Inc, |
| 1403 | Stmt *LoopVar, |
| 1404 | SourceLocation RParenLoc) { |
Douglas Gregor | 6f96f4b | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1405 | // If we've just learned that the range is actually an Objective-C |
| 1406 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1407 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1408 | if (RangeStmt->isSingleDecl()) { |
| 1409 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1410 | if (RangeVar->isInvalidDecl()) |
| 1411 | return StmtError(); |
| 1412 | |
Douglas Gregor | 6f96f4b | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1413 | Expr *RangeExpr = RangeVar->getInit(); |
| 1414 | if (!RangeExpr->isTypeDependent() && |
| 1415 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1416 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1417 | RParenLoc); |
| 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1422 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | 8b533d9 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1423 | Cond, Inc, LoopVar, RParenLoc, |
| 1424 | Sema::BFRK_Rebuild); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1425 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1426 | |
| 1427 | /// \brief Build a new C++0x range-based for statement. |
| 1428 | /// |
| 1429 | /// By default, performs semantic analysis to build the new statement. |
| 1430 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1431 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1432 | bool IsIfExists, |
| 1433 | NestedNameSpecifierLoc QualifierLoc, |
| 1434 | DeclarationNameInfo NameInfo, |
| 1435 | Stmt *Nested) { |
| 1436 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1437 | QualifierLoc, NameInfo, Nested); |
| 1438 | } |
| 1439 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1440 | /// \brief Attach body to a C++0x range-based for statement. |
| 1441 | /// |
| 1442 | /// By default, performs semantic analysis to finish the new statement. |
| 1443 | /// Subclasses may override this routine to provide different behavior. |
| 1444 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1445 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1446 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1447 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1448 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, |
| 1449 | SourceLocation TryLoc, |
| 1450 | Stmt *TryBlock, |
| 1451 | Stmt *Handler) { |
| 1452 | return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1453 | } |
| 1454 | |
| 1455 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, |
| 1456 | Expr *FilterExpr, |
| 1457 | Stmt *Block) { |
| 1458 | return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); |
| 1459 | } |
| 1460 | |
| 1461 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, |
| 1462 | Stmt *Block) { |
| 1463 | return getSema().ActOnSEHFinallyBlock(Loc,Block); |
| 1464 | } |
| 1465 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1466 | /// \brief Build a new expression that references a declaration. |
| 1467 | /// |
| 1468 | /// By default, performs semantic analysis to build the new expression. |
| 1469 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1470 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1471 | LookupResult &R, |
| 1472 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1473 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1474 | } |
| 1475 | |
| 1476 | |
| 1477 | /// \brief Build a new expression that references a declaration. |
| 1478 | /// |
| 1479 | /// By default, performs semantic analysis to build the new expression. |
| 1480 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1481 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1482 | ValueDecl *VD, |
| 1483 | const DeclarationNameInfo &NameInfo, |
| 1484 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1485 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1486 | SS.Adopt(QualifierLoc); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1487 | |
| 1488 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1489 | |
| 1490 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1491 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1492 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | /// By default, performs semantic analysis to build the new expression. |
| 1496 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1497 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1499 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1502 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1503 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1504 | /// By default, performs semantic analysis to build the new expression. |
| 1505 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1506 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1507 | SourceLocation OperatorLoc, |
| 1508 | bool isArrow, |
| 1509 | CXXScopeSpec &SS, |
| 1510 | TypeSourceInfo *ScopeType, |
| 1511 | SourceLocation CCLoc, |
| 1512 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1513 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1514 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1515 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1516 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1517 | /// By default, performs semantic analysis to build the new expression. |
| 1518 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1519 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1520 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1521 | Expr *SubExpr) { |
| 1522 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1523 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1525 | /// \brief Build a new builtin offsetof expression. |
| 1526 | /// |
| 1527 | /// By default, performs semantic analysis to build the new expression. |
| 1528 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1529 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1530 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1531 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1532 | unsigned NumComponents, |
| 1533 | SourceLocation RParenLoc) { |
| 1534 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1535 | NumComponents, RParenLoc); |
| 1536 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1537 | |
| 1538 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1539 | /// type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1540 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1541 | /// By default, performs semantic analysis to build the new expression. |
| 1542 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1543 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1544 | SourceLocation OpLoc, |
| 1545 | UnaryExprOrTypeTrait ExprKind, |
| 1546 | SourceRange R) { |
| 1547 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1550 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1551 | /// expression argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1552 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1553 | /// By default, performs semantic analysis to build the new expression. |
| 1554 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1555 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1556 | UnaryExprOrTypeTrait ExprKind, |
| 1557 | SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1558 | ExprResult Result |
Chandler Carruth | e72c55b | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1559 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1561 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1562 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1563 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1564 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1565 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1566 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1567 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | /// By default, performs semantic analysis to build the new expression. |
| 1569 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1570 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1572 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1573 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1574 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1575 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1576 | RBracketLoc); |
| 1577 | } |
| 1578 | |
| 1579 | /// \brief Build a new call expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1582 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1583 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1584 | MultiExprArg Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1585 | SourceLocation RParenLoc, |
| 1586 | Expr *ExecConfig = 0) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1587 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1588 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | /// \brief Build a new member access 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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1596 | bool isArrow, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1597 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1598 | SourceLocation TemplateKWLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1599 | const DeclarationNameInfo &MemberNameInfo, |
| 1600 | ValueDecl *Member, |
| 1601 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1602 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1603 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1604 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1605 | isArrow); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1606 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1607 | // We have a reference to an unnamed field. This is always the |
| 1608 | // base of an anonymous struct/union member access, i.e. the |
| 1609 | // field is always of record type. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1610 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1611 | assert(Member->getType()->isRecordType() && |
| 1612 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1613 | |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1614 | BaseResult = |
| 1615 | getSema().PerformObjectMemberConversion(BaseResult.take(), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1616 | QualifierLoc.getNestedNameSpecifier(), |
| 1617 | FoundDecl, Member); |
| 1618 | if (BaseResult.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1619 | return ExprError(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1620 | Base = BaseResult.take(); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1621 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1622 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1623 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1624 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1625 | cast<FieldDecl>(Member)->getType(), |
| 1626 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1627 | return getSema().Owned(ME); |
| 1628 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1630 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1631 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1632 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1633 | Base = BaseResult.take(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1634 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1635 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1636 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1637 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1638 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1639 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1640 | R.resolveKind(); |
| 1641 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1642 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1643 | SS, TemplateKWLoc, |
| 1644 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1645 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | /// By default, performs semantic analysis to build the new expression. |
| 1651 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1652 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1653 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1654 | Expr *LHS, Expr *RHS) { |
| 1655 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1659 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | /// By default, performs semantic analysis to build the new expression. |
| 1661 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1662 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1663 | SourceLocation QuestionLoc, |
| 1664 | Expr *LHS, |
| 1665 | SourceLocation ColonLoc, |
| 1666 | Expr *RHS) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1667 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1668 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1671 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1672 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | /// By default, performs semantic analysis to build the new expression. |
| 1674 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1675 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1676 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1677 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1678 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1679 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1680 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | /// \brief Build a new compound literal expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1686 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1687 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1688 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1690 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1691 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1692 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1694 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1697 | /// By default, performs semantic analysis to build the new expression. |
| 1698 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1699 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1700 | SourceLocation OpLoc, |
| 1701 | SourceLocation AccessorLoc, |
| 1702 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1703 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1704 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1705 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1706 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1707 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1708 | SS, SourceLocation(), |
| 1709 | /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1710 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1711 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1712 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | /// \brief Build a new initializer list expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1717 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1718 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1719 | MultiExprArg Inits, |
| 1720 | SourceLocation RBraceLoc, |
| 1721 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1722 | ExprResult Result |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1723 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1724 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1725 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1726 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1727 | // Patch in the result type we were given, which may have been computed |
| 1728 | // when the initial InitListExpr was built. |
| 1729 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1730 | ILE->setType(ResultTy); |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1731 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1734 | /// \brief Build a new designated initializer expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1737 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1738 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1739 | MultiExprArg ArrayExprs, |
| 1740 | SourceLocation EqualOrColonLoc, |
| 1741 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1742 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1743 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1744 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1745 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1746 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1747 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1749 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1750 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1752 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1753 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1754 | /// By default, builds the implicit value initialization without performing |
| 1755 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1756 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1757 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1758 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1759 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1761 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1762 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1763 | /// By default, performs semantic analysis to build the new expression. |
| 1764 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1765 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1766 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1767 | SourceLocation RParenLoc) { |
| 1768 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1769 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1770 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1775 | /// By default, performs semantic analysis to build the new expression. |
| 1776 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1777 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1778 | MultiExprArg SubExprs, |
| 1779 | SourceLocation RParenLoc) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1780 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1781 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1783 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 | /// |
| 1785 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1786 | /// rather than attempting to map the label statement itself. |
| 1787 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1788 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1789 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1790 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1791 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1793 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1794 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | /// By default, performs semantic analysis to build the new expression. |
| 1796 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1797 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1798 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1799 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1800 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1801 | } |
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 | /// \brief Build a new __builtin_choose_expr expression. |
| 1804 | /// |
| 1805 | /// By default, performs semantic analysis to build the new expression. |
| 1806 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1807 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1808 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1809 | SourceLocation RParenLoc) { |
| 1810 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1811 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1812 | RParenLoc); |
| 1813 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1814 | |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1815 | /// \brief Build a new generic selection expression. |
| 1816 | /// |
| 1817 | /// By default, performs semantic analysis to build the new expression. |
| 1818 | /// Subclasses may override this routine to provide different behavior. |
| 1819 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1820 | SourceLocation DefaultLoc, |
| 1821 | SourceLocation RParenLoc, |
| 1822 | Expr *ControllingExpr, |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 1823 | ArrayRef<TypeSourceInfo *> Types, |
| 1824 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1825 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 1826 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1829 | /// \brief Build a new overloaded operator call expression. |
| 1830 | /// |
| 1831 | /// By default, performs semantic analysis to build the new expression. |
| 1832 | /// The semantic analysis provides the behavior of template instantiation, |
| 1833 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1835 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1836 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1837 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1838 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1839 | Expr *Callee, |
| 1840 | Expr *First, |
| 1841 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | |
| 1843 | /// \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] | 1844 | /// reinterpret_cast. |
| 1845 | /// |
| 1846 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1848 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1849 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1850 | Stmt::StmtClass Class, |
| 1851 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1852 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1853 | SourceLocation RAngleLoc, |
| 1854 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1855 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1856 | SourceLocation RParenLoc) { |
| 1857 | switch (Class) { |
| 1858 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1859 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1860 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1861 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1862 | |
| 1863 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1864 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1866 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1868 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1869 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1870 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1871 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1872 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1873 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1874 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1875 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1877 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1878 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1879 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1880 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1881 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1882 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1883 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1884 | /// \brief Build a new C++ static_cast expression. |
| 1885 | /// |
| 1886 | /// By default, performs semantic analysis to build the new expression. |
| 1887 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1888 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1889 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1890 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1891 | SourceLocation RAngleLoc, |
| 1892 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1893 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1894 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1895 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1896 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1897 | SourceRange(LAngleLoc, RAngleLoc), |
| 1898 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | /// \brief Build a new C++ dynamic_cast expression. |
| 1902 | /// |
| 1903 | /// By default, performs semantic analysis to build the new expression. |
| 1904 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1905 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1906 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1907 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1908 | SourceLocation RAngleLoc, |
| 1909 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1910 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1911 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1912 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1913 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1914 | SourceRange(LAngleLoc, RAngleLoc), |
| 1915 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1919 | /// |
| 1920 | /// By default, performs semantic analysis to build the new expression. |
| 1921 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1922 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1923 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1924 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1925 | SourceLocation RAngleLoc, |
| 1926 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1927 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1928 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1929 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1930 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1931 | SourceRange(LAngleLoc, RAngleLoc), |
| 1932 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /// \brief Build a new C++ const_cast expression. |
| 1936 | /// |
| 1937 | /// By default, performs semantic analysis to build the new expression. |
| 1938 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1939 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1940 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1941 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1942 | SourceLocation RAngleLoc, |
| 1943 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1944 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1945 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1946 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1947 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1948 | SourceRange(LAngleLoc, RAngleLoc), |
| 1949 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1950 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1951 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1952 | /// \brief Build a new C++ functional-style cast expression. |
| 1953 | /// |
| 1954 | /// By default, performs semantic analysis to build the new expression. |
| 1955 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1956 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1957 | SourceLocation LParenLoc, |
| 1958 | Expr *Sub, |
| 1959 | SourceLocation RParenLoc) { |
| 1960 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1961 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1962 | RParenLoc); |
| 1963 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1964 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1965 | /// \brief Build a new C++ typeid(type) expression. |
| 1966 | /// |
| 1967 | /// By default, performs semantic analysis to build the new expression. |
| 1968 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1969 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1970 | SourceLocation TypeidLoc, |
| 1971 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1972 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1973 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1974 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1975 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1976 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1977 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1978 | /// \brief Build a new C++ typeid(expr) expression. |
| 1979 | /// |
| 1980 | /// By default, performs semantic analysis to build the new expression. |
| 1981 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1982 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1983 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1984 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1985 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1986 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1987 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1990 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1991 | /// |
| 1992 | /// By default, performs semantic analysis to build the new expression. |
| 1993 | /// Subclasses may override this routine to provide different behavior. |
| 1994 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1995 | SourceLocation TypeidLoc, |
| 1996 | TypeSourceInfo *Operand, |
| 1997 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1998 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1999 | RParenLoc); |
| 2000 | } |
| 2001 | |
| 2002 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2003 | /// |
| 2004 | /// By default, performs semantic analysis to build the new expression. |
| 2005 | /// Subclasses may override this routine to provide different behavior. |
| 2006 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2007 | SourceLocation TypeidLoc, |
| 2008 | Expr *Operand, |
| 2009 | SourceLocation RParenLoc) { |
| 2010 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2011 | RParenLoc); |
| 2012 | } |
| 2013 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | /// \brief Build a new C++ "this" expression. |
| 2015 | /// |
| 2016 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2018 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2019 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2020 | QualType ThisType, |
| 2021 | bool isImplicit) { |
Eli Friedman | b69b42c | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2022 | getSema().CheckCXXThisCapture(ThisLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2023 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 2024 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 2025 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | /// \brief Build a new C++ throw expression. |
| 2029 | /// |
| 2030 | /// By default, performs semantic analysis to build the new expression. |
| 2031 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2032 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2033 | bool IsThrownVariableInScope) { |
| 2034 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | /// \brief Build a new C++ default-argument expression. |
| 2038 | /// |
| 2039 | /// By default, builds a new default-argument expression, which does not |
| 2040 | /// require any semantic analysis. Subclasses may override this routine to |
| 2041 | /// provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2042 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2043 | ParmVarDecl *Param) { |
| 2044 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 2045 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2048 | /// \brief Build a new C++11 default-initialization expression. |
| 2049 | /// |
| 2050 | /// By default, builds a new default field initialization expression, which |
| 2051 | /// does not require any semantic analysis. Subclasses may override this |
| 2052 | /// routine to provide different behavior. |
| 2053 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2054 | FieldDecl *Field) { |
| 2055 | return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc, |
| 2056 | Field)); |
| 2057 | } |
| 2058 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2059 | /// \brief Build a new C++ zero-initialization expression. |
| 2060 | /// |
| 2061 | /// By default, performs semantic analysis to build the new expression. |
| 2062 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2063 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2064 | SourceLocation LParenLoc, |
| 2065 | SourceLocation RParenLoc) { |
| 2066 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2067 | None, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2069 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2070 | /// \brief Build a new C++ "new" expression. |
| 2071 | /// |
| 2072 | /// By default, performs semantic analysis to build the new expression. |
| 2073 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2074 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2075 | bool UseGlobal, |
| 2076 | SourceLocation PlacementLParen, |
| 2077 | MultiExprArg PlacementArgs, |
| 2078 | SourceLocation PlacementRParen, |
| 2079 | SourceRange TypeIdParens, |
| 2080 | QualType AllocatedType, |
| 2081 | TypeSourceInfo *AllocatedTypeInfo, |
| 2082 | Expr *ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2083 | SourceRange DirectInitRange, |
| 2084 | Expr *Initializer) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2085 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2086 | PlacementLParen, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2087 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2088 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2089 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2090 | AllocatedType, |
| 2091 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2092 | ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2093 | DirectInitRange, |
| 2094 | Initializer); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2095 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2096 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2097 | /// \brief Build a new C++ "delete" expression. |
| 2098 | /// |
| 2099 | /// By default, performs semantic analysis to build the new expression. |
| 2100 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2101 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2102 | bool IsGlobalDelete, |
| 2103 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2104 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2105 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2106 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2107 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2108 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2109 | /// \brief Build a new unary type trait expression. |
| 2110 | /// |
| 2111 | /// By default, performs semantic analysis to build the new expression. |
| 2112 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2113 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 2114 | SourceLocation StartLoc, |
| 2115 | TypeSourceInfo *T, |
| 2116 | SourceLocation RParenLoc) { |
| 2117 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2120 | /// \brief Build a new binary type trait expression. |
| 2121 | /// |
| 2122 | /// By default, performs semantic analysis to build the new expression. |
| 2123 | /// Subclasses may override this routine to provide different behavior. |
| 2124 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 2125 | SourceLocation StartLoc, |
| 2126 | TypeSourceInfo *LhsT, |
| 2127 | TypeSourceInfo *RhsT, |
| 2128 | SourceLocation RParenLoc) { |
| 2129 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 2130 | } |
| 2131 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2132 | /// \brief Build a new type trait expression. |
| 2133 | /// |
| 2134 | /// By default, performs semantic analysis to build the new expression. |
| 2135 | /// Subclasses may override this routine to provide different behavior. |
| 2136 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2137 | SourceLocation StartLoc, |
| 2138 | ArrayRef<TypeSourceInfo *> Args, |
| 2139 | SourceLocation RParenLoc) { |
| 2140 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2141 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2142 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2143 | /// \brief Build a new array type trait expression. |
| 2144 | /// |
| 2145 | /// By default, performs semantic analysis to build the new expression. |
| 2146 | /// Subclasses may override this routine to provide different behavior. |
| 2147 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2148 | SourceLocation StartLoc, |
| 2149 | TypeSourceInfo *TSInfo, |
| 2150 | Expr *DimExpr, |
| 2151 | SourceLocation RParenLoc) { |
| 2152 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2153 | } |
| 2154 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2155 | /// \brief Build a new expression trait expression. |
| 2156 | /// |
| 2157 | /// By default, performs semantic analysis to build the new expression. |
| 2158 | /// Subclasses may override this routine to provide different behavior. |
| 2159 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2160 | SourceLocation StartLoc, |
| 2161 | Expr *Queried, |
| 2162 | SourceLocation RParenLoc) { |
| 2163 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2164 | } |
| 2165 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2166 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2167 | /// expression. |
| 2168 | /// |
| 2169 | /// By default, performs semantic analysis to build the new expression. |
| 2170 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2171 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2172 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2173 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2174 | const DeclarationNameInfo &NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2175 | const TemplateArgumentListInfo *TemplateArgs, |
| 2176 | bool IsAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2177 | CXXScopeSpec SS; |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2178 | SS.Adopt(QualifierLoc); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2179 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2180 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2181 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2182 | NameInfo, TemplateArgs); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2183 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2184 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo, |
| 2185 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | /// \brief Build a new template-id expression. |
| 2189 | /// |
| 2190 | /// By default, performs semantic analysis to build the new expression. |
| 2191 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2192 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2193 | SourceLocation TemplateKWLoc, |
| 2194 | LookupResult &R, |
| 2195 | bool RequiresADL, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2196 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2197 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2198 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | /// \brief Build a new object-construction expression. |
| 2202 | /// |
| 2203 | /// By default, performs semantic analysis to build the new expression. |
| 2204 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2205 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2206 | SourceLocation Loc, |
| 2207 | CXXConstructorDecl *Constructor, |
| 2208 | bool IsElidable, |
| 2209 | MultiExprArg Args, |
| 2210 | bool HadMultipleCandidates, |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2211 | bool ListInitialization, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2212 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2213 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2214 | SourceRange ParenRange) { |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2215 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2216 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2217 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2218 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2219 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2220 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2221 | ConvertedArgs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2222 | HadMultipleCandidates, |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2223 | ListInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2224 | RequiresZeroInit, ConstructKind, |
| 2225 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | /// \brief Build a new object-construction expression. |
| 2229 | /// |
| 2230 | /// By default, performs semantic analysis to build the new expression. |
| 2231 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2232 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2233 | SourceLocation LParenLoc, |
| 2234 | MultiExprArg Args, |
| 2235 | SourceLocation RParenLoc) { |
| 2236 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2237 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2238 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2239 | RParenLoc); |
| 2240 | } |
| 2241 | |
| 2242 | /// \brief Build a new object-construction expression. |
| 2243 | /// |
| 2244 | /// By default, performs semantic analysis to build the new expression. |
| 2245 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2246 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2247 | SourceLocation LParenLoc, |
| 2248 | MultiExprArg Args, |
| 2249 | SourceLocation RParenLoc) { |
| 2250 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2251 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2252 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2253 | RParenLoc); |
| 2254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2255 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2256 | /// \brief Build a new member reference expression. |
| 2257 | /// |
| 2258 | /// By default, performs semantic analysis to build the new expression. |
| 2259 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2260 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2261 | QualType BaseType, |
| 2262 | bool IsArrow, |
| 2263 | SourceLocation OperatorLoc, |
| 2264 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2265 | SourceLocation TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2266 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2267 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2268 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2269 | CXXScopeSpec SS; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2270 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2271 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2272 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2273 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2274 | SS, TemplateKWLoc, |
| 2275 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2276 | MemberNameInfo, |
| 2277 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2280 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2281 | /// |
| 2282 | /// By default, performs semantic analysis to build the new expression. |
| 2283 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2284 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2285 | SourceLocation OperatorLoc, |
| 2286 | bool IsArrow, |
| 2287 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2288 | SourceLocation TemplateKWLoc, |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2289 | NamedDecl *FirstQualifierInScope, |
| 2290 | LookupResult &R, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2291 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2292 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2293 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2294 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2295 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2296 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2297 | SS, TemplateKWLoc, |
| 2298 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2299 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2300 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2301 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2302 | /// \brief Build a new noexcept expression. |
| 2303 | /// |
| 2304 | /// By default, performs semantic analysis to build the new expression. |
| 2305 | /// Subclasses may override this routine to provide different behavior. |
| 2306 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2307 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2308 | } |
| 2309 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2310 | /// \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] | 2311 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2312 | SourceLocation PackLoc, |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2313 | SourceLocation RParenLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2314 | Optional<unsigned> Length) { |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2315 | if (Length) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2316 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2317 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2318 | RParenLoc, *Length); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2319 | |
| 2320 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2321 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2322 | RParenLoc); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2323 | } |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2324 | |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2325 | /// \brief Build a new Objective-C boxed expression. |
| 2326 | /// |
| 2327 | /// By default, performs semantic analysis to build the new expression. |
| 2328 | /// Subclasses may override this routine to provide different behavior. |
| 2329 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2330 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2331 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2332 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2333 | /// \brief Build a new Objective-C array literal. |
| 2334 | /// |
| 2335 | /// By default, performs semantic analysis to build the new expression. |
| 2336 | /// Subclasses may override this routine to provide different behavior. |
| 2337 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2338 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2339 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2340 | MultiExprArg(Elements, NumElements)); |
| 2341 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2342 | |
| 2343 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2344 | Expr *Base, Expr *Key, |
| 2345 | ObjCMethodDecl *getterMethod, |
| 2346 | ObjCMethodDecl *setterMethod) { |
| 2347 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2348 | getterMethod, setterMethod); |
| 2349 | } |
| 2350 | |
| 2351 | /// \brief Build a new Objective-C dictionary literal. |
| 2352 | /// |
| 2353 | /// By default, performs semantic analysis to build the new expression. |
| 2354 | /// Subclasses may override this routine to provide different behavior. |
| 2355 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2356 | ObjCDictionaryElement *Elements, |
| 2357 | unsigned NumElements) { |
| 2358 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2359 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2360 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2361 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2362 | /// |
| 2363 | /// By default, performs semantic analysis to build the new expression. |
| 2364 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2365 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2366 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2367 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2368 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2369 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2370 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2371 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2372 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2373 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2374 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2375 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2376 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2377 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2378 | MultiExprArg Args, |
| 2379 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2380 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2381 | ReceiverTypeInfo->getType(), |
| 2382 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2383 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2384 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2388 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2389 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2390 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2391 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2392 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2393 | MultiExprArg Args, |
| 2394 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2395 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2396 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2397 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2398 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2399 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2400 | } |
| 2401 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2402 | /// \brief Build a new Objective-C ivar reference expression. |
| 2403 | /// |
| 2404 | /// By default, performs semantic analysis to build the new expression. |
| 2405 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2406 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2407 | SourceLocation IvarLoc, |
| 2408 | bool IsArrow, bool IsFreeIvar) { |
| 2409 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2410 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2411 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2412 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2413 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2414 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2415 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2416 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2417 | false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2418 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2419 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2420 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2421 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2422 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2423 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2424 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2425 | /*FIXME:*/IvarLoc, IsArrow, |
| 2426 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2427 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2428 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2429 | /*TemplateArgs=*/0); |
| 2430 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2431 | |
| 2432 | /// \brief Build a new Objective-C property reference expression. |
| 2433 | /// |
| 2434 | /// By default, performs semantic analysis to build the new expression. |
| 2435 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2436 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2437 | ObjCPropertyDecl *Property, |
| 2438 | SourceLocation PropertyLoc) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2439 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2440 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2441 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2442 | Sema::LookupMemberName); |
| 2443 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2444 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2445 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2446 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2447 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2448 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2449 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2450 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2451 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2452 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2453 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2454 | /*FIXME:*/PropertyLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2455 | SS, SourceLocation(), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2456 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2457 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2458 | /*TemplateArgs=*/0); |
| 2459 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2460 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2461 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2462 | /// |
| 2463 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2464 | /// Subclasses may override this routine to provide different behavior. |
| 2465 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2466 | ObjCMethodDecl *Getter, |
| 2467 | ObjCMethodDecl *Setter, |
| 2468 | SourceLocation PropertyLoc) { |
| 2469 | // Since these expressions can only be value-dependent, we do not |
| 2470 | // need to perform semantic analysis again. |
| 2471 | return Owned( |
| 2472 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2473 | VK_LValue, OK_ObjCProperty, |
| 2474 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2477 | /// \brief Build a new Objective-C "isa" expression. |
| 2478 | /// |
| 2479 | /// By default, performs semantic analysis to build the new expression. |
| 2480 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2481 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2482 | SourceLocation OpLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2483 | bool IsArrow) { |
| 2484 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2485 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2486 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2487 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2488 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2489 | OpLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2490 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2491 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2492 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2493 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2494 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2495 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2496 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2497 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2498 | OpLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2499 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2500 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2501 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2502 | /*TemplateArgs=*/0); |
| 2503 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2504 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2505 | /// \brief Build a new shuffle vector expression. |
| 2506 | /// |
| 2507 | /// By default, performs semantic analysis to build the new expression. |
| 2508 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2509 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2510 | MultiExprArg SubExprs, |
| 2511 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2512 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2513 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2514 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2515 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2516 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2517 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2518 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2519 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2520 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2521 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2522 | SemaRef.Context.BuiltinFnTy, |
| 2523 | VK_RValue, BuiltinLoc); |
| 2524 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2525 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| 2526 | CK_BuiltinFnToFnPtr).take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2527 | |
| 2528 | // Build the CallExpr |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2529 | ExprResult TheCall = SemaRef.Owned( |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2530 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs, |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2531 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2532 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2533 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2535 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2536 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2537 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2538 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2539 | /// \brief Build a new template argument pack expansion. |
| 2540 | /// |
| 2541 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2542 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2543 | /// different behavior. |
| 2544 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2545 | SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2546 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2547 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2548 | case TemplateArgument::Expression: { |
| 2549 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2550 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2551 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2552 | if (Result.isInvalid()) |
| 2553 | return TemplateArgumentLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2554 | |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2555 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2556 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2557 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2558 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2559 | return TemplateArgumentLoc(TemplateArgument( |
| 2560 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2561 | NumExpansions), |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2562 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2563 | Pattern.getTemplateNameLoc(), |
| 2564 | EllipsisLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2565 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2566 | case TemplateArgument::Null: |
| 2567 | case TemplateArgument::Integral: |
| 2568 | case TemplateArgument::Declaration: |
| 2569 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2570 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2571 | case TemplateArgument::NullPtr: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2572 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2573 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2574 | case TemplateArgument::Type: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2575 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2576 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2577 | EllipsisLoc, |
| 2578 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2579 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2580 | Expansion); |
| 2581 | break; |
| 2582 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2583 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2584 | return TemplateArgumentLoc(); |
| 2585 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2586 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2587 | /// \brief Build a new expression pack expansion. |
| 2588 | /// |
| 2589 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2590 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2591 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2592 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2593 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2594 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2595 | } |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2596 | |
| 2597 | /// \brief Build a new atomic operation expression. |
| 2598 | /// |
| 2599 | /// By default, performs semantic analysis to build the new expression. |
| 2600 | /// Subclasses may override this routine to provide different behavior. |
| 2601 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2602 | MultiExprArg SubExprs, |
| 2603 | QualType RetTy, |
| 2604 | AtomicExpr::AtomicOp Op, |
| 2605 | SourceLocation RParenLoc) { |
| 2606 | // Just create the expression; there is not any interesting semantic |
| 2607 | // analysis here because we can't actually build an AtomicExpr until |
| 2608 | // we are sure it is semantically sound. |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2609 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2610 | RParenLoc); |
| 2611 | } |
| 2612 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2613 | private: |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2614 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2615 | QualType ObjectType, |
| 2616 | NamedDecl *FirstQualifierInScope, |
| 2617 | CXXScopeSpec &SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2618 | |
| 2619 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2620 | QualType ObjectType, |
| 2621 | NamedDecl *FirstQualifierInScope, |
| 2622 | CXXScopeSpec &SS); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2623 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2624 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2625 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2626 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2627 | if (!S) |
| 2628 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2629 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2630 | switch (S->getStmtClass()) { |
| 2631 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2632 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2633 | // Transform individual statement nodes |
| 2634 | #define STMT(Node, Parent) \ |
| 2635 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2636 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2637 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2638 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2639 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2640 | // Transform expressions by calling TransformExpr. |
| 2641 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2642 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2643 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2644 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2645 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2646 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2647 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2648 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2649 | |
Richard Smith | 4195637 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2650 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2651 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2654 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2655 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2656 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2657 | template<typename Derived> |
| 2658 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2659 | if (!S) |
| 2660 | return S; |
| 2661 | |
| 2662 | switch (S->getClauseKind()) { |
| 2663 | default: break; |
| 2664 | // Transform individual clause nodes |
| 2665 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2666 | case OMPC_ ## Name : \ |
| 2667 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2668 | #include "clang/Basic/OpenMPKinds.def" |
| 2669 | } |
| 2670 | |
| 2671 | return S; |
| 2672 | } |
| 2673 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2674 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2675 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2676 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2677 | if (!E) |
| 2678 | return SemaRef.Owned(E); |
| 2679 | |
| 2680 | switch (E->getStmtClass()) { |
| 2681 | case Stmt::NoStmtClass: break; |
| 2682 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2683 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2684 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2685 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2686 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2689 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | template<typename Derived> |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2693 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 2694 | bool CXXDirectInit) { |
| 2695 | // Initializers are instantiated like expressions, except that various outer |
| 2696 | // layers are stripped. |
| 2697 | if (!Init) |
| 2698 | return SemaRef.Owned(Init); |
| 2699 | |
| 2700 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2701 | Init = ExprTemp->getSubExpr(); |
| 2702 | |
Richard Smith | 858c2c3 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 2703 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 2704 | Init = MTE->GetTemporaryExpr(); |
| 2705 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2706 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 2707 | Init = Binder->getSubExpr(); |
| 2708 | |
| 2709 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 2710 | Init = ICE->getSubExprAsWritten(); |
| 2711 | |
Richard Smith | 7c3e615 | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 2712 | if (CXXStdInitializerListExpr *ILE = |
| 2713 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| 2714 | return TransformInitializer(ILE->getSubExpr(), CXXDirectInit); |
| 2715 | |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2716 | // If this is not a direct-initializer, we only need to reconstruct |
| 2717 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 2718 | // the initializer is already the right type. |
| 2719 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 2720 | if (!CXXDirectInit && !(Construct && Construct->isListInitialization())) |
| 2721 | return getDerived().TransformExpr(Init); |
| 2722 | |
| 2723 | // Revert value-initialization back to empty parens. |
| 2724 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 2725 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2726 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2727 | Parens.getEnd()); |
| 2728 | } |
| 2729 | |
| 2730 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 2731 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2732 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2733 | SourceLocation()); |
| 2734 | |
| 2735 | // Revert initialization by constructor back to a parenthesized or braced list |
| 2736 | // of expressions. Any other form of initializer can just be reused directly. |
| 2737 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2738 | return getDerived().TransformExpr(Init); |
| 2739 | |
| 2740 | SmallVector<Expr*, 8> NewArgs; |
| 2741 | bool ArgChanged = false; |
| 2742 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 2743 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| 2744 | return ExprError(); |
| 2745 | |
| 2746 | // If this was list initialization, revert to list form. |
| 2747 | if (Construct->isListInitialization()) |
| 2748 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 2749 | Construct->getLocEnd(), |
| 2750 | Construct->getType()); |
| 2751 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2752 | // Build a ParenListExpr to represent anything else. |
| 2753 | SourceRange Parens = Construct->getParenRange(); |
| 2754 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 2755 | Parens.getEnd()); |
| 2756 | } |
| 2757 | |
| 2758 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2759 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2760 | unsigned NumInputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2761 | bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2762 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2763 | bool *ArgChanged) { |
| 2764 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2765 | // If requested, drop call arguments that need to be dropped. |
| 2766 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2767 | if (ArgChanged) |
| 2768 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2769 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2770 | break; |
| 2771 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2772 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2773 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2774 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2775 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2776 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2777 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2778 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2779 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2780 | // Determine whether the set of unexpanded parameter packs can and should |
| 2781 | // be expanded. |
| 2782 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2783 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2784 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 2785 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2786 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2787 | Pattern->getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2788 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2789 | Expand, RetainExpansion, |
| 2790 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2791 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2792 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2793 | if (!Expand) { |
| 2794 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2795 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2796 | // expansion. |
| 2797 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2798 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2799 | if (OutPattern.isInvalid()) |
| 2800 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2801 | |
| 2802 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2803 | Expansion->getEllipsisLoc(), |
| 2804 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2805 | if (Out.isInvalid()) |
| 2806 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2808 | if (ArgChanged) |
| 2809 | *ArgChanged = true; |
| 2810 | Outputs.push_back(Out.get()); |
| 2811 | continue; |
| 2812 | } |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2813 | |
| 2814 | // Record right away that the argument was changed. This needs |
| 2815 | // to happen even if the array expands to nothing. |
| 2816 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2817 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2818 | // The transform has determined that we should perform an elementwise |
| 2819 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2820 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2821 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2822 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2823 | if (Out.isInvalid()) |
| 2824 | return true; |
| 2825 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2826 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2827 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2828 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2829 | if (Out.isInvalid()) |
| 2830 | return true; |
| 2831 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2832 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2833 | Outputs.push_back(Out.get()); |
| 2834 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2835 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2836 | continue; |
| 2837 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2838 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2839 | ExprResult Result = |
| 2840 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 2841 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2842 | if (Result.isInvalid()) |
| 2843 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2844 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2845 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2846 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2847 | |
| 2848 | Outputs.push_back(Result.get()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2849 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2850 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2851 | return false; |
| 2852 | } |
| 2853 | |
| 2854 | template<typename Derived> |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2855 | NestedNameSpecifierLoc |
| 2856 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2857 | NestedNameSpecifierLoc NNS, |
| 2858 | QualType ObjectType, |
| 2859 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2860 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2861 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2862 | Qualifier = Qualifier.getPrefix()) |
| 2863 | Qualifiers.push_back(Qualifier); |
| 2864 | |
| 2865 | CXXScopeSpec SS; |
| 2866 | while (!Qualifiers.empty()) { |
| 2867 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2868 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2869 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2870 | switch (QNNS->getKind()) { |
| 2871 | case NestedNameSpecifier::Identifier: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2872 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2873 | *QNNS->getAsIdentifier(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2874 | Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2875 | Q.getLocalEndLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2876 | ObjectType, false, SS, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2877 | FirstQualifierInScope, false)) |
| 2878 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2879 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2880 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2881 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2882 | case NestedNameSpecifier::Namespace: { |
| 2883 | NamespaceDecl *NS |
| 2884 | = cast_or_null<NamespaceDecl>( |
| 2885 | getDerived().TransformDecl( |
| 2886 | Q.getLocalBeginLoc(), |
| 2887 | QNNS->getAsNamespace())); |
| 2888 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2889 | break; |
| 2890 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2891 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2892 | case NestedNameSpecifier::NamespaceAlias: { |
| 2893 | NamespaceAliasDecl *Alias |
| 2894 | = cast_or_null<NamespaceAliasDecl>( |
| 2895 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2896 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2897 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2898 | Q.getLocalEndLoc()); |
| 2899 | break; |
| 2900 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2901 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2902 | case NestedNameSpecifier::Global: |
| 2903 | // There is no meaningful transformation that one could perform on the |
| 2904 | // global scope. |
| 2905 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2906 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2907 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2908 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2909 | case NestedNameSpecifier::TypeSpec: { |
| 2910 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2911 | FirstQualifierInScope, SS); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2912 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2913 | if (!TL) |
| 2914 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2915 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2916 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2917 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2918 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2919 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2920 | "Can't get cv-qualifiers here"); |
Richard Smith | 95aafb2 | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 2921 | if (TL.getType()->isEnumeralType()) |
| 2922 | SemaRef.Diag(TL.getBeginLoc(), |
| 2923 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2924 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2925 | Q.getLocalEndLoc()); |
| 2926 | break; |
| 2927 | } |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2928 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2929 | // error because a previous error should have already been emitted. |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 2930 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 2931 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2932 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2933 | << TL.getType() << SS.getRange(); |
| 2934 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2935 | return NestedNameSpecifierLoc(); |
| 2936 | } |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2937 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2938 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2939 | // 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] | 2940 | FirstQualifierInScope = 0; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2941 | ObjectType = QualType(); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2942 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2943 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2944 | // 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] | 2945 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2946 | !getDerived().AlwaysRebuild()) |
| 2947 | return NNS; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2948 | |
| 2949 | // If we can re-use the source-location data from the original |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2950 | // nested-name-specifier, do so. |
| 2951 | if (SS.location_size() == NNS.getDataLength() && |
| 2952 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2953 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2954 | |
| 2955 | // Allocate new nested-name-specifier location information. |
| 2956 | return SS.getWithLocInContext(SemaRef.Context); |
| 2957 | } |
| 2958 | |
| 2959 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2960 | DeclarationNameInfo |
| 2961 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2962 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2963 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2964 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2965 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2966 | |
| 2967 | switch (Name.getNameKind()) { |
| 2968 | case DeclarationName::Identifier: |
| 2969 | case DeclarationName::ObjCZeroArgSelector: |
| 2970 | case DeclarationName::ObjCOneArgSelector: |
| 2971 | case DeclarationName::ObjCMultiArgSelector: |
| 2972 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2973 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2974 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2975 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2976 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2977 | case DeclarationName::CXXConstructorName: |
| 2978 | case DeclarationName::CXXDestructorName: |
| 2979 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2980 | TypeSourceInfo *NewTInfo; |
| 2981 | CanQualType NewCanTy; |
| 2982 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2983 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2984 | if (!NewTInfo) |
| 2985 | return DeclarationNameInfo(); |
| 2986 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2987 | } |
| 2988 | else { |
| 2989 | NewTInfo = 0; |
| 2990 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2991 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2992 | if (NewT.isNull()) |
| 2993 | return DeclarationNameInfo(); |
| 2994 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2995 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2996 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2997 | DeclarationName NewName |
| 2998 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2999 | NewCanTy); |
| 3000 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3001 | NewNameInfo.setName(NewName); |
| 3002 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3003 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3004 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3007 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3012 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3013 | TemplateName Name, |
| 3014 | SourceLocation NameLoc, |
| 3015 | QualType ObjectType, |
| 3016 | NamedDecl *FirstQualifierInScope) { |
| 3017 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3018 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3019 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3020 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3021 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3022 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3023 | Template)); |
| 3024 | if (!TransTemplate) |
| 3025 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3026 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3027 | if (!getDerived().AlwaysRebuild() && |
| 3028 | SS.getScopeRep() == QTN->getQualifier() && |
| 3029 | TransTemplate == Template) |
| 3030 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3031 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3032 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3033 | TransTemplate); |
| 3034 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3035 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3036 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3037 | if (SS.getScopeRep()) { |
| 3038 | // These apply to the scope specifier, not the template. |
| 3039 | ObjectType = QualType(); |
| 3040 | FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3043 | if (!getDerived().AlwaysRebuild() && |
| 3044 | SS.getScopeRep() == DTN->getQualifier() && |
| 3045 | ObjectType.isNull()) |
| 3046 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3047 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3048 | if (DTN->isIdentifier()) { |
| 3049 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3050 | *DTN->getIdentifier(), |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3051 | NameLoc, |
| 3052 | ObjectType, |
| 3053 | FirstQualifierInScope); |
| 3054 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3055 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3056 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3057 | ObjectType); |
| 3058 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3059 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3060 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3061 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3062 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3063 | Template)); |
| 3064 | if (!TransTemplate) |
| 3065 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3066 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3067 | if (!getDerived().AlwaysRebuild() && |
| 3068 | TransTemplate == Template) |
| 3069 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3070 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3071 | return TemplateName(TransTemplate); |
| 3072 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3073 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3074 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3075 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3076 | TemplateTemplateParmDecl *TransParam |
| 3077 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3078 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3079 | if (!TransParam) |
| 3080 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3081 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3082 | if (!getDerived().AlwaysRebuild() && |
| 3083 | TransParam == SubstPack->getParameterPack()) |
| 3084 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3085 | |
| 3086 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3087 | SubstPack->getArgumentPack()); |
| 3088 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3089 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3090 | // These should be getting filtered out before they reach the AST. |
| 3091 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3095 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3096 | const TemplateArgument &Arg, |
| 3097 | TemplateArgumentLoc &Output) { |
| 3098 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3099 | switch (Arg.getKind()) { |
| 3100 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3101 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3102 | break; |
| 3103 | |
| 3104 | case TemplateArgument::Type: |
| 3105 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3106 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3107 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3108 | break; |
| 3109 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3110 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3111 | case TemplateArgument::TemplateExpansion: { |
| 3112 | NestedNameSpecifierLocBuilder Builder; |
| 3113 | TemplateName Template = Arg.getAsTemplate(); |
| 3114 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3115 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3116 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3117 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3118 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3119 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3120 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3121 | Builder.getWithLocInContext(SemaRef.Context), |
| 3122 | Loc); |
| 3123 | else |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3124 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3125 | Builder.getWithLocInContext(SemaRef.Context), |
| 3126 | Loc, Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3127 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3128 | break; |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3129 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3130 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3131 | case TemplateArgument::Expression: |
| 3132 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3133 | break; |
| 3134 | |
| 3135 | case TemplateArgument::Declaration: |
| 3136 | case TemplateArgument::Integral: |
| 3137 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3138 | case TemplateArgument::NullPtr: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3139 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3140 | break; |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | template<typename Derived> |
| 3145 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3146 | const TemplateArgumentLoc &Input, |
| 3147 | TemplateArgumentLoc &Output) { |
| 3148 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3149 | switch (Arg.getKind()) { |
| 3150 | case TemplateArgument::Null: |
| 3151 | case TemplateArgument::Integral: |
Eli Friedman | 511e3ae | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3152 | case TemplateArgument::Pack: |
| 3153 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3154 | case TemplateArgument::NullPtr: |
| 3155 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3156 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3157 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3158 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3159 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3160 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3161 | |
| 3162 | DI = getDerived().TransformType(DI); |
| 3163 | if (!DI) return true; |
| 3164 | |
| 3165 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3166 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3167 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3168 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3169 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3170 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3171 | if (QualifierLoc) { |
| 3172 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3173 | if (!QualifierLoc) |
| 3174 | return true; |
| 3175 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3176 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3177 | CXXScopeSpec SS; |
| 3178 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3179 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3180 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3181 | Input.getTemplateNameLoc()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3182 | if (Template.isNull()) |
| 3183 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3184 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3185 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3186 | Input.getTemplateNameLoc()); |
| 3187 | return false; |
| 3188 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3189 | |
| 3190 | case TemplateArgument::TemplateExpansion: |
| 3191 | llvm_unreachable("Caller should expand pack expansions"); |
| 3192 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3193 | case TemplateArgument::Expression: { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3194 | // Template argument expressions are constant expressions. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3195 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3196 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3198 | Expr *InputExpr = Input.getSourceExpression(); |
| 3199 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3200 | |
Chris Lattner | 223de24 | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3201 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3202 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3203 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3204 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3205 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3206 | } |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3207 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3208 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3209 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3210 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3213 | /// \brief Iterator adaptor that invents template argument location information |
| 3214 | /// for each of the template arguments in its underlying iterator. |
| 3215 | template<typename Derived, typename InputIterator> |
| 3216 | class TemplateArgumentLocInventIterator { |
| 3217 | TreeTransform<Derived> &Self; |
| 3218 | InputIterator Iter; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3219 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3220 | public: |
| 3221 | typedef TemplateArgumentLoc value_type; |
| 3222 | typedef TemplateArgumentLoc reference; |
| 3223 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3224 | difference_type; |
| 3225 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3226 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3227 | class pointer { |
| 3228 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3229 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3230 | public: |
| 3231 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3232 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3233 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3234 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3235 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3236 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3237 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3238 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3239 | InputIterator Iter) |
| 3240 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3241 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3242 | TemplateArgumentLocInventIterator &operator++() { |
| 3243 | ++Iter; |
| 3244 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3245 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3246 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3247 | TemplateArgumentLocInventIterator operator++(int) { |
| 3248 | TemplateArgumentLocInventIterator Old(*this); |
| 3249 | ++(*this); |
| 3250 | return Old; |
| 3251 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3252 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3253 | reference operator*() const { |
| 3254 | TemplateArgumentLoc Result; |
| 3255 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3256 | return Result; |
| 3257 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3258 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3259 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3260 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3261 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3262 | const TemplateArgumentLocInventIterator &Y) { |
| 3263 | return X.Iter == Y.Iter; |
| 3264 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3265 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3266 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3267 | const TemplateArgumentLocInventIterator &Y) { |
| 3268 | return X.Iter != Y.Iter; |
| 3269 | } |
| 3270 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3271 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3272 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3273 | template<typename InputIterator> |
| 3274 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3275 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3276 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3277 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3278 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3279 | TemplateArgumentLoc In = *First; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3280 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3281 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3282 | // Unpack argument packs, which we translate them into separate |
| 3283 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3284 | // FIXME: We could do much better if we could guarantee that the |
| 3285 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3286 | // all of the template arguments in the argument pack. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3287 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3288 | TemplateArgument::pack_iterator> |
| 3289 | PackLocIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3290 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3291 | In.getArgument().pack_begin()), |
| 3292 | PackLocIterator(*this, |
| 3293 | In.getArgument().pack_end()), |
| 3294 | Outputs)) |
| 3295 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3296 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3297 | continue; |
| 3298 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3299 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3300 | if (In.getArgument().isPackExpansion()) { |
| 3301 | // We have a pack expansion, for which we will be substituting into |
| 3302 | // the pattern. |
| 3303 | SourceLocation Ellipsis; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3304 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3305 | TemplateArgumentLoc Pattern |
Eli Friedman | 850cf51 | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3306 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3307 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3308 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3309 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3310 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3311 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3312 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3313 | // Determine whether the set of unexpanded parameter packs can and should |
| 3314 | // be expanded. |
| 3315 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3316 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3317 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3318 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3319 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3320 | Unexpanded, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3321 | Expand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3322 | RetainExpansion, |
| 3323 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3324 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3325 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3326 | if (!Expand) { |
| 3327 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3328 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3329 | // expansion. |
| 3330 | TemplateArgumentLoc OutPattern; |
| 3331 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3332 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3333 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3335 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3336 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3337 | if (Out.getArgument().isNull()) |
| 3338 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3339 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3340 | Outputs.addArgument(Out); |
| 3341 | continue; |
| 3342 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3343 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3344 | // The transform has determined that we should perform an elementwise |
| 3345 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3346 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3347 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3348 | |
| 3349 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3350 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3351 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3352 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3353 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3354 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3355 | if (Out.getArgument().isNull()) |
| 3356 | return true; |
| 3357 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3358 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3359 | Outputs.addArgument(Out); |
| 3360 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3361 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3362 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3363 | // forgetting the partially-substituted parameter pack. |
| 3364 | if (RetainExpansion) { |
| 3365 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3366 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3367 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3368 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3369 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3370 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3371 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3372 | if (Out.getArgument().isNull()) |
| 3373 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3374 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3375 | Outputs.addArgument(Out); |
| 3376 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3377 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3378 | continue; |
| 3379 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3380 | |
| 3381 | // The simple case: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3382 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3383 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3384 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3385 | Outputs.addArgument(Out); |
| 3386 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3387 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3388 | return false; |
| 3389 | |
| 3390 | } |
| 3391 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3392 | //===----------------------------------------------------------------------===// |
| 3393 | // Type transformation |
| 3394 | //===----------------------------------------------------------------------===// |
| 3395 | |
| 3396 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3397 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3398 | if (getDerived().AlreadyTransformed(T)) |
| 3399 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3400 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3401 | // Temporary workaround. All of these transformations should |
| 3402 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3403 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3404 | getDerived().getBaseLocation()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3405 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3406 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3407 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3408 | if (!NewDI) |
| 3409 | return QualType(); |
| 3410 | |
| 3411 | return NewDI->getType(); |
| 3412 | } |
| 3413 | |
| 3414 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3415 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3416 | // Refine the base location to the type's location. |
| 3417 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3418 | getDerived().getBaseEntity()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3419 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3420 | return DI; |
| 3421 | |
| 3422 | TypeLocBuilder TLB; |
| 3423 | |
| 3424 | TypeLoc TL = DI->getTypeLoc(); |
| 3425 | TLB.reserve(TL.getFullDataSize()); |
| 3426 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3427 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3428 | if (Result.isNull()) |
| 3429 | return 0; |
| 3430 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3431 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | template<typename Derived> |
| 3435 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3436 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3437 | switch (T.getTypeLocClass()) { |
| 3438 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3439 | #define TYPELOC(CLASS, PARENT) \ |
| 3440 | case TypeLoc::CLASS: \ |
| 3441 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3442 | T.castAs<CLASS##TypeLoc>()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3443 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3444 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3445 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3446 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3450 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3451 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3452 | /// types). This is the right thing for template instantiation, but |
| 3453 | /// probably not for other clients. |
| 3454 | template<typename Derived> |
| 3455 | QualType |
| 3456 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3457 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3458 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3459 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3460 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3461 | if (Result.isNull()) |
| 3462 | return QualType(); |
| 3463 | |
| 3464 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3465 | // FIXME: this is the right thing for template instantiation, but |
| 3466 | // probably not for other clients. |
| 3467 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3468 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3470 | // 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] | 3471 | // resulting type. |
| 3472 | if (Quals.hasObjCLifetime()) { |
| 3473 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3474 | Quals.removeObjCLifetime(); |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3475 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3476 | // Objective-C ARC: |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3477 | // A lifetime qualifier applied to a substituted template parameter |
| 3478 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3479 | const AutoType *AutoTy; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3480 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3481 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3482 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3483 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3484 | Qs.removeObjCLifetime(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3485 | Replacement |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3486 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3487 | Qs); |
| 3488 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3489 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3490 | Replacement); |
| 3491 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3492 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3493 | // 'auto' types behave the same way as template parameters. |
| 3494 | QualType Deduced = AutoTy->getDeducedType(); |
| 3495 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3496 | Qs.removeObjCLifetime(); |
| 3497 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3498 | Qs); |
Faisal Vali | ecb5819 | 2013-08-22 01:49:11 +0000 | [diff] [blame] | 3499 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(), |
| 3500 | AutoTy->isDependentType(), |
| 3501 | AutoTy->containsUnexpandedParameterPack()); |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3502 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3503 | } else { |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3504 | // Otherwise, complain about the addition of a qualifier to an |
| 3505 | // already-qualified type. |
Eli Friedman | 44ee0a7 | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3506 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3507 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3508 | << Result << R; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3509 | |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3510 | Quals.removeObjCLifetime(); |
| 3511 | } |
| 3512 | } |
| 3513 | } |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3514 | if (!Quals.empty()) { |
| 3515 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | 9807a2e | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3516 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3517 | if (Result.hasLocalQualifiers()) |
| 3518 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3519 | // No location information to preserve. |
| 3520 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3521 | |
| 3522 | return Result; |
| 3523 | } |
| 3524 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3525 | template<typename Derived> |
| 3526 | TypeLoc |
| 3527 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3528 | QualType ObjectType, |
| 3529 | NamedDecl *UnqualLookup, |
| 3530 | CXXScopeSpec &SS) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3531 | QualType T = TL.getType(); |
| 3532 | if (getDerived().AlreadyTransformed(T)) |
| 3533 | return TL; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3534 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3535 | TypeLocBuilder TLB; |
| 3536 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3537 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3538 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3539 | TemplateSpecializationTypeLoc SpecTL = |
| 3540 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3542 | TemplateName Template = |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3543 | getDerived().TransformTemplateName(SS, |
| 3544 | SpecTL.getTypePtr()->getTemplateName(), |
| 3545 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3546 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3547 | if (Template.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3548 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3549 | |
| 3550 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3551 | Template); |
| 3552 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3553 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3554 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3555 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3556 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3557 | = getDerived().RebuildTemplateName(SS, |
| 3558 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3559 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3560 | ObjectType, UnqualLookup); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3561 | if (Template.isNull()) |
| 3562 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3563 | |
| 3564 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3565 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3566 | Template, |
| 3567 | SS); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3568 | } else { |
| 3569 | // Nothing special needs to be done for these. |
| 3570 | Result = getDerived().TransformType(TLB, TL); |
| 3571 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3572 | |
| 3573 | if (Result.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3574 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3575 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3576 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3577 | } |
| 3578 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3579 | template<typename Derived> |
| 3580 | TypeSourceInfo * |
| 3581 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3582 | QualType ObjectType, |
| 3583 | NamedDecl *UnqualLookup, |
| 3584 | CXXScopeSpec &SS) { |
| 3585 | // FIXME: Painfully copy-paste from the above! |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3586 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3587 | QualType T = TSInfo->getType(); |
| 3588 | if (getDerived().AlreadyTransformed(T)) |
| 3589 | return TSInfo; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3590 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3591 | TypeLocBuilder TLB; |
| 3592 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3593 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3594 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3595 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3596 | TemplateSpecializationTypeLoc SpecTL = |
| 3597 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3598 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3599 | TemplateName Template |
| 3600 | = getDerived().TransformTemplateName(SS, |
| 3601 | SpecTL.getTypePtr()->getTemplateName(), |
| 3602 | SpecTL.getTemplateNameLoc(), |
| 3603 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3604 | if (Template.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3605 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3606 | |
| 3607 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3608 | Template); |
| 3609 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3610 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3611 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3612 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3613 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3614 | = getDerived().RebuildTemplateName(SS, |
| 3615 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3616 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3617 | ObjectType, UnqualLookup); |
| 3618 | if (Template.isNull()) |
| 3619 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3620 | |
| 3621 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3622 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3623 | Template, |
| 3624 | SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3625 | } else { |
| 3626 | // Nothing special needs to be done for these. |
| 3627 | Result = getDerived().TransformType(TLB, TL); |
| 3628 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3629 | |
| 3630 | if (Result.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3631 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3632 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3633 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3634 | } |
| 3635 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3636 | template <class TyLoc> static inline |
| 3637 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3638 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3639 | NewT.setNameLoc(T.getNameLoc()); |
| 3640 | return T.getType(); |
| 3641 | } |
| 3642 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3643 | template<typename Derived> |
| 3644 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3645 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3646 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3647 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3648 | if (T.needsExtraLocalData()) |
| 3649 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3650 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3651 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3652 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3653 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3654 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3655 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3656 | // FIXME: recurse? |
| 3657 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3658 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3660 | template<typename Derived> |
Reid Kleckner | 12df246 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 3661 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 3662 | DecayedTypeLoc TL) { |
| 3663 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3664 | if (OriginalType.isNull()) |
| 3665 | return QualType(); |
| 3666 | |
| 3667 | QualType Result = TL.getType(); |
| 3668 | if (getDerived().AlwaysRebuild() || |
| 3669 | OriginalType != TL.getOriginalLoc().getType()) |
| 3670 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 3671 | TLB.push<DecayedTypeLoc>(Result); |
| 3672 | // Nothing to set for DecayedTypeLoc. |
| 3673 | return Result; |
| 3674 | } |
| 3675 | |
| 3676 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3677 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3678 | PointerTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3679 | QualType PointeeType |
| 3680 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3681 | if (PointeeType.isNull()) |
| 3682 | return QualType(); |
| 3683 | |
| 3684 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3685 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3686 | // A dependent pointer type 'T *' has is being transformed such |
| 3687 | // that an Objective-C class type is being replaced for 'T'. The |
| 3688 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3689 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3690 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3691 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3692 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3693 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3694 | return Result; |
| 3695 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3696 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3697 | if (getDerived().AlwaysRebuild() || |
| 3698 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3699 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3700 | if (Result.isNull()) |
| 3701 | return QualType(); |
| 3702 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3703 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3704 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3705 | // pointing to. |
| 3706 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3707 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3708 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3709 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3710 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3711 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | |
| 3713 | template<typename Derived> |
| 3714 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3715 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3716 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3717 | QualType PointeeType |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3718 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3719 | if (PointeeType.isNull()) |
| 3720 | return QualType(); |
| 3721 | |
| 3722 | QualType Result = TL.getType(); |
| 3723 | if (getDerived().AlwaysRebuild() || |
| 3724 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3725 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3726 | TL.getSigilLoc()); |
| 3727 | if (Result.isNull()) |
| 3728 | return QualType(); |
| 3729 | } |
| 3730 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3731 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3732 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3733 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3734 | } |
| 3735 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3736 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3737 | /// don't care whether the type itself is an l-value type or an r-value |
| 3738 | /// type; we only care if the type was *written* as an l-value type |
| 3739 | /// or an r-value type. |
| 3740 | template<typename Derived> |
| 3741 | QualType |
| 3742 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3743 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3744 | const ReferenceType *T = TL.getTypePtr(); |
| 3745 | |
| 3746 | // Note that this works with the pointee-as-written. |
| 3747 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3748 | if (PointeeType.isNull()) |
| 3749 | return QualType(); |
| 3750 | |
| 3751 | QualType Result = TL.getType(); |
| 3752 | if (getDerived().AlwaysRebuild() || |
| 3753 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3754 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3755 | T->isSpelledAsLValue(), |
| 3756 | TL.getSigilLoc()); |
| 3757 | if (Result.isNull()) |
| 3758 | return QualType(); |
| 3759 | } |
| 3760 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3761 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3762 | // referring to. |
| 3763 | TLB.TypeWasModifiedSafely( |
| 3764 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3765 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3766 | // r-value references can be rebuilt as l-value references. |
| 3767 | ReferenceTypeLoc NewTL; |
| 3768 | if (isa<LValueReferenceType>(Result)) |
| 3769 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3770 | else |
| 3771 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3772 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3773 | |
| 3774 | return Result; |
| 3775 | } |
| 3776 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | template<typename Derived> |
| 3778 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3779 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3780 | LValueReferenceTypeLoc TL) { |
| 3781 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3784 | template<typename Derived> |
| 3785 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3786 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3787 | RValueReferenceTypeLoc TL) { |
| 3788 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3789 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3790 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3791 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3793 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3794 | MemberPointerTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3795 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3796 | if (PointeeType.isNull()) |
| 3797 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3798 | |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3799 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3800 | TypeSourceInfo* NewClsTInfo = 0; |
| 3801 | if (OldClsTInfo) { |
| 3802 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3803 | if (!NewClsTInfo) |
| 3804 | return QualType(); |
| 3805 | } |
| 3806 | |
| 3807 | const MemberPointerType *T = TL.getTypePtr(); |
| 3808 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3809 | QualType NewClsType; |
| 3810 | if (NewClsTInfo) |
| 3811 | NewClsType = NewClsTInfo->getType(); |
| 3812 | else { |
| 3813 | NewClsType = getDerived().TransformType(OldClsType); |
| 3814 | if (NewClsType.isNull()) |
| 3815 | return QualType(); |
| 3816 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3817 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3818 | QualType Result = TL.getType(); |
| 3819 | if (getDerived().AlwaysRebuild() || |
| 3820 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3821 | NewClsType != OldClsType) { |
| 3822 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3823 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3824 | if (Result.isNull()) |
| 3825 | return QualType(); |
| 3826 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3827 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3828 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3829 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3830 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3831 | |
| 3832 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3835 | template<typename Derived> |
| 3836 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3837 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3838 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3839 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3840 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3841 | if (ElementType.isNull()) |
| 3842 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3843 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3844 | QualType Result = TL.getType(); |
| 3845 | if (getDerived().AlwaysRebuild() || |
| 3846 | ElementType != T->getElementType()) { |
| 3847 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3848 | T->getSizeModifier(), |
| 3849 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3850 | T->getIndexTypeCVRQualifiers(), |
| 3851 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3852 | if (Result.isNull()) |
| 3853 | return QualType(); |
| 3854 | } |
Eli Friedman | 457a377 | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 3855 | |
| 3856 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 3857 | // a ConstantArrayType is allowed to have an element type which is a |
| 3858 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 3859 | // types have the same location layout. |
| 3860 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3861 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3862 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3863 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3864 | Expr *Size = TL.getSizeExpr(); |
| 3865 | if (Size) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3866 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3867 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3868 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3869 | Size = SemaRef.ActOnConstantExpression(Size).take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3870 | } |
| 3871 | NewTL.setSizeExpr(Size); |
| 3872 | |
| 3873 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3874 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3875 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3876 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3877 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3878 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3879 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3880 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3881 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3882 | if (ElementType.isNull()) |
| 3883 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3884 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3885 | QualType Result = TL.getType(); |
| 3886 | if (getDerived().AlwaysRebuild() || |
| 3887 | ElementType != T->getElementType()) { |
| 3888 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3889 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3890 | T->getIndexTypeCVRQualifiers(), |
| 3891 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3892 | if (Result.isNull()) |
| 3893 | return QualType(); |
| 3894 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3895 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3896 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3897 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3898 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3899 | NewTL.setSizeExpr(0); |
| 3900 | |
| 3901 | return Result; |
| 3902 | } |
| 3903 | |
| 3904 | template<typename Derived> |
| 3905 | QualType |
| 3906 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3907 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3908 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3909 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3910 | if (ElementType.isNull()) |
| 3911 | return QualType(); |
| 3912 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3913 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3914 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3915 | if (SizeResult.isInvalid()) |
| 3916 | return QualType(); |
| 3917 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3918 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3919 | |
| 3920 | QualType Result = TL.getType(); |
| 3921 | if (getDerived().AlwaysRebuild() || |
| 3922 | ElementType != T->getElementType() || |
| 3923 | Size != T->getSizeExpr()) { |
| 3924 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3925 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3926 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3927 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3928 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3929 | if (Result.isNull()) |
| 3930 | return QualType(); |
| 3931 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3932 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3933 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3934 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3935 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3936 | NewTL.setSizeExpr(Size); |
| 3937 | |
| 3938 | return Result; |
| 3939 | } |
| 3940 | |
| 3941 | template<typename Derived> |
| 3942 | QualType |
| 3943 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3944 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3945 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3946 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3947 | if (ElementType.isNull()) |
| 3948 | return QualType(); |
| 3949 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3950 | // Array bounds are constant expressions. |
| 3951 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3952 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3953 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3954 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3955 | Expr *origSize = TL.getSizeExpr(); |
| 3956 | if (!origSize) origSize = T->getSizeExpr(); |
| 3957 | |
| 3958 | ExprResult sizeResult |
| 3959 | = getDerived().TransformExpr(origSize); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3960 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3961 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3962 | return QualType(); |
| 3963 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3964 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3965 | |
| 3966 | QualType Result = TL.getType(); |
| 3967 | if (getDerived().AlwaysRebuild() || |
| 3968 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3969 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3970 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3971 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3972 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3973 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3974 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3975 | if (Result.isNull()) |
| 3976 | return QualType(); |
| 3977 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3978 | |
| 3979 | // We might have any sort of array type now, but fortunately they |
| 3980 | // all have the same location layout. |
| 3981 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3982 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3983 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3984 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3985 | |
| 3986 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3987 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | |
| 3989 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3990 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3991 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3992 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3993 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3994 | |
| 3995 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3996 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3997 | if (ElementType.isNull()) |
| 3998 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3999 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4000 | // Vector sizes are constant expressions. |
| 4001 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4002 | Sema::ConstantEvaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4003 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4004 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4005 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4006 | if (Size.isInvalid()) |
| 4007 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4008 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4009 | QualType Result = TL.getType(); |
| 4010 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4011 | ElementType != T->getElementType() || |
| 4012 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4013 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4014 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4015 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4016 | if (Result.isNull()) |
| 4017 | return QualType(); |
| 4018 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4019 | |
| 4020 | // Result might be dependent or not. |
| 4021 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4022 | DependentSizedExtVectorTypeLoc NewTL |
| 4023 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4024 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4025 | } else { |
| 4026 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4027 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4028 | } |
| 4029 | |
| 4030 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4031 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
| 4033 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4034 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4035 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4036 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4037 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4038 | if (ElementType.isNull()) |
| 4039 | return QualType(); |
| 4040 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4041 | QualType Result = TL.getType(); |
| 4042 | if (getDerived().AlwaysRebuild() || |
| 4043 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4044 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4045 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4046 | if (Result.isNull()) |
| 4047 | return QualType(); |
| 4048 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4049 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4050 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4051 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4052 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4053 | return Result; |
| 4054 | } |
| 4055 | |
| 4056 | template<typename Derived> |
| 4057 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4058 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4059 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4060 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4061 | if (ElementType.isNull()) |
| 4062 | return QualType(); |
| 4063 | |
| 4064 | QualType Result = TL.getType(); |
| 4065 | if (getDerived().AlwaysRebuild() || |
| 4066 | ElementType != T->getElementType()) { |
| 4067 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4068 | T->getNumElements(), |
| 4069 | /*FIXME*/ SourceLocation()); |
| 4070 | if (Result.isNull()) |
| 4071 | return QualType(); |
| 4072 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4073 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4074 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4075 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4076 | |
| 4077 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4078 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4079 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4080 | template <typename Derived> |
| 4081 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4082 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4083 | bool ExpectParameterPack) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4084 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4085 | TypeSourceInfo *NewDI = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4086 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4087 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4088 | // 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] | 4089 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4090 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4091 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4092 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4093 | TypeLocBuilder TLB; |
| 4094 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4095 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4096 | |
| 4097 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4098 | OldExpansionTL.getPatternLoc()); |
| 4099 | if (Result.isNull()) |
| 4100 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4101 | |
| 4102 | Result = RebuildPackExpansionType(Result, |
| 4103 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4104 | OldExpansionTL.getEllipsisLoc(), |
| 4105 | NumExpansions); |
| 4106 | if (Result.isNull()) |
| 4107 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4108 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4109 | PackExpansionTypeLoc NewExpansionTL |
| 4110 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4111 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4112 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4113 | } else |
| 4114 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4115 | if (!NewDI) |
| 4116 | return 0; |
| 4117 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4118 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4119 | return OldParm; |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4120 | |
| 4121 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4122 | OldParm->getDeclContext(), |
| 4123 | OldParm->getInnerLocStart(), |
| 4124 | OldParm->getLocation(), |
| 4125 | OldParm->getIdentifier(), |
| 4126 | NewDI->getType(), |
| 4127 | NewDI, |
| 4128 | OldParm->getStorageClass(), |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4129 | /* DefArg */ NULL); |
| 4130 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4131 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4132 | return newParm; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | template<typename Derived> |
| 4136 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4137 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4138 | ParmVarDecl **Params, unsigned NumParams, |
| 4139 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4140 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4141 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4142 | int indexAdjustment = 0; |
| 4143 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4144 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4145 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4146 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4147 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4148 | Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4149 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4150 | if (OldParm->isParameterPack()) { |
| 4151 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4152 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4154 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4155 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4156 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4157 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4158 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4159 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4160 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4161 | // Determine whether we should expand the parameter packs. |
| 4162 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4163 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4164 | Optional<unsigned> OrigNumExpansions = |
| 4165 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4166 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4167 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4168 | Pattern.getSourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4169 | Unexpanded, |
| 4170 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4171 | RetainExpansion, |
| 4172 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4173 | return true; |
| 4174 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4175 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4176 | if (ShouldExpand) { |
| 4177 | // Expand the function parameter pack into multiple, separate |
| 4178 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4179 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4180 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4181 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4182 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4183 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4184 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4185 | OrigNumExpansions, |
| 4186 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4187 | if (!NewParm) |
| 4188 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4189 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4190 | OutParamTypes.push_back(NewParm->getType()); |
| 4191 | if (PVars) |
| 4192 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4193 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4194 | |
| 4195 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4196 | // forgetting the partially-substituted parameter pack. |
| 4197 | if (RetainExpansion) { |
| 4198 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4199 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4200 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4201 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4202 | OrigNumExpansions, |
| 4203 | /*ExpectParameterPack=*/false); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4204 | if (!NewParm) |
| 4205 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4206 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4207 | OutParamTypes.push_back(NewParm->getType()); |
| 4208 | if (PVars) |
| 4209 | PVars->push_back(NewParm); |
| 4210 | } |
| 4211 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4212 | // The next parameter should have the same adjustment as the |
| 4213 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4214 | // on every push. Also, if we push nothing, the adjustment should |
| 4215 | // go down by one. |
| 4216 | indexAdjustment--; |
| 4217 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4218 | // We're done with the pack expansion. |
| 4219 | continue; |
| 4220 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4221 | |
| 4222 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4223 | // expansion. |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4224 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4225 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4226 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4227 | NumExpansions, |
| 4228 | /*ExpectParameterPack=*/true); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4229 | } else { |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4230 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4231 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4232 | } |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4233 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4234 | if (!NewParm) |
| 4235 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4236 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4237 | OutParamTypes.push_back(NewParm->getType()); |
| 4238 | if (PVars) |
| 4239 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4240 | continue; |
| 4241 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4242 | |
| 4243 | // Deal with the possibility that we don't have a parameter |
| 4244 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4245 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4246 | bool IsPackExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4247 | Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4248 | QualType NewType; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4249 | if (const PackExpansionType *Expansion |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4250 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4251 | // We have a function parameter pack that may need to be expanded. |
| 4252 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4253 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4254 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4255 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4256 | // Determine whether we should expand the parameter packs. |
| 4257 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4258 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4259 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4260 | Unexpanded, |
| 4261 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4262 | RetainExpansion, |
| 4263 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4264 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4265 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4266 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4267 | if (ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4268 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4269 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4270 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4271 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4272 | QualType NewType = getDerived().TransformType(Pattern); |
| 4273 | if (NewType.isNull()) |
| 4274 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4275 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4276 | OutParamTypes.push_back(NewType); |
| 4277 | if (PVars) |
| 4278 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4279 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4280 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4281 | // We're done with the pack expansion. |
| 4282 | continue; |
| 4283 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4284 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4285 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4286 | // forgetting the partially-substituted parameter pack. |
| 4287 | if (RetainExpansion) { |
| 4288 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4289 | QualType NewType = getDerived().TransformType(Pattern); |
| 4290 | if (NewType.isNull()) |
| 4291 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4292 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4293 | OutParamTypes.push_back(NewType); |
| 4294 | if (PVars) |
| 4295 | PVars->push_back(0); |
| 4296 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4297 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4298 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4299 | // expansion. |
| 4300 | OldType = Expansion->getPattern(); |
| 4301 | IsPackExpansion = true; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4302 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4303 | NewType = getDerived().TransformType(OldType); |
| 4304 | } else { |
| 4305 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4306 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4307 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4308 | if (NewType.isNull()) |
| 4309 | return true; |
| 4310 | |
| 4311 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4312 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4313 | NumExpansions); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4314 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4315 | OutParamTypes.push_back(NewType); |
| 4316 | if (PVars) |
| 4317 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4318 | } |
| 4319 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4320 | #ifndef NDEBUG |
| 4321 | if (PVars) { |
| 4322 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4323 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4324 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4325 | } |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4326 | #endif |
| 4327 | |
| 4328 | return false; |
| 4329 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4330 | |
| 4331 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4332 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4333 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4334 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4335 | return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); |
| 4336 | } |
| 4337 | |
| 4338 | template<typename Derived> |
| 4339 | QualType |
| 4340 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4341 | FunctionProtoTypeLoc TL, |
| 4342 | CXXRecordDecl *ThisContext, |
| 4343 | unsigned ThisTypeQuals) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4344 | // Transform the parameters and return type. |
| 4345 | // |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4346 | // 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] | 4347 | // When the function has a trailing return type, we instantiate the |
| 4348 | // parameters before the return type, since the return type can then refer |
| 4349 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4350 | // |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4351 | SmallVector<QualType, 4> ParamTypes; |
| 4352 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4353 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4354 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4355 | QualType ResultType; |
| 4356 | |
Richard Smith | 9fbf327 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4357 | if (T->hasTrailingReturn()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4358 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4359 | TL.getParmArray(), |
| 4360 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4361 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4362 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4363 | return QualType(); |
| 4364 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4365 | { |
| 4366 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4367 | // If a declaration declares a member function or member function |
| 4368 | // 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] | 4369 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4370 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4371 | // declarator. |
| 4372 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4373 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4374 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4375 | if (ResultType.isNull()) |
| 4376 | return QualType(); |
| 4377 | } |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4378 | } |
| 4379 | else { |
| 4380 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4381 | if (ResultType.isNull()) |
| 4382 | return QualType(); |
| 4383 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4384 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4385 | TL.getParmArray(), |
| 4386 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4387 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4388 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4389 | return QualType(); |
| 4390 | } |
| 4391 | |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4392 | // FIXME: Need to transform the exception-specification too. |
| 4393 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4394 | QualType Result = TL.getType(); |
| 4395 | if (getDerived().AlwaysRebuild() || |
| 4396 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4397 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4398 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 4399 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 4400 | T->getExtProtoInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4401 | if (Result.isNull()) |
| 4402 | return QualType(); |
| 4403 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4404 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4405 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4406 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4407 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4408 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4409 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4410 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4411 | NewTL.setArg(i, ParamDecls[i]); |
| 4412 | |
| 4413 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4414 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4416 | template<typename Derived> |
| 4417 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4418 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4419 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4420 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4421 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4422 | if (ResultType.isNull()) |
| 4423 | return QualType(); |
| 4424 | |
| 4425 | QualType Result = TL.getType(); |
| 4426 | if (getDerived().AlwaysRebuild() || |
| 4427 | ResultType != T->getResultType()) |
| 4428 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4429 | |
| 4430 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4431 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4432 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4433 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4434 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4435 | |
| 4436 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4437 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4438 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4439 | template<typename Derived> QualType |
| 4440 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4441 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4442 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4443 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4444 | if (!D) |
| 4445 | return QualType(); |
| 4446 | |
| 4447 | QualType Result = TL.getType(); |
| 4448 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4449 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4450 | if (Result.isNull()) |
| 4451 | return QualType(); |
| 4452 | } |
| 4453 | |
| 4454 | // We might get an arbitrary type spec type back. We should at |
| 4455 | // least always get a type spec type, though. |
| 4456 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4457 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4458 | |
| 4459 | return Result; |
| 4460 | } |
| 4461 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4462 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4463 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4464 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4465 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4466 | TypedefNameDecl *Typedef |
| 4467 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4468 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4469 | if (!Typedef) |
| 4470 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4472 | QualType Result = TL.getType(); |
| 4473 | if (getDerived().AlwaysRebuild() || |
| 4474 | Typedef != T->getDecl()) { |
| 4475 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4476 | if (Result.isNull()) |
| 4477 | return QualType(); |
| 4478 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4479 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4480 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4481 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4482 | |
| 4483 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4484 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4485 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4486 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4487 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4488 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4489 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4490 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4491 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4492 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4493 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4494 | if (E.isInvalid()) |
| 4495 | return QualType(); |
| 4496 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4497 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4498 | if (E.isInvalid()) |
| 4499 | return QualType(); |
| 4500 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4501 | QualType Result = TL.getType(); |
| 4502 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4503 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4504 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4505 | if (Result.isNull()) |
| 4506 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4507 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4508 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4509 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4510 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4511 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4512 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4513 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4514 | |
| 4515 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4516 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4517 | |
| 4518 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4519 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4520 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4521 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4522 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4523 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4524 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4525 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4526 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4527 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4528 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 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 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4534 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4535 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4536 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4537 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4538 | |
| 4539 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4540 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4541 | |
| 4542 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4543 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4544 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4545 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4546 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4547 | // decltype expressions are not potentially evaluated contexts |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4548 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, |
| 4549 | /*IsDecltype=*/ true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4550 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4551 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4552 | if (E.isInvalid()) |
| 4553 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4554 | |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4555 | E = getSema().ActOnDecltypeExpression(E.take()); |
| 4556 | if (E.isInvalid()) |
| 4557 | return QualType(); |
| 4558 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4559 | QualType Result = TL.getType(); |
| 4560 | if (getDerived().AlwaysRebuild() || |
| 4561 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4562 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4563 | if (Result.isNull()) |
| 4564 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4565 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4566 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4567 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4568 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4569 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4570 | |
| 4571 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4572 | } |
| 4573 | |
| 4574 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4575 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4576 | TypeLocBuilder &TLB, |
| 4577 | UnaryTransformTypeLoc TL) { |
| 4578 | QualType Result = TL.getType(); |
| 4579 | if (Result->isDependentType()) { |
| 4580 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4581 | QualType NewBase = |
| 4582 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4583 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4584 | T->getUTTKind(), |
| 4585 | TL.getKWLoc()); |
| 4586 | if (Result.isNull()) |
| 4587 | return QualType(); |
| 4588 | } |
| 4589 | |
| 4590 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4591 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4592 | NewTL.setParensRange(TL.getParensRange()); |
| 4593 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4594 | return Result; |
| 4595 | } |
| 4596 | |
| 4597 | template<typename Derived> |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4598 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4599 | AutoTypeLoc TL) { |
| 4600 | const AutoType *T = TL.getTypePtr(); |
| 4601 | QualType OldDeduced = T->getDeducedType(); |
| 4602 | QualType NewDeduced; |
| 4603 | if (!OldDeduced.isNull()) { |
| 4604 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4605 | if (NewDeduced.isNull()) |
| 4606 | return QualType(); |
| 4607 | } |
| 4608 | |
| 4609 | QualType Result = TL.getType(); |
Richard Smith | dc7a4f5 | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 4610 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 4611 | T->isDependentType()) { |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 4612 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4613 | if (Result.isNull()) |
| 4614 | return QualType(); |
| 4615 | } |
| 4616 | |
| 4617 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4618 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4619 | |
| 4620 | return Result; |
| 4621 | } |
| 4622 | |
| 4623 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4624 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4625 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4626 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4627 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4628 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4629 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4630 | if (!Record) |
| 4631 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4632 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4633 | QualType Result = TL.getType(); |
| 4634 | if (getDerived().AlwaysRebuild() || |
| 4635 | Record != T->getDecl()) { |
| 4636 | Result = getDerived().RebuildRecordType(Record); |
| 4637 | if (Result.isNull()) |
| 4638 | return QualType(); |
| 4639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4640 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4641 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4642 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4643 | |
| 4644 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4645 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4646 | |
| 4647 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4648 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4649 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4650 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4651 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4652 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4653 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4654 | if (!Enum) |
| 4655 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4657 | QualType Result = TL.getType(); |
| 4658 | if (getDerived().AlwaysRebuild() || |
| 4659 | Enum != T->getDecl()) { |
| 4660 | Result = getDerived().RebuildEnumType(Enum); |
| 4661 | if (Result.isNull()) |
| 4662 | return QualType(); |
| 4663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4665 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4666 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4667 | |
| 4668 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4669 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4670 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4671 | template<typename Derived> |
| 4672 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4673 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4674 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4675 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4676 | TL.getTypePtr()->getDecl()); |
| 4677 | if (!D) return QualType(); |
| 4678 | |
| 4679 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4680 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4681 | return T; |
| 4682 | } |
| 4683 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4684 | template<typename Derived> |
| 4685 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4686 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4687 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4688 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4691 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4692 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4693 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4694 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4695 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4697 | // Substitute into the replacement type, which itself might involve something |
| 4698 | // that needs to be transformed. This only tends to occur with default |
| 4699 | // template arguments of template template parameters. |
| 4700 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4701 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4702 | if (Replacement.isNull()) |
| 4703 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4704 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4705 | // Always canonicalize the replacement type. |
| 4706 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4707 | QualType Result |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4708 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4709 | Replacement); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4710 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4711 | // Propagate type-source information. |
| 4712 | SubstTemplateTypeParmTypeLoc NewTL |
| 4713 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4714 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4715 | return Result; |
| 4716 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4717 | } |
| 4718 | |
| 4719 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4720 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4721 | TypeLocBuilder &TLB, |
| 4722 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4723 | return TransformTypeSpecType(TLB, TL); |
| 4724 | } |
| 4725 | |
| 4726 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4727 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4728 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4729 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4730 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4731 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4732 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4733 | // because we can't have a dependent nested-name-specifier anyway. |
| 4734 | CXXScopeSpec SS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4736 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4737 | TL.getTemplateNameLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4738 | if (Template.isNull()) |
| 4739 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4740 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4741 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4742 | } |
| 4743 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4744 | template<typename Derived> |
| 4745 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4746 | AtomicTypeLoc TL) { |
| 4747 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4748 | if (ValueType.isNull()) |
| 4749 | return QualType(); |
| 4750 | |
| 4751 | QualType Result = TL.getType(); |
| 4752 | if (getDerived().AlwaysRebuild() || |
| 4753 | ValueType != TL.getValueLoc().getType()) { |
| 4754 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4755 | if (Result.isNull()) |
| 4756 | return QualType(); |
| 4757 | } |
| 4758 | |
| 4759 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4760 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4761 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4762 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4763 | |
| 4764 | return Result; |
| 4765 | } |
| 4766 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4767 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4768 | /// container that provides a \c getArgLoc() member function. |
| 4769 | /// |
| 4770 | /// This iterator is intended to be used with the iterator form of |
| 4771 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4772 | template<typename ArgLocContainer> |
| 4773 | class TemplateArgumentLocContainerIterator { |
| 4774 | ArgLocContainer *Container; |
| 4775 | unsigned Index; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4776 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4777 | public: |
| 4778 | typedef TemplateArgumentLoc value_type; |
| 4779 | typedef TemplateArgumentLoc reference; |
| 4780 | typedef int difference_type; |
| 4781 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4782 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4783 | class pointer { |
| 4784 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4785 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4786 | public: |
| 4787 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4788 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4789 | const TemplateArgumentLoc *operator->() const { |
| 4790 | return &Arg; |
| 4791 | } |
| 4792 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4793 | |
| 4794 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4795 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4796 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4797 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4798 | unsigned Index) |
| 4799 | : Container(&Container), Index(Index) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4800 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4801 | TemplateArgumentLocContainerIterator &operator++() { |
| 4802 | ++Index; |
| 4803 | return *this; |
| 4804 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4805 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4806 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4807 | TemplateArgumentLocContainerIterator Old(*this); |
| 4808 | ++(*this); |
| 4809 | return Old; |
| 4810 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4811 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4812 | TemplateArgumentLoc operator*() const { |
| 4813 | return Container->getArgLoc(Index); |
| 4814 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4815 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4816 | pointer operator->() const { |
| 4817 | return pointer(Container->getArgLoc(Index)); |
| 4818 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4819 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4820 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4821 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4822 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4823 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4824 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4825 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4826 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4827 | return !(X == Y); |
| 4828 | } |
| 4829 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4830 | |
| 4831 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4832 | template <typename Derived> |
| 4833 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4834 | TypeLocBuilder &TLB, |
| 4835 | TemplateSpecializationTypeLoc TL, |
| 4836 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4837 | TemplateArgumentListInfo NewTemplateArgs; |
| 4838 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4839 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4840 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4841 | ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4842 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4843 | ArgIterator(TL, TL.getNumArgs()), |
| 4844 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4845 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4846 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4847 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4848 | |
| 4849 | QualType Result = |
| 4850 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4851 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4852 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4853 | |
| 4854 | if (!Result.isNull()) { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4855 | // Specializations of template template parameters are represented as |
| 4856 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4857 | // within a dependent context can transform them into |
| 4858 | // DependentTemplateSpecializationTypes. |
| 4859 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4860 | DependentTemplateSpecializationTypeLoc NewTL |
| 4861 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4862 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4863 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4864 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4865 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4866 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4867 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4868 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4869 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4870 | return Result; |
| 4871 | } |
| 4872 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4873 | TemplateSpecializationTypeLoc NewTL |
| 4874 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4875 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4876 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4877 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4878 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4879 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4880 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4881 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4882 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4883 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4884 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4885 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4886 | template <typename Derived> |
| 4887 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4888 | TypeLocBuilder &TLB, |
| 4889 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4890 | TemplateName Template, |
| 4891 | CXXScopeSpec &SS) { |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4892 | TemplateArgumentListInfo NewTemplateArgs; |
| 4893 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4894 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4895 | typedef TemplateArgumentLocContainerIterator< |
| 4896 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4897 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4898 | ArgIterator(TL, TL.getNumArgs()), |
| 4899 | NewTemplateArgs)) |
| 4900 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4901 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4902 | // 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] | 4903 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4904 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4905 | QualType Result |
| 4906 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4907 | TL.getTypePtr()->getKeyword(), |
| 4908 | DTN->getQualifier(), |
| 4909 | DTN->getIdentifier(), |
| 4910 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4911 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4912 | DependentTemplateSpecializationTypeLoc NewTL |
| 4913 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4914 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4915 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4916 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4917 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4918 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4919 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4920 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4921 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4922 | return Result; |
| 4923 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4924 | |
| 4925 | QualType Result |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4926 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4927 | TL.getTemplateNameLoc(), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4928 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4929 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4930 | if (!Result.isNull()) { |
| 4931 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4932 | TemplateSpecializationTypeLoc NewTL |
| 4933 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4934 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4935 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4936 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4937 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4938 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4939 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4940 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4941 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4942 | return Result; |
| 4943 | } |
| 4944 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4945 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4946 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4947 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4948 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4949 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4950 | |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4951 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4952 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4953 | if (TL.getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4954 | QualifierLoc |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4955 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4956 | if (!QualifierLoc) |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4957 | return QualType(); |
| 4958 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4959 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4960 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4961 | if (NamedT.isNull()) |
| 4962 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4963 | |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4964 | // C++0x [dcl.type.elab]p2: |
| 4965 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4966 | // resolves to an alias template specialization, the |
| 4967 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 1804174 | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 4968 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 4969 | if (const TemplateSpecializationType *TST = |
| 4970 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4971 | TemplateName Template = TST->getTemplateName(); |
| 4972 | if (TypeAliasTemplateDecl *TAT = |
| 4973 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4974 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4975 | diag::err_tag_reference_non_tag) << 4; |
| 4976 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4977 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4978 | } |
| 4979 | } |
| 4980 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4981 | QualType Result = TL.getType(); |
| 4982 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4983 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4984 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4985 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4986 | T->getKeyword(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4987 | QualifierLoc, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4988 | if (Result.isNull()) |
| 4989 | return QualType(); |
| 4990 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4991 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4992 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4993 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4994 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4995 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4996 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4997 | |
| 4998 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4999 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5000 | TypeLocBuilder &TLB, |
| 5001 | AttributedTypeLoc TL) { |
| 5002 | const AttributedType *oldType = TL.getTypePtr(); |
| 5003 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5004 | if (modifiedType.isNull()) |
| 5005 | return QualType(); |
| 5006 | |
| 5007 | QualType result = TL.getType(); |
| 5008 | |
| 5009 | // FIXME: dependent operand expressions? |
| 5010 | if (getDerived().AlwaysRebuild() || |
| 5011 | modifiedType != oldType->getModifiedType()) { |
| 5012 | // TODO: this is really lame; we should really be rebuilding the |
| 5013 | // equivalent type from first principles. |
| 5014 | QualType equivalentType |
| 5015 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5016 | if (equivalentType.isNull()) |
| 5017 | return QualType(); |
| 5018 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5019 | modifiedType, |
| 5020 | equivalentType); |
| 5021 | } |
| 5022 | |
| 5023 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5024 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5025 | if (TL.hasAttrOperand()) |
| 5026 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5027 | if (TL.hasAttrExprOperand()) |
| 5028 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5029 | else if (TL.hasAttrEnumOperand()) |
| 5030 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5031 | |
| 5032 | return result; |
| 5033 | } |
| 5034 | |
| 5035 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5036 | QualType |
| 5037 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5038 | ParenTypeLoc TL) { |
| 5039 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5040 | if (Inner.isNull()) |
| 5041 | return QualType(); |
| 5042 | |
| 5043 | QualType Result = TL.getType(); |
| 5044 | if (getDerived().AlwaysRebuild() || |
| 5045 | Inner != TL.getInnerLoc().getType()) { |
| 5046 | Result = getDerived().RebuildParenType(Inner); |
| 5047 | if (Result.isNull()) |
| 5048 | return QualType(); |
| 5049 | } |
| 5050 | |
| 5051 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5052 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5053 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5054 | return Result; |
| 5055 | } |
| 5056 | |
| 5057 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5058 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5059 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5060 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5061 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5062 | NestedNameSpecifierLoc QualifierLoc |
| 5063 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5064 | if (!QualifierLoc) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5065 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5067 | QualType Result |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5068 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5069 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5070 | QualifierLoc, |
| 5071 | T->getIdentifier(), |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5072 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5073 | if (Result.isNull()) |
| 5074 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5075 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5076 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5077 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5078 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5079 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5080 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5081 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5082 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5083 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5084 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5085 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5086 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5087 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5088 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5089 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5092 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5093 | QualType TreeTransform<Derived>:: |
| 5094 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5095 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5096 | NestedNameSpecifierLoc QualifierLoc; |
| 5097 | if (TL.getQualifierLoc()) { |
| 5098 | QualifierLoc |
| 5099 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5100 | if (!QualifierLoc) |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5101 | return QualType(); |
| 5102 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5103 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5104 | return getDerived() |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5105 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | template<typename Derived> |
| 5109 | QualType TreeTransform<Derived>:: |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5110 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5111 | DependentTemplateSpecializationTypeLoc TL, |
| 5112 | NestedNameSpecifierLoc QualifierLoc) { |
| 5113 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5115 | TemplateArgumentListInfo NewTemplateArgs; |
| 5116 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5117 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5118 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5119 | typedef TemplateArgumentLocContainerIterator< |
| 5120 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5121 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5122 | ArgIterator(TL, TL.getNumArgs()), |
| 5123 | NewTemplateArgs)) |
| 5124 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5125 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5126 | QualType Result |
| 5127 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5128 | QualifierLoc, |
| 5129 | T->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5130 | TL.getTemplateNameLoc(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5131 | NewTemplateArgs); |
| 5132 | if (Result.isNull()) |
| 5133 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5134 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5135 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5136 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5137 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5138 | // Copy information relevant to the template specialization. |
| 5139 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5140 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5141 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5142 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5143 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5144 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5145 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5146 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5147 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5148 | // Copy information relevant to the elaborated type. |
| 5149 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5150 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5151 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5152 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5153 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5154 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5155 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5156 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5157 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5158 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5159 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5160 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5161 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5162 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5163 | } else { |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5164 | TemplateSpecializationTypeLoc SpecTL |
| 5165 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5166 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5167 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5168 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5169 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5170 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5171 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5172 | } |
| 5173 | return Result; |
| 5174 | } |
| 5175 | |
| 5176 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5177 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5178 | PackExpansionTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5179 | QualType Pattern |
| 5180 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5181 | if (Pattern.isNull()) |
| 5182 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5183 | |
| 5184 | QualType Result = TL.getType(); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5185 | if (getDerived().AlwaysRebuild() || |
| 5186 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5187 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5188 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5189 | TL.getEllipsisLoc(), |
| 5190 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5191 | if (Result.isNull()) |
| 5192 | return QualType(); |
| 5193 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5194 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5195 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5196 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5197 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5201 | QualType |
| 5202 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5203 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5204 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5205 | TLB.pushFullCopy(TL); |
| 5206 | return TL.getType(); |
| 5207 | } |
| 5208 | |
| 5209 | template<typename Derived> |
| 5210 | QualType |
| 5211 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5212 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5213 | // ObjCObjectType is never dependent. |
| 5214 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5215 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5216 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | |
| 5218 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5219 | QualType |
| 5220 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5221 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5222 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5223 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5224 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5225 | } |
| 5226 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5227 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5228 | // Statement transformation |
| 5229 | //===----------------------------------------------------------------------===// |
| 5230 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5231 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5233 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5237 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5238 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5239 | return getDerived().TransformCompoundStmt(S, false); |
| 5240 | } |
| 5241 | |
| 5242 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5243 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5244 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5245 | bool IsStmtExpr) { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5246 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5247 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5248 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5249 | bool SubStmtChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5250 | SmallVector<Stmt*, 8> Statements; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5251 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 5252 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5253 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5254 | if (Result.isInvalid()) { |
| 5255 | // Immediately fail if this was a DeclStmt, since it's very |
| 5256 | // likely that this will cause problems for future statements. |
| 5257 | if (isa<DeclStmt>(*B)) |
| 5258 | return StmtError(); |
| 5259 | |
| 5260 | // Otherwise, just keep processing substatements and fail later. |
| 5261 | SubStmtInvalid = true; |
| 5262 | continue; |
| 5263 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5264 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5265 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 5266 | Statements.push_back(Result.takeAs<Stmt>()); |
| 5267 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5268 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5269 | if (SubStmtInvalid) |
| 5270 | return StmtError(); |
| 5271 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5272 | if (!getDerived().AlwaysRebuild() && |
| 5273 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5274 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5275 | |
| 5276 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5277 | Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5278 | S->getRBracLoc(), |
| 5279 | IsStmtExpr); |
| 5280 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5281 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5282 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5283 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5285 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5286 | { |
Eli Friedman | 6b3014b | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5287 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5288 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5290 | // Transform the left-hand case value. |
| 5291 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5292 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5293 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5294 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5295 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5296 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5297 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5298 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5299 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5300 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5301 | } |
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 | // Build the case statement. |
| 5304 | // Case statements are always rebuilt so that they will attached to their |
| 5305 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5306 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5307 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5308 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5309 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5310 | S->getColonLoc()); |
| 5311 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5312 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5313 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5314 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5315 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5316 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5317 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5318 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5319 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5320 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5324 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5325 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5326 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5327 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5328 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5329 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5330 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5331 | // Default statements are always rebuilt |
| 5332 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5333 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5334 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5335 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5336 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5337 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5338 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5339 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5340 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5341 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5342 | |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5343 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5344 | S->getDecl()); |
| 5345 | if (!LD) |
| 5346 | return StmtError(); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5347 | |
| 5348 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5349 | // FIXME: Pass the real colon location in. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5350 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5351 | cast<LabelDecl>(LD), SourceLocation(), |
| 5352 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5353 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5354 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5355 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5356 | StmtResult |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5357 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5358 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5359 | if (SubStmt.isInvalid()) |
| 5360 | return StmtError(); |
| 5361 | |
| 5362 | // TODO: transform attributes |
| 5363 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5364 | return S; |
| 5365 | |
| 5366 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5367 | S->getAttrs(), |
| 5368 | SubStmt.get()); |
| 5369 | } |
| 5370 | |
| 5371 | template<typename Derived> |
| 5372 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5373 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5374 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5375 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5376 | VarDecl *ConditionVar = 0; |
| 5377 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5378 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5379 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5380 | getDerived().TransformDefinition( |
| 5381 | S->getConditionVariable()->getLocation(), |
| 5382 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5383 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5384 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5385 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5386 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5387 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5388 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5389 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5390 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5391 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5392 | if (S->getCond()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5393 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5394 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5395 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5396 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5397 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5398 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5399 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5400 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5401 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5402 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5403 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5404 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5405 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5406 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5407 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5408 | if (Then.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5409 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5410 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5411 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5412 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5413 | if (Else.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5414 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5415 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5416 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5417 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5418 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5419 | Then.get() == S->getThen() && |
| 5420 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5421 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5422 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5423 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5424 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5425 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5429 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5430 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5431 | // Transform the condition. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5432 | ExprResult Cond; |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5433 | VarDecl *ConditionVar = 0; |
| 5434 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5435 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5436 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5437 | getDerived().TransformDefinition( |
| 5438 | S->getConditionVariable()->getLocation(), |
| 5439 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5440 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5441 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5442 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5443 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5444 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5445 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5446 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5447 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5448 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5449 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5450 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5451 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5452 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5453 | if (Switch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5454 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5455 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5456 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5457 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5458 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5459 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5461 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5462 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5463 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5464 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5466 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5467 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5468 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5469 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5470 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5471 | VarDecl *ConditionVar = 0; |
| 5472 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5473 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5474 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5475 | getDerived().TransformDefinition( |
| 5476 | S->getConditionVariable()->getLocation(), |
| 5477 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5478 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5479 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5480 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5481 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5482 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5483 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5484 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5485 | |
| 5486 | if (S->getCond()) { |
| 5487 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5488 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5489 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5490 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5491 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5492 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5493 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5494 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5495 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5496 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5497 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5498 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5499 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5500 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5501 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5502 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5503 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5504 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5505 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5506 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5507 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5508 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5509 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5510 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5511 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5512 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5513 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5514 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5515 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5516 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5517 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5518 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5519 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5520 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5521 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5522 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5523 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5524 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5525 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5526 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5527 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5528 | if (!getDerived().AlwaysRebuild() && |
| 5529 | Cond.get() == S->getCond() && |
| 5530 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5531 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5532 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5533 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5534 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5535 | S->getRParenLoc()); |
| 5536 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5537 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5538 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5539 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5540 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5541 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5542 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5543 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5544 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5545 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5546 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5547 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5548 | VarDecl *ConditionVar = 0; |
| 5549 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5550 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5551 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5552 | getDerived().TransformDefinition( |
| 5553 | S->getConditionVariable()->getLocation(), |
| 5554 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5555 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5556 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5557 | } else { |
| 5558 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5559 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5560 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5561 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5562 | |
| 5563 | if (S->getCond()) { |
| 5564 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5565 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5566 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5567 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5568 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5569 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5570 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5571 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5572 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5573 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5574 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5575 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5576 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5577 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5578 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5579 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5580 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5581 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | |
Richard Smith | 4195637 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 5583 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5584 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5585 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5586 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5587 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5588 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5589 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5590 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5591 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5592 | if (!getDerived().AlwaysRebuild() && |
| 5593 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5594 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5595 | Inc.get() == S->getInc() && |
| 5596 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5597 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5598 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5599 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5600 | Init.get(), FullCond, ConditionVar, |
| 5601 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5605 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5606 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5607 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5608 | S->getLabel()); |
| 5609 | if (!LD) |
| 5610 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5611 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5612 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5613 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5614 | cast<LabelDecl>(LD)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5618 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5619 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5620 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5621 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5622 | return StmtError(); |
Eli Friedman | d29975f | 2012-01-31 22:47:07 +0000 | [diff] [blame] | 5623 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5624 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5625 | if (!getDerived().AlwaysRebuild() && |
| 5626 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5627 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5628 | |
| 5629 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5630 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5631 | } |
| 5632 | |
| 5633 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5634 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5635 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5636 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5637 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5638 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5639 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5640 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5641 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5642 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5643 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5644 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5645 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5646 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5647 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5648 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5649 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5650 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5651 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5652 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5653 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5654 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5655 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5656 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5657 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5658 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5659 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5660 | bool DeclChanged = false; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5661 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5662 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5663 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5664 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5665 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5666 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5667 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5668 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5669 | if (Transformed != *D) |
| 5670 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5671 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5672 | Decls.push_back(Transformed); |
| 5673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5674 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5675 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5676 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5677 | |
Rafael Espindola | 4549d7f | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 5678 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5679 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5680 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5681 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5682 | StmtResult |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5683 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5684 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5685 | SmallVector<Expr*, 8> Constraints; |
| 5686 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5687 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5688 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5689 | ExprResult AsmString; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5690 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5691 | |
| 5692 | bool ExprsChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5693 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5694 | // Go through the outputs. |
| 5695 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5696 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5697 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5698 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5699 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5700 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5701 | // Transform the output expr. |
| 5702 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5703 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5704 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5705 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5706 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5707 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5708 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5709 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5710 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5711 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5712 | // Go through the inputs. |
| 5713 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5714 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5715 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5716 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5717 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5718 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5719 | // Transform the input expr. |
| 5720 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5721 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5722 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5723 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5724 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5725 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5726 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5727 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5728 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5729 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5730 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5731 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5732 | |
| 5733 | // Go through the clobbers. |
| 5734 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | 5c7f594 | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5735 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5736 | |
| 5737 | // No need to transform the asm string literal. |
| 5738 | AsmString = SemaRef.Owned(S->getAsmString()); |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5739 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5740 | S->isVolatile(), S->getNumOutputs(), |
| 5741 | S->getNumInputs(), Names.data(), |
| 5742 | Constraints, Exprs, AsmString.get(), |
| 5743 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5746 | template<typename Derived> |
| 5747 | StmtResult |
| 5748 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5749 | ArrayRef<Token> AsmToks = |
| 5750 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 62f22b8 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5751 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5752 | bool HadError = false, HadChange = false; |
| 5753 | |
| 5754 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 5755 | SmallVector<Expr*, 8> TransformedExprs; |
| 5756 | TransformedExprs.reserve(SrcExprs.size()); |
| 5757 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 5758 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 5759 | if (!Result.isUsable()) { |
| 5760 | HadError = true; |
| 5761 | } else { |
| 5762 | HadChange |= (Result.get() != SrcExprs[i]); |
| 5763 | TransformedExprs.push_back(Result.take()); |
| 5764 | } |
| 5765 | } |
| 5766 | |
| 5767 | if (HadError) return StmtError(); |
| 5768 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 5769 | return Owned(S); |
| 5770 | |
Chad Rosier | 7bd092b | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 5771 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5772 | AsmToks, S->getAsmString(), |
| 5773 | S->getNumOutputs(), S->getNumInputs(), |
| 5774 | S->getAllConstraints(), S->getClobbers(), |
| 5775 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5776 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5777 | |
| 5778 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5779 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5780 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5781 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5782 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5783 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5784 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5785 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5786 | // Transform the @catch statements (if present). |
| 5787 | bool AnyCatchChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5788 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5789 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5790 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5791 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5792 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5793 | if (Catch.get() != S->getCatchStmt(I)) |
| 5794 | AnyCatchChanged = true; |
| 5795 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5796 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5797 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5798 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5799 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5800 | if (S->getFinallyStmt()) { |
| 5801 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5802 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5803 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | // If nothing changed, just retain this statement. |
| 5807 | if (!getDerived().AlwaysRebuild() && |
| 5808 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5809 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5810 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5811 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5812 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5813 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5814 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5815 | CatchStmts, Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5816 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5817 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5818 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5819 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5820 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5821 | // Transform the @catch parameter, if there is one. |
| 5822 | VarDecl *Var = 0; |
| 5823 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5824 | TypeSourceInfo *TSInfo = 0; |
| 5825 | if (FromVar->getTypeSourceInfo()) { |
| 5826 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5827 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5828 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5829 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5830 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5831 | QualType T; |
| 5832 | if (TSInfo) |
| 5833 | T = TSInfo->getType(); |
| 5834 | else { |
| 5835 | T = getDerived().TransformType(FromVar->getType()); |
| 5836 | if (T.isNull()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5837 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5838 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5839 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5840 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5841 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5842 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5843 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5844 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5845 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5846 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5847 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5848 | |
| 5849 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5850 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5851 | Var, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5852 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5853 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5854 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5855 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5856 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5857 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5858 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5859 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5860 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5861 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5862 | // If nothing changed, just retain this statement. |
| 5863 | if (!getDerived().AlwaysRebuild() && |
| 5864 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5865 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5866 | |
| 5867 | // Build a new statement. |
| 5868 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5869 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5870 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5871 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5872 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5873 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5874 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5875 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5876 | if (S->getThrowExpr()) { |
| 5877 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5878 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5879 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5880 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5881 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5882 | if (!getDerived().AlwaysRebuild() && |
| 5883 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5884 | return getSema().Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5885 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5886 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5887 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5888 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5889 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5890 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5891 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5892 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5893 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5894 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5895 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5896 | return StmtError(); |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5897 | Object = |
| 5898 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5899 | Object.get()); |
| 5900 | if (Object.isInvalid()) |
| 5901 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5902 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5903 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5904 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5905 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5906 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5907 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5908 | // If nothing change, just retain the current statement. |
| 5909 | if (!getDerived().AlwaysRebuild() && |
| 5910 | Object.get() == S->getSynchExpr() && |
| 5911 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5912 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5913 | |
| 5914 | // Build a new statement. |
| 5915 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5916 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
| 5919 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5920 | StmtResult |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5921 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5922 | ObjCAutoreleasePoolStmt *S) { |
| 5923 | // Transform the body. |
| 5924 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5925 | if (Body.isInvalid()) |
| 5926 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5927 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5928 | // If nothing changed, just retain this statement. |
| 5929 | if (!getDerived().AlwaysRebuild() && |
| 5930 | Body.get() == S->getSubStmt()) |
| 5931 | return SemaRef.Owned(S); |
| 5932 | |
| 5933 | // Build a new statement. |
| 5934 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5935 | S->getAtLoc(), Body.get()); |
| 5936 | } |
| 5937 | |
| 5938 | template<typename Derived> |
| 5939 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5940 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5941 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5942 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5943 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5944 | if (Element.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5945 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5946 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5947 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5948 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5949 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5950 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5951 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5952 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5953 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5954 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5955 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5956 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5957 | // If nothing changed, just retain this statement. |
| 5958 | if (!getDerived().AlwaysRebuild() && |
| 5959 | Element.get() == S->getElement() && |
| 5960 | Collection.get() == S->getCollection() && |
| 5961 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5962 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5963 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5964 | // Build a new statement. |
| 5965 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5966 | Element.get(), |
| 5967 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5968 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5969 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | |
| 5973 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5974 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5975 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5976 | // Transform the exception declaration, if any. |
| 5977 | VarDecl *Var = 0; |
| 5978 | if (S->getExceptionDecl()) { |
| 5979 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5980 | TypeSourceInfo *T = getDerived().TransformType( |
| 5981 | ExceptionDecl->getTypeSourceInfo()); |
| 5982 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5983 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5984 | |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5985 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 5986 | ExceptionDecl->getInnerLocStart(), |
| 5987 | ExceptionDecl->getLocation(), |
| 5988 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5989 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5990 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5992 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5993 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5994 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5995 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5996 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5997 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5998 | if (!getDerived().AlwaysRebuild() && |
| 5999 | !Var && |
| 6000 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6001 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6002 | |
| 6003 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 6004 | Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6005 | Handler.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6006 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6007 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6008 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6009 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6010 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 6011 | // Transform the try block itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6012 | StmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6013 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 6014 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6015 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6016 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6017 | // Transform the handlers. |
| 6018 | bool HandlerChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6019 | SmallVector<Stmt*, 8> Handlers; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6020 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6021 | StmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6022 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 6023 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6024 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6025 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6026 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 6027 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 6028 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6029 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6030 | if (!getDerived().AlwaysRebuild() && |
| 6031 | TryBlock.get() == S->getTryBlock() && |
| 6032 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6033 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6034 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6035 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6036 | Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6037 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6038 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6039 | template<typename Derived> |
| 6040 | StmtResult |
| 6041 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6042 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6043 | if (Range.isInvalid()) |
| 6044 | return StmtError(); |
| 6045 | |
| 6046 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6047 | if (BeginEnd.isInvalid()) |
| 6048 | return StmtError(); |
| 6049 | |
| 6050 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6051 | if (Cond.isInvalid()) |
| 6052 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6053 | if (Cond.get()) |
| 6054 | Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); |
| 6055 | if (Cond.isInvalid()) |
| 6056 | return StmtError(); |
| 6057 | if (Cond.get()) |
| 6058 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6059 | |
| 6060 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6061 | if (Inc.isInvalid()) |
| 6062 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6063 | if (Inc.get()) |
| 6064 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6065 | |
| 6066 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6067 | if (LoopVar.isInvalid()) |
| 6068 | return StmtError(); |
| 6069 | |
| 6070 | StmtResult NewStmt = S; |
| 6071 | if (getDerived().AlwaysRebuild() || |
| 6072 | Range.get() != S->getRangeStmt() || |
| 6073 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6074 | Cond.get() != S->getCond() || |
| 6075 | Inc.get() != S->getInc() || |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6076 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6077 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6078 | S->getColonLoc(), Range.get(), |
| 6079 | BeginEnd.get(), Cond.get(), |
| 6080 | Inc.get(), LoopVar.get(), |
| 6081 | S->getRParenLoc()); |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6082 | if (NewStmt.isInvalid()) |
| 6083 | return StmtError(); |
| 6084 | } |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6085 | |
| 6086 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6087 | if (Body.isInvalid()) |
| 6088 | return StmtError(); |
| 6089 | |
| 6090 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6091 | // it now so we have a new statement to attach the body to. |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6092 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6093 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6094 | S->getColonLoc(), Range.get(), |
| 6095 | BeginEnd.get(), Cond.get(), |
| 6096 | Inc.get(), LoopVar.get(), |
| 6097 | S->getRParenLoc()); |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6098 | if (NewStmt.isInvalid()) |
| 6099 | return StmtError(); |
| 6100 | } |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6101 | |
| 6102 | if (NewStmt.get() == S) |
| 6103 | return SemaRef.Owned(S); |
| 6104 | |
| 6105 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6106 | } |
| 6107 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6108 | template<typename Derived> |
| 6109 | StmtResult |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6110 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6111 | MSDependentExistsStmt *S) { |
| 6112 | // Transform the nested-name-specifier, if any. |
| 6113 | NestedNameSpecifierLoc QualifierLoc; |
| 6114 | if (S->getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6115 | QualifierLoc |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6116 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6117 | if (!QualifierLoc) |
| 6118 | return StmtError(); |
| 6119 | } |
| 6120 | |
| 6121 | // Transform the declaration name. |
| 6122 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6123 | if (NameInfo.getName()) { |
| 6124 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6125 | if (!NameInfo.getName()) |
| 6126 | return StmtError(); |
| 6127 | } |
| 6128 | |
| 6129 | // Check whether anything changed. |
| 6130 | if (!getDerived().AlwaysRebuild() && |
| 6131 | QualifierLoc == S->getQualifierLoc() && |
| 6132 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6133 | return S; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6134 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6135 | // Determine whether this name exists, if we can. |
| 6136 | CXXScopeSpec SS; |
| 6137 | SS.Adopt(QualifierLoc); |
| 6138 | bool Dependent = false; |
| 6139 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { |
| 6140 | case Sema::IER_Exists: |
| 6141 | if (S->isIfExists()) |
| 6142 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6143 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6144 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6145 | |
| 6146 | case Sema::IER_DoesNotExist: |
| 6147 | if (S->isIfNotExists()) |
| 6148 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6149 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6150 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6151 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6152 | case Sema::IER_Dependent: |
| 6153 | Dependent = true; |
| 6154 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6155 | |
Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6156 | case Sema::IER_Error: |
| 6157 | return StmtError(); |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6158 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6159 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6160 | // We need to continue with the instantiation, so do so now. |
| 6161 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6162 | if (SubStmt.isInvalid()) |
| 6163 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6164 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6165 | // If we have resolved the name, just transform to the substatement. |
| 6166 | if (!Dependent) |
| 6167 | return SubStmt; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6168 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6169 | // The name is still dependent, so build a dependent expression again. |
| 6170 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6171 | S->isIfExists(), |
| 6172 | QualifierLoc, |
| 6173 | NameInfo, |
| 6174 | SubStmt.get()); |
| 6175 | } |
| 6176 | |
| 6177 | template<typename Derived> |
John McCall | 76da55d | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6178 | ExprResult |
| 6179 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6180 | NestedNameSpecifierLoc QualifierLoc; |
| 6181 | if (E->getQualifierLoc()) { |
| 6182 | QualifierLoc |
| 6183 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6184 | if (!QualifierLoc) |
| 6185 | return ExprError(); |
| 6186 | } |
| 6187 | |
| 6188 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6189 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6190 | if (!PD) |
| 6191 | return ExprError(); |
| 6192 | |
| 6193 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6194 | if (Base.isInvalid()) |
| 6195 | return ExprError(); |
| 6196 | |
| 6197 | return new (SemaRef.getASTContext()) |
| 6198 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6199 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6200 | QualifierLoc, E->getMemberLoc()); |
| 6201 | } |
| 6202 | |
| 6203 | template<typename Derived> |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6204 | StmtResult |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6205 | TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 6206 | StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 6207 | if(TryBlock.isInvalid()) return StmtError(); |
| 6208 | |
| 6209 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 6210 | if(!getDerived().AlwaysRebuild() && |
| 6211 | TryBlock.get() == S->getTryBlock() && |
| 6212 | Handler.get() == S->getHandler()) |
| 6213 | return SemaRef.Owned(S); |
| 6214 | |
| 6215 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), |
| 6216 | S->getTryLoc(), |
| 6217 | TryBlock.take(), |
| 6218 | Handler.take()); |
| 6219 | } |
| 6220 | |
| 6221 | template<typename Derived> |
| 6222 | StmtResult |
| 6223 | TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 6224 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 6225 | if(Block.isInvalid()) return StmtError(); |
| 6226 | |
| 6227 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), |
| 6228 | Block.take()); |
| 6229 | } |
| 6230 | |
| 6231 | template<typename Derived> |
| 6232 | StmtResult |
| 6233 | TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 6234 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 6235 | if(FilterExpr.isInvalid()) return StmtError(); |
| 6236 | |
| 6237 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 6238 | if(Block.isInvalid()) return StmtError(); |
| 6239 | |
| 6240 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), |
| 6241 | FilterExpr.take(), |
| 6242 | Block.take()); |
| 6243 | } |
| 6244 | |
| 6245 | template<typename Derived> |
| 6246 | StmtResult |
| 6247 | TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6248 | if(isa<SEHFinallyStmt>(Handler)) |
| 6249 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6250 | else |
| 6251 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6252 | } |
| 6253 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6254 | template<typename Derived> |
| 6255 | StmtResult |
| 6256 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 6257 | // Transform the clauses |
Robert Wilhelm | e7205c0 | 2013-08-10 12:33:24 +0000 | [diff] [blame] | 6258 | SmallVector<OMPClause *, 5> TClauses; |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6259 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6260 | TClauses.reserve(Clauses.size()); |
| 6261 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6262 | I != E; ++I) { |
| 6263 | if (*I) { |
| 6264 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
| 6265 | if (!Clause) |
| 6266 | return StmtError(); |
| 6267 | TClauses.push_back(Clause); |
| 6268 | } |
| 6269 | else { |
| 6270 | TClauses.push_back(0); |
| 6271 | } |
| 6272 | } |
| 6273 | if (!D->getAssociatedStmt()) |
| 6274 | return StmtError(); |
| 6275 | StmtResult AssociatedStmt = |
| 6276 | getDerived().TransformStmt(D->getAssociatedStmt()); |
| 6277 | if (AssociatedStmt.isInvalid()) |
| 6278 | return StmtError(); |
| 6279 | |
| 6280 | return getDerived().RebuildOMPParallelDirective(TClauses, |
| 6281 | AssociatedStmt.take(), |
| 6282 | D->getLocStart(), |
| 6283 | D->getLocEnd()); |
| 6284 | } |
| 6285 | |
| 6286 | template<typename Derived> |
| 6287 | OMPClause * |
| 6288 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| 6289 | return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(), |
| 6290 | C->getDefaultKindKwLoc(), |
| 6291 | C->getLocStart(), |
| 6292 | C->getLParenLoc(), |
| 6293 | C->getLocEnd()); |
| 6294 | } |
| 6295 | |
| 6296 | template<typename Derived> |
| 6297 | OMPClause * |
| 6298 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Robert Wilhelm | e7205c0 | 2013-08-10 12:33:24 +0000 | [diff] [blame] | 6299 | SmallVector<Expr *, 5> Vars; |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6300 | Vars.reserve(C->varlist_size()); |
| 6301 | for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(), |
| 6302 | E = C->varlist_end(); |
| 6303 | I != E; ++I) { |
| 6304 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I)); |
| 6305 | if (EVar.isInvalid()) |
| 6306 | return 0; |
| 6307 | Vars.push_back(EVar.take()); |
| 6308 | } |
| 6309 | return getDerived().RebuildOMPPrivateClause(Vars, |
| 6310 | C->getLocStart(), |
| 6311 | C->getLParenLoc(), |
| 6312 | C->getLocEnd()); |
| 6313 | } |
| 6314 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6315 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6316 | // Expression transformation |
| 6317 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6318 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6319 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6320 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6321 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6323 | |
| 6324 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6325 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6326 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6327 | NestedNameSpecifierLoc QualifierLoc; |
| 6328 | if (E->getQualifierLoc()) { |
| 6329 | QualifierLoc |
| 6330 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6331 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6332 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6333 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6334 | |
| 6335 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6336 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6337 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6338 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6339 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6340 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6341 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6342 | if (NameInfo.getName()) { |
| 6343 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6344 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6345 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6346 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6347 | |
| 6348 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6349 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6350 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6351 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6352 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6353 | |
| 6354 | // Mark it referenced in the new context regardless. |
| 6355 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6356 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6357 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6358 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6359 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6360 | |
| 6361 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6362 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6363 | TemplateArgs = &TransArgs; |
| 6364 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6365 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6366 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6367 | E->getNumTemplateArgs(), |
| 6368 | TransArgs)) |
| 6369 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6370 | } |
| 6371 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6372 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6373 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6374 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6375 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6376 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6377 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6378 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6379 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6381 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6382 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6383 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6384 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6385 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6386 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6387 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6388 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6389 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6390 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6391 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6393 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6394 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6395 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6396 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6397 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6399 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6400 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6401 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6402 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
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 | } |
| 6405 | |
| 6406 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6407 | ExprResult |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6408 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 391ca9f | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 6409 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 6410 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6411 | return SemaRef.MaybeBindToTemporary(E); |
| 6412 | } |
| 6413 | |
| 6414 | template<typename Derived> |
| 6415 | ExprResult |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6416 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6417 | ExprResult ControllingExpr = |
| 6418 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6419 | if (ControllingExpr.isInvalid()) |
| 6420 | return ExprError(); |
| 6421 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6422 | SmallVector<Expr *, 4> AssocExprs; |
| 6423 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6424 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6425 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6426 | if (TS) { |
| 6427 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6428 | if (!AssocType) |
| 6429 | return ExprError(); |
| 6430 | AssocTypes.push_back(AssocType); |
| 6431 | } else { |
| 6432 | AssocTypes.push_back(0); |
| 6433 | } |
| 6434 | |
| 6435 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6436 | if (AssocExpr.isInvalid()) |
| 6437 | return ExprError(); |
| 6438 | AssocExprs.push_back(AssocExpr.release()); |
| 6439 | } |
| 6440 | |
| 6441 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6442 | E->getDefaultLoc(), |
| 6443 | E->getRParenLoc(), |
| 6444 | ControllingExpr.release(), |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 6445 | AssocTypes, |
| 6446 | AssocExprs); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6447 | } |
| 6448 | |
| 6449 | template<typename Derived> |
| 6450 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6451 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6452 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6453 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6454 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6455 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6456 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6457 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6458 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6459 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6460 | E->getRParen()); |
| 6461 | } |
| 6462 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6463 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 6464 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 6465 | /// object available. |
| 6466 | template<typename Derived> |
| 6467 | ExprResult |
| 6468 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 6469 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| 6470 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true); |
| 6471 | else |
| 6472 | return getDerived().TransformExpr(E); |
| 6473 | } |
| 6474 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6475 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6476 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6477 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | 82b0001 | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 6478 | ExprResult SubExpr; |
| 6479 | if (E->getOpcode() == UO_AddrOf) |
| 6480 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 6481 | else |
| 6482 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6483 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6484 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6485 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6486 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6487 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6488 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6489 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 6490 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6491 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6493 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6494 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6495 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6496 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 6497 | // Transform the type. |
| 6498 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6499 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6500 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6501 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6502 | // Transform all of the components into components similar to what the |
| 6503 | // parser uses. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6504 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 6505 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 6506 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6507 | // template code that we don't care. |
| 6508 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6509 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6510 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6511 | SmallVector<Component, 4> Components; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6512 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 6513 | const Node &ON = E->getComponent(I); |
| 6514 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 6515 | Comp.isBrackets = true; |
Abramo Bagnara | 06dec89 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 6516 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 6517 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6518 | switch (ON.getKind()) { |
| 6519 | case Node::Array: { |
| 6520 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6521 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6522 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6523 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6524 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6525 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 6526 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6527 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6528 | break; |
| 6529 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6530 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6531 | case Node::Field: |
| 6532 | case Node::Identifier: |
| 6533 | Comp.isBrackets = false; |
| 6534 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 6535 | if (!Comp.U.IdentInfo) |
| 6536 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6537 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6538 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6539 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 6540 | case Node::Base: |
| 6541 | // Will be recomputed during the rebuild. |
| 6542 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6543 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6544 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6545 | Components.push_back(Comp); |
| 6546 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6547 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6548 | // If nothing changed, retain the existing expression. |
| 6549 | if (!getDerived().AlwaysRebuild() && |
| 6550 | Type == E->getTypeSourceInfo() && |
| 6551 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6552 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6553 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6554 | // Build a new offsetof expression. |
| 6555 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 6556 | Components.data(), Components.size(), |
| 6557 | E->getRParenLoc()); |
| 6558 | } |
| 6559 | |
| 6560 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6561 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 6562 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6563 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 6564 | "opaque value expression requires transformation"); |
| 6565 | return SemaRef.Owned(E); |
| 6566 | } |
| 6567 | |
| 6568 | template<typename Derived> |
| 6569 | ExprResult |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6570 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | 01e19be | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 6571 | // Rebuild the syntactic form. The original syntactic form has |
| 6572 | // opaque-value expressions in it, so strip those away and rebuild |
| 6573 | // the result. This is a really awful way of doing this, but the |
| 6574 | // better solution (rebuilding the semantic expressions and |
| 6575 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 6576 | // TreeTransform to not strip away implicit conversions. |
| 6577 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 6578 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6579 | if (result.isInvalid()) return ExprError(); |
| 6580 | |
| 6581 | // If that gives us a pseudo-object result back, the pseudo-object |
| 6582 | // expression must have been an lvalue-to-rvalue conversion which we |
| 6583 | // should reapply. |
| 6584 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 6585 | result = SemaRef.checkPseudoObjectRValue(result.take()); |
| 6586 | |
| 6587 | return result; |
| 6588 | } |
| 6589 | |
| 6590 | template<typename Derived> |
| 6591 | ExprResult |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6592 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 6593 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6594 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6595 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6596 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6597 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6598 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6599 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6600 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6601 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6602 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6603 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6604 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 6605 | E->getKind(), |
| 6606 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6608 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6609 | // C++0x [expr.sizeof]p1: |
| 6610 | // The operand is either an expression, which is an unevaluated operand |
| 6611 | // [...] |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 6612 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 6613 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6614 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6615 | ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 6616 | if (SubExpr.isInvalid()) |
| 6617 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6618 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6619 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 6620 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6621 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6622 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6623 | E->getOperatorLoc(), |
| 6624 | E->getKind(), |
| 6625 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6626 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6628 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6629 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6630 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6631 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6632 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6633 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6634 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6635 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6636 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6637 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6638 | |
| 6639 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6640 | if (!getDerived().AlwaysRebuild() && |
| 6641 | LHS.get() == E->getLHS() && |
| 6642 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6643 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6644 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6645 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6646 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6647 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6648 | E->getRBracketLoc()); |
| 6649 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6650 | |
| 6651 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6652 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6653 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6654 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6655 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6656 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6657 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6658 | |
| 6659 | // Transform arguments. |
| 6660 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6661 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6662 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6663 | &ArgChanged)) |
| 6664 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6665 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6666 | if (!getDerived().AlwaysRebuild() && |
| 6667 | Callee.get() == E->getCallee() && |
| 6668 | !ArgChanged) |
Dmitri Gribenko | 1ad23d6 | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 6669 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6670 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6671 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6672 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6673 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6674 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6675 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6676 | E->getRParenLoc()); |
| 6677 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6678 | |
| 6679 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6680 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6681 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6682 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6683 | if (Base.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 | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6686 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6687 | if (E->hasQualifier()) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6688 | QualifierLoc |
| 6689 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6690 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6691 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6692 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6693 | } |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6694 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6695 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6696 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6697 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6698 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6699 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6700 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6701 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6702 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6703 | if (FoundDecl == E->getMemberDecl()) { |
| 6704 | FoundDecl = Member; |
| 6705 | } else { |
| 6706 | FoundDecl = cast_or_null<NamedDecl>( |
| 6707 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6708 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6709 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6710 | } |
| 6711 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6712 | if (!getDerived().AlwaysRebuild() && |
| 6713 | Base.get() == E->getBase() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6714 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6715 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6716 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6717 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6718 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6719 | // Mark it referenced in the new context regardless. |
| 6720 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6721 | SemaRef.MarkMemberReferenced(E); |
| 6722 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6723 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6724 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6725 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6726 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6727 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6728 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6729 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6730 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6731 | E->getNumTemplateArgs(), |
| 6732 | TransArgs)) |
| 6733 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6734 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6735 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6736 | // FIXME: Bogus source location for the operator |
| 6737 | SourceLocation FakeOperatorLoc |
| 6738 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6739 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6740 | // FIXME: to do this check properly, we will need to preserve the |
| 6741 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6742 | // base (and therefore couldn't do the check) and a |
| 6743 | // nested-name-qualifier (and therefore could do the lookup). |
| 6744 | NamedDecl *FirstQualifierInScope = 0; |
| 6745 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6746 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6747 | E->isArrow(), |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6748 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6749 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6750 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6751 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6752 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6753 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6754 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6755 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6757 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6758 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6759 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6760 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6761 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6762 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6763 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6764 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6765 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6766 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6767 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6768 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6769 | if (!getDerived().AlwaysRebuild() && |
| 6770 | LHS.get() == E->getLHS() && |
| 6771 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6772 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6773 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 6774 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 6775 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 6776 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6777 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6778 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6781 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6782 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6783 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6784 | CompoundAssignOperator *E) { |
| 6785 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6786 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6787 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6788 | template<typename Derived> |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6789 | ExprResult TreeTransform<Derived>:: |
| 6790 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6791 | // Just rebuild the common and RHS expressions and see whether we |
| 6792 | // get any changes. |
| 6793 | |
| 6794 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6795 | if (commonExpr.isInvalid()) |
| 6796 | return ExprError(); |
| 6797 | |
| 6798 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6799 | if (rhs.isInvalid()) |
| 6800 | return ExprError(); |
| 6801 | |
| 6802 | if (!getDerived().AlwaysRebuild() && |
| 6803 | commonExpr.get() == e->getCommon() && |
| 6804 | rhs.get() == e->getFalseExpr()) |
| 6805 | return SemaRef.Owned(e); |
| 6806 | |
| 6807 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6808 | e->getQuestionLoc(), |
| 6809 | 0, |
| 6810 | e->getColonLoc(), |
| 6811 | rhs.get()); |
| 6812 | } |
| 6813 | |
| 6814 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6815 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6816 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6817 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6818 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6819 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6820 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6821 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6822 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6823 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6824 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6825 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6826 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6827 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6829 | if (!getDerived().AlwaysRebuild() && |
| 6830 | Cond.get() == E->getCond() && |
| 6831 | LHS.get() == E->getLHS() && |
| 6832 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6833 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6834 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6835 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6836 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6837 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6838 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6839 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6841 | |
| 6842 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6843 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6844 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6845 | // Implicit casts are eliminated during transformation, since they |
| 6846 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6847 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6848 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6849 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6850 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6851 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6852 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6853 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6854 | if (!Type) |
| 6855 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6856 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6857 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6858 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6859 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6860 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6861 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6862 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6863 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6864 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6865 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6866 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6867 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6868 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6869 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6870 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6871 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6872 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6873 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6874 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6875 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6876 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6877 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6878 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6879 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6880 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6881 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6882 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6883 | return ExprError(); |
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 | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6886 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6887 | Init.get() == E->getInitializer()) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6888 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6889 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6890 | // Note: the expression type doesn't necessarily match the |
| 6891 | // type-as-written, but that's okay, because it should always be |
| 6892 | // derivable from the initializer. |
| 6893 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6894 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6895 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6896 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6897 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6898 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6899 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6900 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6901 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6902 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6903 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6904 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6906 | if (!getDerived().AlwaysRebuild() && |
| 6907 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6908 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6909 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6910 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6911 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6912 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6913 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6914 | E->getAccessorLoc(), |
| 6915 | E->getAccessor()); |
| 6916 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6919 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6920 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6921 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6922 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6923 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6924 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6925 | Inits, &InitChanged)) |
| 6926 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6927 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6928 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6929 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6930 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6931 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6932 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6933 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6934 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6935 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6936 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6937 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6938 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6939 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6940 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6941 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6942 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6943 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6944 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6945 | // transform the designators. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6946 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6947 | bool ExprChanged = false; |
| 6948 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6949 | DEnd = E->designators_end(); |
| 6950 | D != DEnd; ++D) { |
| 6951 | if (D->isFieldDesignator()) { |
| 6952 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6953 | D->getDotLoc(), |
| 6954 | D->getFieldLoc())); |
| 6955 | continue; |
| 6956 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6957 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6958 | if (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6959 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6960 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6961 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6962 | |
| 6963 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6964 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6965 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6966 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6967 | ArrayExprs.push_back(Index.release()); |
| 6968 | continue; |
| 6969 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6970 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6971 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6972 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6973 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6974 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6975 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6976 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6977 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6978 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6979 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6980 | |
| 6981 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6982 | End.get(), |
| 6983 | D->getLBracketLoc(), |
| 6984 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6985 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6986 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6987 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6988 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6989 | ArrayExprs.push_back(Start.release()); |
| 6990 | ArrayExprs.push_back(End.release()); |
| 6991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6992 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6993 | if (!getDerived().AlwaysRebuild() && |
| 6994 | Init.get() == E->getInit() && |
| 6995 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6996 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6997 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6998 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6999 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7000 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7001 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7002 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7003 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7004 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7005 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7006 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7007 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7008 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7009 | // FIXME: Will we ever have proper type location here? Will we actually |
| 7010 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7011 | QualType T = getDerived().TransformType(E->getType()); |
| 7012 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7013 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 7016 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7017 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7018 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7019 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 7020 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7021 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7022 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7023 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7024 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 7025 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 7026 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7027 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7028 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7029 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7030 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7031 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7032 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7033 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7034 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7035 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7036 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7037 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7038 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7039 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7040 | } |
| 7041 | |
| 7042 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7043 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7044 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7045 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7046 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7047 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 7048 | &ArgumentChanged)) |
| 7049 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7050 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7051 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7052 | Inits, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7053 | E->getRParenLoc()); |
| 7054 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7055 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7056 | /// \brief Transform an address-of-label expression. |
| 7057 | /// |
| 7058 | /// By default, the transformation of an address-of-label expression always |
| 7059 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 7060 | /// the corresponding label statement by semantic analysis. |
| 7061 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7062 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7063 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7064 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 7065 | E->getLabel()); |
| 7066 | if (!LD) |
| 7067 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7068 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7069 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7070 | cast<LabelDecl>(LD)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7072 | |
| 7073 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7074 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7075 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7076 | SemaRef.ActOnStartStmtExpr(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7077 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7078 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7079 | if (SubStmt.isInvalid()) { |
| 7080 | SemaRef.ActOnStmtExprError(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7081 | return ExprError(); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7082 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7083 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7084 | if (!getDerived().AlwaysRebuild() && |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7085 | SubStmt.get() == E->getSubStmt()) { |
| 7086 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 7087 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7088 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7089 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7090 | |
| 7091 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7092 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7093 | E->getRParenLoc()); |
| 7094 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7095 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7096 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7097 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7098 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7099 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7100 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7101 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7102 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7103 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7104 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7105 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7106 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7107 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7108 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7109 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7110 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7111 | if (!getDerived().AlwaysRebuild() && |
| 7112 | Cond.get() == E->getCond() && |
| 7113 | LHS.get() == E->getLHS() && |
| 7114 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7115 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7116 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7117 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7118 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7119 | E->getRParenLoc()); |
| 7120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7121 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7122 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7123 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7124 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7125 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7126 | } |
| 7127 | |
| 7128 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7129 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7130 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7131 | switch (E->getOperator()) { |
| 7132 | case OO_New: |
| 7133 | case OO_Delete: |
| 7134 | case OO_Array_New: |
| 7135 | case OO_Array_Delete: |
| 7136 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7137 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7138 | case OO_Call: { |
| 7139 | // This is a call to an object's operator(). |
| 7140 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 7141 | |
| 7142 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7143 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7144 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7145 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7146 | |
| 7147 | // FIXME: Poor location information |
| 7148 | SourceLocation FakeLParenLoc |
| 7149 | = SemaRef.PP.getLocForEndOfToken( |
| 7150 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 7151 | |
| 7152 | // Transform the call arguments. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7153 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7154 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7155 | Args)) |
| 7156 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7157 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7158 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7159 | Args, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7160 | E->getLocEnd()); |
| 7161 | } |
| 7162 | |
| 7163 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 7164 | case OO_##Name: |
| 7165 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 7166 | #include "clang/Basic/OperatorKinds.def" |
| 7167 | case OO_Subscript: |
| 7168 | // Handled below. |
| 7169 | break; |
| 7170 | |
| 7171 | case OO_Conditional: |
| 7172 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7173 | |
| 7174 | case OO_None: |
| 7175 | case NUM_OVERLOADED_OPERATORS: |
| 7176 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7177 | } |
| 7178 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7179 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7180 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7181 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7182 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7183 | ExprResult First; |
| 7184 | if (E->getOperator() == OO_Amp) |
| 7185 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 7186 | else |
| 7187 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7188 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7189 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7190 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7191 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7192 | if (E->getNumArgs() == 2) { |
| 7193 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 7194 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7195 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7196 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7197 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7198 | if (!getDerived().AlwaysRebuild() && |
| 7199 | Callee.get() == E->getCallee() && |
| 7200 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7201 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7202 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7203 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7204 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7205 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7206 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7207 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 7208 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7209 | Callee.get(), |
| 7210 | First.get(), |
| 7211 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7213 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7214 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7215 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7216 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7217 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7218 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7219 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7220 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7221 | ExprResult |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7222 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 7223 | // Transform the callee. |
| 7224 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 7225 | if (Callee.isInvalid()) |
| 7226 | return ExprError(); |
| 7227 | |
| 7228 | // Transform exec config. |
| 7229 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 7230 | if (EC.isInvalid()) |
| 7231 | return ExprError(); |
| 7232 | |
| 7233 | // Transform arguments. |
| 7234 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7235 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7236 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7237 | &ArgChanged)) |
| 7238 | return ExprError(); |
| 7239 | |
| 7240 | if (!getDerived().AlwaysRebuild() && |
| 7241 | Callee.get() == E->getCallee() && |
| 7242 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7243 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7244 | |
| 7245 | // FIXME: Wrong source location information for the '('. |
| 7246 | SourceLocation FakeLParenLoc |
| 7247 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 7248 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7249 | Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7250 | E->getRParenLoc(), EC.get()); |
| 7251 | } |
| 7252 | |
| 7253 | template<typename Derived> |
| 7254 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7255 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7256 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7257 | if (!Type) |
| 7258 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7259 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7260 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7261 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7262 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7263 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7264 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7265 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7266 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7267 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7268 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7269 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7270 | E->getStmtClass(), |
Fariborz Jahanian | f799ae1 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7271 | E->getAngleBrackets().getBegin(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7272 | Type, |
Fariborz Jahanian | f799ae1 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7273 | E->getAngleBrackets().getEnd(), |
| 7274 | // FIXME. this should be '(' location |
| 7275 | E->getAngleBrackets().getEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7276 | SubExpr.get(), |
Abramo Bagnara | 6cf7d7d | 2012-10-15 21:08:58 +0000 | [diff] [blame] | 7277 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7278 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7279 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7280 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7281 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7282 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 7283 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7284 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7285 | |
| 7286 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7287 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7288 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 7289 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7290 | } |
| 7291 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7292 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7293 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7294 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7295 | CXXReinterpretCastExpr *E) { |
| 7296 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7297 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7298 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7299 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7300 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7301 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 7302 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7303 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7304 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7305 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7306 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7307 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7308 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7309 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7310 | if (!Type) |
| 7311 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7312 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7313 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7314 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7315 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7316 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7317 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7318 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7319 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7320 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7321 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7322 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7323 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | cdd4b78 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 7324 | E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7325 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7326 | E->getRParenLoc()); |
| 7327 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7328 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7329 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7330 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7331 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7332 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7333 | TypeSourceInfo *TInfo |
| 7334 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7335 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7336 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7337 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7338 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7339 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7340 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7341 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7342 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7343 | E->getLocStart(), |
| 7344 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7345 | E->getLocEnd()); |
| 7346 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7347 | |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7348 | // We don't know whether the subexpression is potentially evaluated until |
| 7349 | // after we perform semantic analysis. We speculatively assume it is |
| 7350 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7351 | // potentially evaluated. |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7352 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7353 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7354 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7355 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7356 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7357 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7358 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7359 | if (!getDerived().AlwaysRebuild() && |
| 7360 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7361 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7362 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7363 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7364 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7365 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7366 | E->getLocEnd()); |
| 7367 | } |
| 7368 | |
| 7369 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7370 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7371 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7372 | if (E->isTypeOperand()) { |
| 7373 | TypeSourceInfo *TInfo |
| 7374 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7375 | if (!TInfo) |
| 7376 | return ExprError(); |
| 7377 | |
| 7378 | if (!getDerived().AlwaysRebuild() && |
| 7379 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7380 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7381 | |
Douglas Gregor | 3c52a21 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7382 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7383 | E->getLocStart(), |
| 7384 | TInfo, |
| 7385 | E->getLocEnd()); |
| 7386 | } |
| 7387 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7388 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7389 | |
| 7390 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7391 | if (SubExpr.isInvalid()) |
| 7392 | return ExprError(); |
| 7393 | |
| 7394 | if (!getDerived().AlwaysRebuild() && |
| 7395 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7396 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7397 | |
| 7398 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7399 | E->getLocStart(), |
| 7400 | SubExpr.get(), |
| 7401 | E->getLocEnd()); |
| 7402 | } |
| 7403 | |
| 7404 | template<typename Derived> |
| 7405 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7406 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7407 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7409 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7410 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7411 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7412 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7413 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7414 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7415 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7416 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7417 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7418 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7419 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | cafeb94 | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 7420 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7421 | |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7422 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7423 | // Make sure that we capture 'this'. |
| 7424 | getSema().CheckCXXThisCapture(E->getLocStart()); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7425 | return SemaRef.Owned(E); |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7426 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7427 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7428 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7429 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7430 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7431 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7432 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7433 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7434 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7435 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7436 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7437 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7438 | if (!getDerived().AlwaysRebuild() && |
| 7439 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7440 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7441 | |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7442 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7443 | E->isThrownVariableInScope()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7444 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7445 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7446 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7447 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7448 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7449 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7450 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7451 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7452 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7453 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7454 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7455 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7456 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7457 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7458 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7459 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7461 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7462 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7463 | ExprResult |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 7464 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7465 | FieldDecl *Field |
| 7466 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7467 | E->getField())); |
| 7468 | if (!Field) |
| 7469 | return ExprError(); |
| 7470 | |
| 7471 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
| 7472 | return SemaRef.Owned(E); |
| 7473 | |
| 7474 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 7475 | } |
| 7476 | |
| 7477 | template<typename Derived> |
| 7478 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7479 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 7480 | CXXScalarValueInitExpr *E) { |
| 7481 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7482 | if (!T) |
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 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7485 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7486 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7487 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7488 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7489 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7490 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 7491 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7493 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7494 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7495 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7496 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7497 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7498 | TypeSourceInfo *AllocTypeInfo |
| 7499 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 7500 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7501 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7502 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7503 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7504 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7505 | if (ArraySize.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7506 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7507 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7508 | // Transform the placement arguments (if any). |
| 7509 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7510 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7511 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7512 | E->getNumPlacementArgs(), true, |
| 7513 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7514 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7515 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7516 | // Transform the initializer (if any). |
| 7517 | Expr *OldInit = E->getInitializer(); |
| 7518 | ExprResult NewInit; |
| 7519 | if (OldInit) |
| 7520 | NewInit = getDerived().TransformExpr(OldInit); |
| 7521 | if (NewInit.isInvalid()) |
| 7522 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7523 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7524 | // Transform new operator and delete operator. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7525 | FunctionDecl *OperatorNew = 0; |
| 7526 | if (E->getOperatorNew()) { |
| 7527 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7528 | getDerived().TransformDecl(E->getLocStart(), |
| 7529 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7530 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7531 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7532 | } |
| 7533 | |
| 7534 | FunctionDecl *OperatorDelete = 0; |
| 7535 | if (E->getOperatorDelete()) { |
| 7536 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7537 | getDerived().TransformDecl(E->getLocStart(), |
| 7538 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7539 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7540 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7541 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7542 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7543 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7544 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7545 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7546 | NewInit.get() == OldInit && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7547 | OperatorNew == E->getOperatorNew() && |
| 7548 | OperatorDelete == E->getOperatorDelete() && |
| 7549 | !ArgumentChanged) { |
| 7550 | // Mark any declarations we need as referenced. |
| 7551 | // FIXME: instantiation-specific. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7552 | if (OperatorNew) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7553 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7554 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7555 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7556 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7557 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7558 | QualType ElementType |
| 7559 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 7560 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 7561 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 7562 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7563 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7564 | } |
| 7565 | } |
| 7566 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7567 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7568 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7569 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7570 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7571 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7572 | if (!ArraySize.get()) { |
| 7573 | // If no array size was specified, but the new expression was |
| 7574 | // instantiated with an array type (e.g., "new T" where T is |
| 7575 | // instantiated with "int[4]"), extract the outer bound from the |
| 7576 | // array type as our array size. We do this with constant and |
| 7577 | // dependently-sized array types. |
| 7578 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 7579 | if (!ArrayT) { |
| 7580 | // Do nothing |
| 7581 | } else if (const ConstantArrayType *ConsArrayT |
| 7582 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7583 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7584 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7585 | ConsArrayT->getSize(), |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7586 | SemaRef.Context.getSizeType(), |
| 7587 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7588 | AllocType = ConsArrayT->getElementType(); |
| 7589 | } else if (const DependentSizedArrayType *DepArrayT |
| 7590 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 7591 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7592 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7593 | AllocType = DepArrayT->getElementType(); |
| 7594 | } |
| 7595 | } |
| 7596 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7597 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7598 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 7599 | E->isGlobalNew(), |
| 7600 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7601 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7602 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 7603 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7604 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7605 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7606 | ArraySize.get(), |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7607 | E->getDirectInitRange(), |
| 7608 | NewInit.take()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7610 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7611 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7612 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7613 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7614 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7615 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7616 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7617 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7618 | // Transform the delete operator, if known. |
| 7619 | FunctionDecl *OperatorDelete = 0; |
| 7620 | if (E->getOperatorDelete()) { |
| 7621 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7622 | getDerived().TransformDecl(E->getLocStart(), |
| 7623 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7624 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7625 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7626 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7628 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7629 | Operand.get() == E->getArgument() && |
| 7630 | OperatorDelete == E->getOperatorDelete()) { |
| 7631 | // Mark any declarations we need as referenced. |
| 7632 | // FIXME: instantiation-specific. |
| 7633 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7634 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7635 | |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7636 | if (!E->getArgument()->isTypeDependent()) { |
| 7637 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7638 | E->getDestroyedType()); |
| 7639 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7640 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7641 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7642 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7643 | } |
| 7644 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7645 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7646 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7647 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7648 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7649 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7650 | E->isGlobalDelete(), |
| 7651 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7652 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7653 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7654 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7655 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7656 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7657 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7658 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7659 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7660 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7661 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7662 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7663 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7664 | bool MayBePseudoDestructor = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7665 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7666 | E->getOperatorLoc(), |
| 7667 | E->isArrow()? tok::arrow : tok::period, |
| 7668 | ObjectTypePtr, |
| 7669 | MayBePseudoDestructor); |
| 7670 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7671 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7672 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7673 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7674 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7675 | if (QualifierLoc) { |
| 7676 | QualifierLoc |
| 7677 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7678 | if (!QualifierLoc) |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7679 | return ExprError(); |
| 7680 | } |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7681 | CXXScopeSpec SS; |
| 7682 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7683 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7684 | PseudoDestructorTypeStorage Destroyed; |
| 7685 | if (E->getDestroyedTypeInfo()) { |
| 7686 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7687 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7688 | ObjectType, 0, SS); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7689 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7690 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7691 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 7692 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7693 | // We aren't likely to be able to resolve the identifier down to a type |
| 7694 | // now anyway, so just retain the identifier. |
| 7695 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7696 | E->getDestroyedTypeLoc()); |
| 7697 | } else { |
| 7698 | // Look for a destructor known with the given name. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7699 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7700 | *E->getDestroyedTypeIdentifier(), |
| 7701 | E->getDestroyedTypeLoc(), |
| 7702 | /*Scope=*/0, |
| 7703 | SS, ObjectTypePtr, |
| 7704 | false); |
| 7705 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7706 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7707 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7708 | Destroyed |
| 7709 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7710 | E->getDestroyedTypeLoc()); |
| 7711 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7712 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7713 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7714 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 303b96f | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 7715 | CXXScopeSpec EmptySS; |
| 7716 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| 7717 | E->getScopeTypeInfo(), ObjectType, 0, EmptySS); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7718 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7719 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7720 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7721 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7722 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7723 | E->getOperatorLoc(), |
| 7724 | E->isArrow(), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7725 | SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7726 | ScopeTypeInfo, |
| 7727 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7728 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7729 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7730 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7731 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7732 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7733 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7734 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7735 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7736 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7737 | Sema::LookupOrdinaryName); |
| 7738 | |
| 7739 | // Transform all the decls. |
| 7740 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7741 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7742 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7743 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7744 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7745 | if (!InstD) { |
| 7746 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7747 | // This can happen because of dependent hiding. |
| 7748 | if (isa<UsingShadowDecl>(*I)) |
| 7749 | continue; |
| 7750 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7751 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7752 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7753 | |
| 7754 | // Expand using declarations. |
| 7755 | if (isa<UsingDecl>(InstD)) { |
| 7756 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7757 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7758 | E = UD->shadow_end(); I != E; ++I) |
| 7759 | R.addDecl(*I); |
| 7760 | continue; |
| 7761 | } |
| 7762 | |
| 7763 | R.addDecl(InstD); |
| 7764 | } |
| 7765 | |
| 7766 | // Resolve a kind, but don't do any further analysis. If it's |
| 7767 | // ambiguous, the callee needs to deal with it. |
| 7768 | R.resolveKind(); |
| 7769 | |
| 7770 | // Rebuild the nested-name qualifier, if present. |
| 7771 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7772 | if (Old->getQualifierLoc()) { |
| 7773 | NestedNameSpecifierLoc QualifierLoc |
| 7774 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7775 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7776 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7777 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7778 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7779 | } |
| 7780 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7781 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7782 | CXXRecordDecl *NamingClass |
| 7783 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7784 | Old->getNameLoc(), |
| 7785 | Old->getNamingClass())); |
| 7786 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7787 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7788 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7789 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7790 | } |
| 7791 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7792 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7793 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7794 | // If we have neither explicit template arguments, nor the template keyword, |
| 7795 | // it's a normal declaration name. |
| 7796 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7797 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7798 | |
| 7799 | // If we have template arguments, rebuild them, then rebuild the |
| 7800 | // templateid expression. |
| 7801 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 02e221b | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 7802 | if (Old->hasExplicitTemplateArgs() && |
| 7803 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7804 | Old->getNumTemplateArgs(), |
| 7805 | TransArgs)) |
| 7806 | return ExprError(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7807 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7808 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7809 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7810 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7811 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7812 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7813 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7814 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7815 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7816 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7817 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7818 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7819 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7820 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7821 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7822 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7823 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7824 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7825 | T, |
| 7826 | E->getLocEnd()); |
| 7827 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7829 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7830 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7831 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7832 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7833 | if (!LhsT) |
| 7834 | return ExprError(); |
| 7835 | |
| 7836 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7837 | if (!RhsT) |
| 7838 | return ExprError(); |
| 7839 | |
| 7840 | if (!getDerived().AlwaysRebuild() && |
| 7841 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7842 | return SemaRef.Owned(E); |
| 7843 | |
| 7844 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7845 | E->getLocStart(), |
| 7846 | LhsT, RhsT, |
| 7847 | E->getLocEnd()); |
| 7848 | } |
| 7849 | |
| 7850 | template<typename Derived> |
| 7851 | ExprResult |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7852 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 7853 | bool ArgChanged = false; |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7854 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7855 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 7856 | TypeSourceInfo *From = E->getArg(I); |
| 7857 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7858 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7859 | TypeLocBuilder TLB; |
| 7860 | TLB.reserve(FromTL.getFullDataSize()); |
| 7861 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 7862 | if (To.isNull()) |
| 7863 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7864 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7865 | if (To == From->getType()) |
| 7866 | Args.push_back(From); |
| 7867 | else { |
| 7868 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7869 | ArgChanged = true; |
| 7870 | } |
| 7871 | continue; |
| 7872 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7873 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7874 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7875 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7876 | // We have a pack expansion. Instantiate it. |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7877 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7878 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 7879 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7880 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7881 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7882 | // Determine whether the set of unexpanded parameter packs can and should |
| 7883 | // be expanded. |
| 7884 | bool Expand = true; |
| 7885 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 7886 | Optional<unsigned> OrigNumExpansions = |
| 7887 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 7888 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7889 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 7890 | PatternTL.getSourceRange(), |
| 7891 | Unexpanded, |
| 7892 | Expand, RetainExpansion, |
| 7893 | NumExpansions)) |
| 7894 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7895 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7896 | if (!Expand) { |
| 7897 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7898 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7899 | // expansion. |
| 7900 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7901 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7902 | TypeLocBuilder TLB; |
| 7903 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 7904 | |
| 7905 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7906 | if (To.isNull()) |
| 7907 | return ExprError(); |
| 7908 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7909 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7910 | PatternTL.getSourceRange(), |
| 7911 | ExpansionTL.getEllipsisLoc(), |
| 7912 | NumExpansions); |
| 7913 | if (To.isNull()) |
| 7914 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7915 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7916 | PackExpansionTypeLoc ToExpansionTL |
| 7917 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7918 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7919 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7920 | continue; |
| 7921 | } |
| 7922 | |
| 7923 | // Expand the pack expansion by substituting for each argument in the |
| 7924 | // pack(s). |
| 7925 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7926 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 7927 | TypeLocBuilder TLB; |
| 7928 | TLB.reserve(PatternTL.getFullDataSize()); |
| 7929 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7930 | if (To.isNull()) |
| 7931 | return ExprError(); |
| 7932 | |
Eli Friedman | 20cfeca | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 7933 | if (To->containsUnexpandedParameterPack()) { |
| 7934 | To = getDerived().RebuildPackExpansionType(To, |
| 7935 | PatternTL.getSourceRange(), |
| 7936 | ExpansionTL.getEllipsisLoc(), |
| 7937 | NumExpansions); |
| 7938 | if (To.isNull()) |
| 7939 | return ExprError(); |
| 7940 | |
| 7941 | PackExpansionTypeLoc ToExpansionTL |
| 7942 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7943 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7944 | } |
| 7945 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7946 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7947 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7948 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7949 | if (!RetainExpansion) |
| 7950 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7951 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7952 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 7953 | // forgetting the partially-substituted parameter pack. |
| 7954 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 7955 | |
| 7956 | TypeLocBuilder TLB; |
| 7957 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7958 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7959 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7960 | if (To.isNull()) |
| 7961 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7962 | |
| 7963 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7964 | PatternTL.getSourceRange(), |
| 7965 | ExpansionTL.getEllipsisLoc(), |
| 7966 | NumExpansions); |
| 7967 | if (To.isNull()) |
| 7968 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7969 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7970 | PackExpansionTypeLoc ToExpansionTL |
| 7971 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7972 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7973 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7974 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7975 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7976 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 7977 | return SemaRef.Owned(E); |
| 7978 | |
| 7979 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 7980 | E->getLocStart(), |
| 7981 | Args, |
| 7982 | E->getLocEnd()); |
| 7983 | } |
| 7984 | |
| 7985 | template<typename Derived> |
| 7986 | ExprResult |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 7987 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 7988 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7989 | if (!T) |
| 7990 | return ExprError(); |
| 7991 | |
| 7992 | if (!getDerived().AlwaysRebuild() && |
| 7993 | T == E->getQueriedTypeSourceInfo()) |
| 7994 | return SemaRef.Owned(E); |
| 7995 | |
| 7996 | ExprResult SubExpr; |
| 7997 | { |
| 7998 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7999 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 8000 | if (SubExpr.isInvalid()) |
| 8001 | return ExprError(); |
| 8002 | |
| 8003 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 8004 | return SemaRef.Owned(E); |
| 8005 | } |
| 8006 | |
| 8007 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 8008 | E->getLocStart(), |
| 8009 | T, |
| 8010 | SubExpr.get(), |
| 8011 | E->getLocEnd()); |
| 8012 | } |
| 8013 | |
| 8014 | template<typename Derived> |
| 8015 | ExprResult |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8016 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 8017 | ExprResult SubExpr; |
| 8018 | { |
| 8019 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8020 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 8021 | if (SubExpr.isInvalid()) |
| 8022 | return ExprError(); |
| 8023 | |
| 8024 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 8025 | return SemaRef.Owned(E); |
| 8026 | } |
| 8027 | |
| 8028 | return getDerived().RebuildExpressionTrait( |
| 8029 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 8030 | } |
| 8031 | |
| 8032 | template<typename Derived> |
| 8033 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8034 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8035 | DependentScopeDeclRefExpr *E) { |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8036 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false); |
| 8037 | } |
| 8038 | |
| 8039 | template<typename Derived> |
| 8040 | ExprResult |
| 8041 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8042 | DependentScopeDeclRefExpr *E, |
| 8043 | bool IsAddressOfOperand) { |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8044 | NestedNameSpecifierLoc QualifierLoc |
| 8045 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8046 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8047 | return ExprError(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8048 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8049 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8050 | // TODO: If this is a conversion-function-id, verify that the |
| 8051 | // destination type name (if present) resolves the same way after |
| 8052 | // instantiation as it did in the local scope. |
| 8053 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8054 | DeclarationNameInfo NameInfo |
| 8055 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 8056 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8057 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8058 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8059 | if (!E->hasExplicitTemplateArgs()) { |
| 8060 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8061 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8062 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 8063 | // if name has not changed, DNLoc has not changed either. |
| 8064 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8065 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8066 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8067 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8068 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8069 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8070 | /*TemplateArgs*/ 0, |
| 8071 | IsAddressOfOperand); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 8072 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8073 | |
| 8074 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8075 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8076 | E->getNumTemplateArgs(), |
| 8077 | TransArgs)) |
| 8078 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8079 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8080 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8081 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8082 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8083 | &TransArgs, |
| 8084 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8085 | } |
| 8086 | |
| 8087 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8088 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8089 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8090 | // CXXConstructExprs other than for list-initialization and |
| 8091 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 8092 | // a 1-argument construction we just transform that argument. |
Richard Smith | 73ed67c | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 8093 | if ((E->getNumArgs() == 1 || |
| 8094 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8095 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 8096 | !E->isListInitialization()) |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 8097 | return getDerived().TransformExpr(E->getArg(0)); |
| 8098 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8099 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 8100 | |
| 8101 | QualType T = getDerived().TransformType(E->getType()); |
| 8102 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8103 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8104 | |
| 8105 | CXXConstructorDecl *Constructor |
| 8106 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8107 | getDerived().TransformDecl(E->getLocStart(), |
| 8108 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8109 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8110 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8111 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8112 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8113 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8114 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8115 | &ArgumentChanged)) |
| 8116 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8117 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8118 | if (!getDerived().AlwaysRebuild() && |
| 8119 | T == E->getType() && |
| 8120 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8121 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8122 | // Mark the constructor as referenced. |
| 8123 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8124 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8125 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8127 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 8128 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 8129 | Constructor, E->isElidable(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8130 | Args, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 8131 | E->hadMultipleCandidates(), |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8132 | E->isListInitialization(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 8133 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 8134 | E->getConstructionKind(), |
| 8135 | E->getParenRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8137 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8138 | /// \brief Transform a C++ temporary-binding expression. |
| 8139 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8140 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 8141 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8142 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8143 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8144 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8145 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8146 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8147 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8148 | /// \brief Transform a C++ expression that contains cleanups that should |
| 8149 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8150 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8151 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8152 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8153 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8154 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8155 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8156 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8159 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8160 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8161 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8162 | CXXTemporaryObjectExpr *E) { |
| 8163 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8164 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8165 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8166 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8167 | CXXConstructorDecl *Constructor |
| 8168 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8169 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8170 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8171 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8172 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8173 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8174 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8175 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8176 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8177 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8178 | &ArgumentChanged)) |
| 8179 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8181 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8182 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8183 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8184 | !ArgumentChanged) { |
| 8185 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8186 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8187 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8188 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8189 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8190 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8191 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 8192 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8193 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8194 | E->getLocEnd()); |
| 8195 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8196 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8197 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8198 | ExprResult |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8199 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Faisal Vali | ecb5819 | 2013-08-22 01:49:11 +0000 | [diff] [blame] | 8200 | |
| 8201 | // FIXME: Implement nested generic lambda transformations. |
| 8202 | if (E->isGenericLambda()) { |
| 8203 | getSema().Diag(E->getIntroducerRange().getBegin(), |
| 8204 | diag::err_glambda_not_fully_implemented) |
| 8205 | << " nested lambdas not implemented yet"; |
| 8206 | return ExprError(); |
| 8207 | } |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8208 | // Transform the type of the lambda parameters and start the definition of |
| 8209 | // the lambda itself. |
| 8210 | TypeSourceInfo *MethodTy |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8211 | = TransformType(E->getCallOperator()->getTypeSourceInfo()); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8212 | if (!MethodTy) |
| 8213 | return ExprError(); |
| 8214 | |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8215 | // Create the local class that will describe the lambda. |
| 8216 | CXXRecordDecl *Class |
| 8217 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| 8218 | MethodTy, |
| 8219 | /*KnownDependent=*/false); |
| 8220 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 8221 | |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8222 | // Transform lambda parameters. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8223 | SmallVector<QualType, 4> ParamTypes; |
| 8224 | SmallVector<ParmVarDecl *, 4> Params; |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8225 | if (getDerived().TransformFunctionTypeParams(E->getLocStart(), |
| 8226 | E->getCallOperator()->param_begin(), |
| 8227 | E->getCallOperator()->param_size(), |
| 8228 | 0, ParamTypes, &Params)) |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8229 | return ExprError(); |
Faisal Vali | ecb5819 | 2013-08-22 01:49:11 +0000 | [diff] [blame] | 8230 | getSema().PushLambdaScope(); |
| 8231 | LambdaScopeInfo *LSI = getSema().getCurLambda(); |
| 8232 | // TODO: Fix for nested lambdas |
| 8233 | LSI->GLTemplateParameterList = 0; |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8234 | // Build the call operator. |
| 8235 | CXXMethodDecl *CallOperator |
| 8236 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8237 | MethodTy, |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8238 | E->getCallOperator()->getLocEnd(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8239 | Params); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8240 | getDerived().transformAttrs(E->getCallOperator(), CallOperator); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8241 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8242 | return getDerived().TransformLambdaScope(E, CallOperator); |
| 8243 | } |
| 8244 | |
| 8245 | template<typename Derived> |
| 8246 | ExprResult |
| 8247 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
| 8248 | CXXMethodDecl *CallOperator) { |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8249 | bool Invalid = false; |
| 8250 | |
| 8251 | // Transform any init-capture expressions before entering the scope of the |
| 8252 | // lambda. |
Robert Wilhelm | e7205c0 | 2013-08-10 12:33:24 +0000 | [diff] [blame] | 8253 | SmallVector<ExprResult, 8> InitCaptureExprs; |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8254 | InitCaptureExprs.resize(E->explicit_capture_end() - |
| 8255 | E->explicit_capture_begin()); |
| 8256 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 8257 | CEnd = E->capture_end(); |
| 8258 | C != CEnd; ++C) { |
| 8259 | if (!C->isInitCapture()) |
| 8260 | continue; |
| 8261 | InitCaptureExprs[C - E->capture_begin()] = |
| 8262 | getDerived().TransformExpr(E->getInitCaptureInit(C)); |
| 8263 | } |
| 8264 | |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8265 | // Introduce the context of the call operator. |
| 8266 | Sema::ContextRAII SavedContext(getSema(), CallOperator); |
| 8267 | |
Faisal Vali | ecb5819 | 2013-08-22 01:49:11 +0000 | [diff] [blame] | 8268 | LambdaScopeInfo *const LSI = getSema().getCurLambda(); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8269 | // Enter the scope of the lambda. |
Faisal Vali | ecb5819 | 2013-08-22 01:49:11 +0000 | [diff] [blame] | 8270 | getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8271 | E->getCaptureDefault(), |
James Dennett | f68af64 | 2013-08-09 23:08:25 +0000 | [diff] [blame] | 8272 | E->getCaptureDefaultLoc(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8273 | E->hasExplicitParameters(), |
| 8274 | E->hasExplicitResultType(), |
| 8275 | E->isMutable()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8276 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8277 | // Transform captures. |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8278 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8279 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8280 | CEnd = E->capture_end(); |
| 8281 | C != CEnd; ++C) { |
| 8282 | // When we hit the first implicit capture, tell Sema that we've finished |
| 8283 | // the list of explicit captures. |
| 8284 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 8285 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8286 | FinishedExplicitCaptures = true; |
| 8287 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8288 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8289 | // Capturing 'this' is trivial. |
| 8290 | if (C->capturesThis()) { |
| 8291 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 8292 | continue; |
| 8293 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8294 | |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8295 | // Rebuild init-captures, including the implied field declaration. |
| 8296 | if (C->isInitCapture()) { |
| 8297 | ExprResult Init = InitCaptureExprs[C - E->capture_begin()]; |
| 8298 | if (Init.isInvalid()) { |
| 8299 | Invalid = true; |
| 8300 | continue; |
| 8301 | } |
| 8302 | FieldDecl *OldFD = C->getInitCaptureField(); |
| 8303 | FieldDecl *NewFD = getSema().checkInitCapture( |
| 8304 | C->getLocation(), OldFD->getType()->isReferenceType(), |
| 8305 | OldFD->getIdentifier(), Init.take()); |
| 8306 | if (!NewFD) |
| 8307 | Invalid = true; |
| 8308 | else |
| 8309 | getDerived().transformedLocalDecl(OldFD, NewFD); |
| 8310 | continue; |
| 8311 | } |
| 8312 | |
| 8313 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 8314 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8315 | // Determine the capture kind for Sema. |
| 8316 | Sema::TryCaptureKind Kind |
| 8317 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 8318 | : C->getCaptureKind() == LCK_ByCopy |
| 8319 | ? Sema::TryCapture_ExplicitByVal |
| 8320 | : Sema::TryCapture_ExplicitByRef; |
| 8321 | SourceLocation EllipsisLoc; |
| 8322 | if (C->isPackExpansion()) { |
| 8323 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 8324 | bool ShouldExpand = false; |
| 8325 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8326 | Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8327 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 8328 | C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8329 | Unexpanded, |
| 8330 | ShouldExpand, RetainExpansion, |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8331 | NumExpansions)) { |
| 8332 | Invalid = true; |
| 8333 | continue; |
| 8334 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8335 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8336 | if (ShouldExpand) { |
| 8337 | // The transform has determined that we should perform an expansion; |
| 8338 | // transform and capture each of the arguments. |
| 8339 | // expansion of the pattern. Do so. |
| 8340 | VarDecl *Pack = C->getCapturedVar(); |
| 8341 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8342 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8343 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8344 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8345 | Pack)); |
| 8346 | if (!CapturedVar) { |
| 8347 | Invalid = true; |
| 8348 | continue; |
| 8349 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8350 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8351 | // Capture the transformed variable. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8352 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 8353 | } |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8354 | continue; |
| 8355 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8356 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8357 | EllipsisLoc = C->getEllipsisLoc(); |
| 8358 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8359 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8360 | // Transform the captured variable. |
| 8361 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8362 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8363 | C->getCapturedVar())); |
| 8364 | if (!CapturedVar) { |
| 8365 | Invalid = true; |
| 8366 | continue; |
| 8367 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8368 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8369 | // Capture the transformed variable. |
Douglas Gregor | 999713e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 8370 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8371 | } |
| 8372 | if (!FinishedExplicitCaptures) |
| 8373 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8374 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8375 | |
| 8376 | // Enter a new evaluation context to insulate the lambda from any |
| 8377 | // cleanups from the enclosing full-expression. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8378 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8379 | |
| 8380 | if (Invalid) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8381 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8382 | /*IsInstantiation=*/true); |
| 8383 | return ExprError(); |
| 8384 | } |
| 8385 | |
| 8386 | // Instantiate the body of the lambda expression. |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8387 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 8388 | if (Body.isInvalid()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8389 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8390 | /*IsInstantiation=*/true); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8391 | return ExprError(); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8392 | } |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 8393 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8394 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 8395 | /*CurScope=*/0, /*IsInstantiation=*/true); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8396 | } |
| 8397 | |
| 8398 | template<typename Derived> |
| 8399 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8400 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8401 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8402 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8403 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8404 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8405 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8406 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8407 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8408 | Args.reserve(E->arg_size()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8409 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8410 | &ArgumentChanged)) |
| 8411 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8412 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8413 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8414 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8415 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8416 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8417 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8418 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8419 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8420 | E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8421 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8422 | E->getRParenLoc()); |
| 8423 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8424 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8425 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8426 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8427 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8428 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8429 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8430 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8431 | Expr *OldBase; |
| 8432 | QualType BaseType; |
| 8433 | QualType ObjectType; |
| 8434 | if (!E->isImplicitAccess()) { |
| 8435 | OldBase = E->getBase(); |
| 8436 | Base = getDerived().TransformExpr(OldBase); |
| 8437 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8438 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8439 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8440 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8441 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8442 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8443 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8444 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8445 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8446 | ObjectTy, |
| 8447 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8448 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8449 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8450 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8451 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8452 | BaseType = ((Expr*) Base.get())->getType(); |
| 8453 | } else { |
| 8454 | OldBase = 0; |
| 8455 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 8456 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 8457 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8458 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8459 | // Transform the first part of the nested-name-specifier that qualifies |
| 8460 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 8461 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8462 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8463 | E->getFirstQualifierFoundInScope(), |
| 8464 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8465 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8466 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8467 | if (E->getQualifier()) { |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8468 | QualifierLoc |
| 8469 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 8470 | ObjectType, |
| 8471 | FirstQualifierInScope); |
| 8472 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8473 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8474 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8475 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8476 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 8477 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8478 | // TODO: If this is a conversion-function-id, verify that the |
| 8479 | // destination type name (if present) resolves the same way after |
| 8480 | // instantiation as it did in the local scope. |
| 8481 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8482 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8483 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8484 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8485 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8486 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8487 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8488 | // This is a reference to a member without an explicitly-specified |
| 8489 | // template argument list. Optimize for this common case. |
| 8490 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8491 | Base.get() == OldBase && |
| 8492 | BaseType == E->getBaseType() && |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8493 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8494 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8495 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8496 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8497 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8498 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8499 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8500 | E->isArrow(), |
| 8501 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8502 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8503 | TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8504 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8505 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8506 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8507 | } |
| 8508 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8509 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8510 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8511 | E->getNumTemplateArgs(), |
| 8512 | TransArgs)) |
| 8513 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8514 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8515 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8516 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8517 | E->isArrow(), |
| 8518 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8519 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8520 | TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8521 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8522 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8523 | &TransArgs); |
| 8524 | } |
| 8525 | |
| 8526 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8527 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8528 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8529 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8530 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8531 | QualType BaseType; |
| 8532 | if (!Old->isImplicitAccess()) { |
| 8533 | Base = getDerived().TransformExpr(Old->getBase()); |
| 8534 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8535 | return ExprError(); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 8536 | Base = getSema().PerformMemberExprBaseConversion(Base.take(), |
| 8537 | Old->isArrow()); |
| 8538 | if (Base.isInvalid()) |
| 8539 | return ExprError(); |
| 8540 | BaseType = Base.get()->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8541 | } else { |
| 8542 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 8543 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8544 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8545 | NestedNameSpecifierLoc QualifierLoc; |
| 8546 | if (Old->getQualifierLoc()) { |
| 8547 | QualifierLoc |
| 8548 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8549 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8550 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8551 | } |
| 8552 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8553 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8554 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8555 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8556 | Sema::LookupOrdinaryName); |
| 8557 | |
| 8558 | // Transform all the decls. |
| 8559 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 8560 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8561 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8562 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 8563 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8564 | if (!InstD) { |
| 8565 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8566 | // This can happen because of dependent hiding. |
| 8567 | if (isa<UsingShadowDecl>(*I)) |
| 8568 | continue; |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8569 | else { |
| 8570 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8571 | return ExprError(); |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8572 | } |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8573 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8574 | |
| 8575 | // Expand using declarations. |
| 8576 | if (isa<UsingDecl>(InstD)) { |
| 8577 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 8578 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 8579 | E = UD->shadow_end(); I != E; ++I) |
| 8580 | R.addDecl(*I); |
| 8581 | continue; |
| 8582 | } |
| 8583 | |
| 8584 | R.addDecl(InstD); |
| 8585 | } |
| 8586 | |
| 8587 | R.resolveKind(); |
| 8588 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8589 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 8590 | if (Old->getNamingClass()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8591 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8592 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8593 | Old->getMemberLoc(), |
| 8594 | Old->getNamingClass())); |
| 8595 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8596 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8597 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8598 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8599 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8600 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8601 | TemplateArgumentListInfo TransArgs; |
| 8602 | if (Old->hasExplicitTemplateArgs()) { |
| 8603 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 8604 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8605 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 8606 | Old->getNumTemplateArgs(), |
| 8607 | TransArgs)) |
| 8608 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8609 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8610 | |
| 8611 | // FIXME: to do this check properly, we will need to preserve the |
| 8612 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8613 | // base (and therefore couldn't do the check) and a |
| 8614 | // nested-name-qualifier (and therefore could do the lookup). |
| 8615 | NamedDecl *FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8616 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8617 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8618 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8619 | Old->getOperatorLoc(), |
| 8620 | Old->isArrow(), |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8621 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8622 | TemplateKWLoc, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8623 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8624 | R, |
| 8625 | (Old->hasExplicitTemplateArgs() |
| 8626 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8627 | } |
| 8628 | |
| 8629 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8630 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8631 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Sean Hunt | eea06c6 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 8632 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8633 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 8634 | if (SubExpr.isInvalid()) |
| 8635 | return ExprError(); |
| 8636 | |
| 8637 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8638 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8639 | |
| 8640 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 8641 | } |
| 8642 | |
| 8643 | template<typename Derived> |
| 8644 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8645 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8646 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 8647 | if (Pattern.isInvalid()) |
| 8648 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8649 | |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8650 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 8651 | return SemaRef.Owned(E); |
| 8652 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 8653 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 8654 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8655 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8656 | |
| 8657 | template<typename Derived> |
| 8658 | ExprResult |
| 8659 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 8660 | // If E is not value-dependent, then nothing will change when we transform it. |
| 8661 | // Note: This is an instantiation-centric view. |
| 8662 | if (!E->isValueDependent()) |
| 8663 | return SemaRef.Owned(E); |
| 8664 | |
| 8665 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 8666 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8667 | // so |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8668 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 8669 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8670 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8671 | Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8672 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 8673 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8674 | ShouldExpand, RetainExpansion, |
| 8675 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8676 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8677 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8678 | if (RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8679 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8680 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8681 | NamedDecl *Pack = E->getPack(); |
| 8682 | if (!ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8683 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8684 | Pack)); |
| 8685 | if (!Pack) |
| 8686 | return ExprError(); |
| 8687 | } |
| 8688 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8689 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8690 | // We now know the length of the parameter pack, so build a new expression |
| 8691 | // that stores that length. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8692 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 8693 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8694 | NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8695 | } |
| 8696 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8697 | template<typename Derived> |
| 8698 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 8699 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 8700 | SubstNonTypeTemplateParmPackExpr *E) { |
| 8701 | // Default behavior is to do nothing with this transformation. |
| 8702 | return SemaRef.Owned(E); |
| 8703 | } |
| 8704 | |
| 8705 | template<typename Derived> |
| 8706 | ExprResult |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 8707 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 8708 | SubstNonTypeTemplateParmExpr *E) { |
| 8709 | // Default behavior is to do nothing with this transformation. |
| 8710 | return SemaRef.Owned(E); |
| 8711 | } |
| 8712 | |
| 8713 | template<typename Derived> |
| 8714 | ExprResult |
Richard Smith | 9a4db03 | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 8715 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 8716 | // Default behavior is to do nothing with this transformation. |
| 8717 | return SemaRef.Owned(E); |
| 8718 | } |
| 8719 | |
| 8720 | template<typename Derived> |
| 8721 | ExprResult |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8722 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 8723 | MaterializeTemporaryExpr *E) { |
| 8724 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 8725 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8726 | |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8727 | template<typename Derived> |
| 8728 | ExprResult |
Richard Smith | 7c3e615 | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 8729 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 8730 | CXXStdInitializerListExpr *E) { |
| 8731 | return getDerived().TransformExpr(E->getSubExpr()); |
| 8732 | } |
| 8733 | |
| 8734 | template<typename Derived> |
| 8735 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8736 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8737 | return SemaRef.MaybeBindToTemporary(E); |
| 8738 | } |
| 8739 | |
| 8740 | template<typename Derived> |
| 8741 | ExprResult |
| 8742 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Jordy Rose | d8b5ca1 | 2012-03-12 17:53:02 +0000 | [diff] [blame] | 8743 | return SemaRef.Owned(E); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8744 | } |
| 8745 | |
| 8746 | template<typename Derived> |
| 8747 | ExprResult |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 8748 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 8749 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 8750 | if (SubExpr.isInvalid()) |
| 8751 | return ExprError(); |
| 8752 | |
| 8753 | if (!getDerived().AlwaysRebuild() && |
| 8754 | SubExpr.get() == E->getSubExpr()) |
| 8755 | return SemaRef.Owned(E); |
| 8756 | |
| 8757 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8758 | } |
| 8759 | |
| 8760 | template<typename Derived> |
| 8761 | ExprResult |
| 8762 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 8763 | // Transform each of the elements. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8764 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8765 | bool ArgChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8766 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8767 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 8768 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8769 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8770 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8771 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8772 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8773 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 8774 | Elements.data(), |
| 8775 | Elements.size()); |
| 8776 | } |
| 8777 | |
| 8778 | template<typename Derived> |
| 8779 | ExprResult |
| 8780 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8781 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8782 | // Transform each of the elements. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8783 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8784 | bool ArgChanged = false; |
| 8785 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 8786 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8787 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8788 | if (OrigElement.isPackExpansion()) { |
| 8789 | // This key/value element is a pack expansion. |
| 8790 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8791 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 8792 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 8793 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 8794 | |
| 8795 | // Determine whether the set of unexpanded parameter packs can |
| 8796 | // and should be expanded. |
| 8797 | bool Expand = true; |
| 8798 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8799 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 8800 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8801 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 8802 | OrigElement.Value->getLocEnd()); |
| 8803 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 8804 | PatternRange, |
| 8805 | Unexpanded, |
| 8806 | Expand, RetainExpansion, |
| 8807 | NumExpansions)) |
| 8808 | return ExprError(); |
| 8809 | |
| 8810 | if (!Expand) { |
| 8811 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8812 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8813 | // expansion. |
| 8814 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 8815 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8816 | if (Key.isInvalid()) |
| 8817 | return ExprError(); |
| 8818 | |
| 8819 | if (Key.get() != OrigElement.Key) |
| 8820 | ArgChanged = true; |
| 8821 | |
| 8822 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8823 | if (Value.isInvalid()) |
| 8824 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8825 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8826 | if (Value.get() != OrigElement.Value) |
| 8827 | ArgChanged = true; |
| 8828 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8829 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8830 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 8831 | }; |
| 8832 | Elements.push_back(Expansion); |
| 8833 | continue; |
| 8834 | } |
| 8835 | |
| 8836 | // Record right away that the argument was changed. This needs |
| 8837 | // to happen even if the array expands to nothing. |
| 8838 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8839 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8840 | // The transform has determined that we should perform an elementwise |
| 8841 | // expansion of the pattern. Do so. |
| 8842 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8843 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8844 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8845 | if (Key.isInvalid()) |
| 8846 | return ExprError(); |
| 8847 | |
| 8848 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8849 | if (Value.isInvalid()) |
| 8850 | return ExprError(); |
| 8851 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8852 | ObjCDictionaryElement Element = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8853 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 8854 | }; |
| 8855 | |
| 8856 | // If any unexpanded parameter packs remain, we still have a |
| 8857 | // pack expansion. |
| 8858 | if (Key.get()->containsUnexpandedParameterPack() || |
| 8859 | Value.get()->containsUnexpandedParameterPack()) |
| 8860 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8861 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8862 | Elements.push_back(Element); |
| 8863 | } |
| 8864 | |
| 8865 | // We've finished with this pack expansion. |
| 8866 | continue; |
| 8867 | } |
| 8868 | |
| 8869 | // Transform and check key. |
| 8870 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8871 | if (Key.isInvalid()) |
| 8872 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8873 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8874 | if (Key.get() != OrigElement.Key) |
| 8875 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8876 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8877 | // Transform and check value. |
| 8878 | ExprResult Value |
| 8879 | = getDerived().TransformExpr(OrigElement.Value); |
| 8880 | if (Value.isInvalid()) |
| 8881 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8882 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8883 | if (Value.get() != OrigElement.Value) |
| 8884 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8885 | |
| 8886 | ObjCDictionaryElement Element = { |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 8887 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8888 | }; |
| 8889 | Elements.push_back(Element); |
| 8890 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8891 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8892 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8893 | return SemaRef.MaybeBindToTemporary(E); |
| 8894 | |
| 8895 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 8896 | Elements.data(), |
| 8897 | Elements.size()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8898 | } |
| 8899 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8900 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8901 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8902 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8903 | TypeSourceInfo *EncodedTypeInfo |
| 8904 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 8905 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8906 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8907 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8908 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8909 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8910 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8911 | |
| 8912 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8913 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8914 | E->getRParenLoc()); |
| 8915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8916 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8917 | template<typename Derived> |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8918 | ExprResult TreeTransform<Derived>:: |
| 8919 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | 93b6457 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 8920 | // This is a kind of implicit conversion, and it needs to get dropped |
| 8921 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 8922 | // do, as well a more specific one: this expression is only valid when |
| 8923 | // it appears *immediately* as an argument expression. |
| 8924 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8925 | } |
| 8926 | |
| 8927 | template<typename Derived> |
| 8928 | ExprResult TreeTransform<Derived>:: |
| 8929 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8930 | TypeSourceInfo *TSInfo |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8931 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8932 | if (!TSInfo) |
| 8933 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8934 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8935 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8936 | if (Result.isInvalid()) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8937 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8938 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8939 | if (!getDerived().AlwaysRebuild() && |
| 8940 | TSInfo == E->getTypeInfoAsWritten() && |
| 8941 | Result.get() == E->getSubExpr()) |
| 8942 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8943 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8944 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8945 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8946 | Result.get()); |
| 8947 | } |
| 8948 | |
| 8949 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8950 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8951 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8952 | // Transform arguments. |
| 8953 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8954 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8955 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8956 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8957 | &ArgChanged)) |
| 8958 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8959 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8960 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 8961 | // Class message: transform the receiver type. |
| 8962 | TypeSourceInfo *ReceiverTypeInfo |
| 8963 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 8964 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8965 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8966 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8967 | // If nothing changed, just retain the existing message send. |
| 8968 | if (!getDerived().AlwaysRebuild() && |
| 8969 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8970 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8971 | |
| 8972 | // Build a new class message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8973 | SmallVector<SourceLocation, 16> SelLocs; |
| 8974 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8975 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 8976 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8977 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8978 | E->getMethodDecl(), |
| 8979 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8980 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8981 | E->getRightLoc()); |
| 8982 | } |
| 8983 | |
| 8984 | // Instance message: transform the receiver |
| 8985 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 8986 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8987 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8988 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 8989 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8990 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8991 | |
| 8992 | // If nothing changed, just retain the existing message send. |
| 8993 | if (!getDerived().AlwaysRebuild() && |
| 8994 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8995 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8996 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8997 | // Build a new instance message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8998 | SmallVector<SourceLocation, 16> SelLocs; |
| 8999 | E->getSelectorLocs(SelLocs); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9000 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9001 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9002 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9003 | E->getMethodDecl(), |
| 9004 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9005 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9006 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9007 | } |
| 9008 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9009 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9010 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9011 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9012 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9013 | } |
| 9014 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9015 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9016 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9017 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9018 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9019 | } |
| 9020 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9021 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9022 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9023 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9024 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9025 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9026 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9027 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9028 | |
| 9029 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9030 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9031 | // If nothing changed, just retain the existing expression. |
| 9032 | if (!getDerived().AlwaysRebuild() && |
| 9033 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9034 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9035 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9036 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9037 | E->getLocation(), |
| 9038 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9039 | } |
| 9040 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9041 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9042 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9043 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9044 | // 'super' and types never change. Property never changes. Just |
| 9045 | // retain the existing expression. |
| 9046 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9047 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9048 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9049 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9050 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9051 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9052 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9053 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9054 | // We don't need to transform the property; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9055 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9056 | // If nothing changed, just retain the existing expression. |
| 9057 | if (!getDerived().AlwaysRebuild() && |
| 9058 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9059 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9060 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9061 | if (E->isExplicitProperty()) |
| 9062 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 9063 | E->getExplicitProperty(), |
| 9064 | E->getLocation()); |
| 9065 | |
| 9066 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 9067 | SemaRef.Context.PseudoObjectTy, |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9068 | E->getImplicitPropertyGetter(), |
| 9069 | E->getImplicitPropertySetter(), |
| 9070 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9071 | } |
| 9072 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9073 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9074 | ExprResult |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9075 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 9076 | // Transform the base expression. |
| 9077 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 9078 | if (Base.isInvalid()) |
| 9079 | return ExprError(); |
| 9080 | |
| 9081 | // Transform the key expression. |
| 9082 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 9083 | if (Key.isInvalid()) |
| 9084 | return ExprError(); |
| 9085 | |
| 9086 | // If nothing changed, just retain the existing expression. |
| 9087 | if (!getDerived().AlwaysRebuild() && |
| 9088 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 9089 | return SemaRef.Owned(E); |
| 9090 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9091 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9092 | Base.get(), Key.get(), |
| 9093 | E->getAtIndexMethodDecl(), |
| 9094 | E->setAtIndexMethodDecl()); |
| 9095 | } |
| 9096 | |
| 9097 | template<typename Derived> |
| 9098 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9099 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9100 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9101 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9102 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9103 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9104 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9105 | // If nothing changed, just retain the existing expression. |
| 9106 | if (!getDerived().AlwaysRebuild() && |
| 9107 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9108 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9109 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9110 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 9111 | E->getOpLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9112 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9113 | } |
| 9114 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9115 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9116 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9117 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9118 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9119 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9120 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9121 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9122 | SubExprs, &ArgumentChanged)) |
| 9123 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9124 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9125 | if (!getDerived().AlwaysRebuild() && |
| 9126 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9127 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9128 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9129 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9130 | SubExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9131 | E->getRParenLoc()); |
| 9132 | } |
| 9133 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9134 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9135 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9136 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9137 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9138 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9139 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 9140 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 9141 | |
| 9142 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 0586520 | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 9143 | blockScope->TheDecl->setBlockMissingReturnType( |
| 9144 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9145 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9146 | SmallVector<ParmVarDecl*, 4> params; |
| 9147 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9148 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 9149 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9150 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 9151 | oldBlock->param_begin(), |
| 9152 | oldBlock->param_size(), |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9153 | 0, paramTypes, ¶ms)) { |
| 9154 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9155 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9156 | } |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9157 | |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9158 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9159 | QualType exprResultType = |
| 9160 | getDerived().TransformType(exprFunctionType->getResultType()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 9161 | |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9162 | QualType functionType = |
| 9163 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9164 | exprFunctionType->getExtProtoInfo()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9165 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9166 | |
| 9167 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9168 | if (!params.empty()) |
David Blaikie | 4278c65 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 9169 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9170 | |
| 9171 | if (!oldBlock->blockMissingReturnType()) { |
| 9172 | blockScope->HasImplicitReturnType = false; |
| 9173 | blockScope->ReturnType = exprResultType; |
| 9174 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9175 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9176 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9177 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9178 | if (body.isInvalid()) { |
| 9179 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9180 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9181 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9182 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9183 | #ifndef NDEBUG |
| 9184 | // In builds with assertions, make sure that we captured everything we |
| 9185 | // captured before. |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9186 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 9187 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 9188 | e = oldBlock->capture_end(); i != e; ++i) { |
| 9189 | VarDecl *oldCapture = i->getVariable(); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9190 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9191 | // Ignore parameter packs. |
| 9192 | if (isa<ParmVarDecl>(oldCapture) && |
| 9193 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 9194 | continue; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9195 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9196 | VarDecl *newCapture = |
| 9197 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 9198 | oldCapture)); |
| 9199 | assert(blockScope->CaptureMap.count(newCapture)); |
| 9200 | } |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 9201 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9202 | } |
| 9203 | #endif |
| 9204 | |
| 9205 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 9206 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9207 | } |
| 9208 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9209 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9210 | ExprResult |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9211 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 9212 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9213 | } |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9214 | |
| 9215 | template<typename Derived> |
| 9216 | ExprResult |
| 9217 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9218 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 9219 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9220 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9221 | SubExprs.reserve(E->getNumSubExprs()); |
| 9222 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 9223 | SubExprs, &ArgumentChanged)) |
| 9224 | return ExprError(); |
| 9225 | |
| 9226 | if (!getDerived().AlwaysRebuild() && |
| 9227 | !ArgumentChanged) |
| 9228 | return SemaRef.Owned(E); |
| 9229 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9230 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9231 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9232 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9233 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9234 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9235 | // Type reconstruction |
| 9236 | //===----------------------------------------------------------------------===// |
| 9237 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9238 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9239 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 9240 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9241 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9242 | getDerived().getBaseEntity()); |
| 9243 | } |
| 9244 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9245 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9246 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 9247 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9248 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9249 | getDerived().getBaseEntity()); |
| 9250 | } |
| 9251 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9252 | template<typename Derived> |
| 9253 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9254 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 9255 | bool WrittenAsLValue, |
| 9256 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9257 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9258 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9259 | } |
| 9260 | |
| 9261 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9262 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9263 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 9264 | QualType ClassType, |
| 9265 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9266 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9267 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9268 | } |
| 9269 | |
| 9270 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9271 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9272 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 9273 | ArrayType::ArraySizeModifier SizeMod, |
| 9274 | const llvm::APInt *Size, |
| 9275 | Expr *SizeExpr, |
| 9276 | unsigned IndexTypeQuals, |
| 9277 | SourceRange BracketsRange) { |
| 9278 | if (SizeExpr || !Size) |
| 9279 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 9280 | IndexTypeQuals, BracketsRange, |
| 9281 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9282 | |
| 9283 | QualType Types[] = { |
| 9284 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 9285 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 9286 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9287 | }; |
Craig Topper | b960232 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 9288 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9289 | QualType SizeType; |
| 9290 | for (unsigned I = 0; I != NumTypes; ++I) |
| 9291 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 9292 | SizeType = Types[I]; |
| 9293 | break; |
| 9294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9295 | |
Eli Friedman | 01f276d | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 9296 | // Note that we can return a VariableArrayType here in the case where |
| 9297 | // the element type was a dependent VariableArrayType. |
| 9298 | IntegerLiteral *ArraySize |
| 9299 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 9300 | /*FIXME*/BracketsRange.getBegin()); |
| 9301 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9302 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9303 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9305 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9306 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9307 | QualType |
| 9308 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9309 | ArrayType::ArraySizeModifier SizeMod, |
| 9310 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9311 | unsigned IndexTypeQuals, |
| 9312 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9313 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9314 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9315 | } |
| 9316 | |
| 9317 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9318 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9319 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9320 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9321 | unsigned IndexTypeQuals, |
| 9322 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9323 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9324 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9325 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9326 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9327 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9328 | QualType |
| 9329 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9330 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9331 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9332 | unsigned IndexTypeQuals, |
| 9333 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9334 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9335 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9336 | IndexTypeQuals, BracketsRange); |
| 9337 | } |
| 9338 | |
| 9339 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9340 | QualType |
| 9341 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9342 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9343 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9344 | unsigned IndexTypeQuals, |
| 9345 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9346 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9347 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9348 | IndexTypeQuals, BracketsRange); |
| 9349 | } |
| 9350 | |
| 9351 | template<typename Derived> |
| 9352 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9353 | unsigned NumElements, |
| 9354 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9355 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9356 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9357 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9358 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9359 | template<typename Derived> |
| 9360 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 9361 | unsigned NumElements, |
| 9362 | SourceLocation AttributeLoc) { |
| 9363 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 9364 | NumElements, true); |
| 9365 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 9366 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 9367 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9368 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9369 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9370 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9371 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9372 | QualType |
| 9373 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9374 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9375 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9376 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9377 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9378 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9379 | template<typename Derived> |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9380 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 9381 | QualType T, |
| 9382 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9383 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 9384 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9385 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9386 | getDerived().getBaseEntity(), |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9387 | EPI); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9389 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9390 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 9391 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 9392 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 9393 | } |
| 9394 | |
| 9395 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9396 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 9397 | assert(D && "no decl found"); |
| 9398 | if (D->isInvalidDecl()) return QualType(); |
| 9399 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9400 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9401 | TypeDecl *Ty; |
| 9402 | if (isa<UsingDecl>(D)) { |
| 9403 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 9404 | assert(Using->hasTypename() && |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9405 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 9406 | |
| 9407 | // A valid resolved using typename decl points to exactly one type decl. |
| 9408 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 9409 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9410 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9411 | } else { |
| 9412 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 9413 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 9414 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 9415 | } |
| 9416 | |
| 9417 | return SemaRef.Context.getTypeDeclType(Ty); |
| 9418 | } |
| 9419 | |
| 9420 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9421 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 9422 | SourceLocation Loc) { |
| 9423 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9424 | } |
| 9425 | |
| 9426 | template<typename Derived> |
| 9427 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 9428 | return SemaRef.Context.getTypeOfType(Underlying); |
| 9429 | } |
| 9430 | |
| 9431 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9432 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 9433 | SourceLocation Loc) { |
| 9434 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9435 | } |
| 9436 | |
| 9437 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 9438 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 9439 | UnaryTransformType::UTTKind UKind, |
| 9440 | SourceLocation Loc) { |
| 9441 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 9442 | } |
| 9443 | |
| 9444 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9445 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 9446 | TemplateName Template, |
| 9447 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 9448 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9449 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9450 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9451 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 9452 | template<typename Derived> |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 9453 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 9454 | SourceLocation KWLoc) { |
| 9455 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 9456 | } |
| 9457 | |
| 9458 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9459 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9460 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9461 | bool TemplateKW, |
| 9462 | TemplateDecl *Template) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9463 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9464 | Template); |
| 9465 | } |
| 9466 | |
| 9467 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9468 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9469 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 9470 | const IdentifierInfo &Name, |
| 9471 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9472 | QualType ObjectType, |
| 9473 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9474 | UnqualifiedId TemplateName; |
| 9475 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9476 | Sema::TemplateTy Template; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9477 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9478 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9479 | SS, TemplateKWLoc, TemplateName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9480 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9481 | /*EnteringContext=*/false, |
| 9482 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9483 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9484 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9485 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9486 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9487 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9488 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9489 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9490 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9491 | QualType ObjectType) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9492 | UnqualifiedId Name; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9493 | // FIXME: Bogus location information. |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9494 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9495 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9496 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9497 | Sema::TemplateTy Template; |
| 9498 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9499 | SS, TemplateKWLoc, Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9500 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9501 | /*EnteringContext=*/false, |
| 9502 | Template); |
| 9503 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9504 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9505 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9506 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9507 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9508 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 9509 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9510 | Expr *OrigCallee, |
| 9511 | Expr *First, |
| 9512 | Expr *Second) { |
| 9513 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 9514 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9515 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9516 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9517 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9518 | if (!First->getType()->isOverloadableType() && |
| 9519 | !Second->getType()->isOverloadableType()) |
| 9520 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 9521 | Callee->getLocStart(), |
| 9522 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 9523 | } else if (Op == OO_Arrow) { |
| 9524 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9525 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 9526 | } else if (Second == 0 || isPostIncDec) { |
| 9527 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9528 | // The argument is not of overloadable type, so try to create a |
| 9529 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9530 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9531 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9532 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9533 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9534 | } |
| 9535 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9536 | if (!First->getType()->isOverloadableType() && |
| 9537 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9538 | // Neither of the arguments is an overloadable type, so try to |
| 9539 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9540 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9541 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9542 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9543 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9544 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9545 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9546 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9547 | } |
| 9548 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9549 | |
| 9550 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9551 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9552 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9553 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9554 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9555 | assert(ULE->requiresADL()); |
| 9556 | |
| 9557 | // FIXME: Do we have to check |
| 9558 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9559 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9560 | } else { |
Richard Smith | f641166 | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 9561 | // If we've resolved this to a particular non-member function, just call |
| 9562 | // that function. If we resolved it to a member function, |
| 9563 | // CreateOverloaded* will find that function for us. |
| 9564 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 9565 | if (!isa<CXXMethodDecl>(ND)) |
| 9566 | Functions.addDecl(ND); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9567 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9568 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9569 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9570 | Expr *Args[2] = { First, Second }; |
| 9571 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9572 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9573 | // Create the overloaded operator invocation for unary operators. |
| 9574 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9575 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9576 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9577 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9578 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9579 | |
Douglas Gregor | 5b8968c | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 9580 | if (Op == OO_Subscript) { |
| 9581 | SourceLocation LBrace; |
| 9582 | SourceLocation RBrace; |
| 9583 | |
| 9584 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 9585 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 9586 | LBrace = SourceLocation::getFromRawEncoding( |
| 9587 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 9588 | RBrace = SourceLocation::getFromRawEncoding( |
| 9589 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 9590 | } else { |
| 9591 | LBrace = Callee->getLocStart(); |
| 9592 | RBrace = OpLoc; |
| 9593 | } |
| 9594 | |
| 9595 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 9596 | First, Second); |
| 9597 | } |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9598 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9599 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9600 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9601 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9602 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 9603 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9604 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9605 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9606 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9608 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9609 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9610 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9611 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9612 | SourceLocation OperatorLoc, |
| 9613 | bool isArrow, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9614 | CXXScopeSpec &SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9615 | TypeSourceInfo *ScopeType, |
| 9616 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9617 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9618 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9619 | QualType BaseType = Base->getType(); |
| 9620 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9621 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9622 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 9623 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 9624 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9625 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9626 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9627 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9628 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9629 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9630 | /*FIXME?*/true); |
| 9631 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9632 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9633 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9634 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 9635 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 9636 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 9637 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 9638 | |
Richard Smith | 6314db9 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 9639 | // The scope type is now known to be a valid nested name specifier |
| 9640 | // component. Tack it on to the end of the nested name specifier. |
| 9641 | if (ScopeType) |
| 9642 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 9643 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9644 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9645 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9646 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9647 | OperatorLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9648 | SS, TemplateKWLoc, |
| 9649 | /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9650 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9651 | /*TemplateArgs*/ 0); |
| 9652 | } |
| 9653 | |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9654 | template<typename Derived> |
| 9655 | StmtResult |
| 9656 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 9657 | SourceLocation Loc = S->getLocStart(); |
| 9658 | unsigned NumParams = S->getCapturedDecl()->getNumParams(); |
| 9659 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0, |
| 9660 | S->getCapturedRegionKind(), NumParams); |
| 9661 | StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 9662 | |
| 9663 | if (Body.isInvalid()) { |
| 9664 | getSema().ActOnCapturedRegionError(); |
| 9665 | return StmtError(); |
| 9666 | } |
| 9667 | |
| 9668 | return getSema().ActOnCapturedRegionEnd(Body.take()); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9669 | } |
| 9670 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9671 | } // end namespace clang |
| 9672 | |
| 9673 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |