Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 16 | |
John McCall | 2d88708 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaInternal.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 18 | #include "clang/Sema/Lookup.h" |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 19 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 20 | #include "clang/Sema/SemaDiagnostic.h" |
John McCall | 781472f | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 21 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
John McCall | 7cd088e | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclObjC.h" |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
| 27 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 28 | #include "clang/AST/Stmt.h" |
| 29 | #include "clang/AST/StmtCXX.h" |
| 30 | #include "clang/AST/StmtObjC.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 31 | #include "clang/Sema/Ownership.h" |
| 32 | #include "clang/Sema/Designator.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 33 | #include "clang/Lex/Preprocessor.h" |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/ArrayRef.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 35 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 7e44e3f | 2010-12-02 00:05:49 +0000 | [diff] [blame] | 36 | #include "TypeLocBuilder.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 37 | #include <algorithm> |
| 38 | |
| 39 | namespace clang { |
John McCall | 781472f | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 40 | using namespace sema; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 42 | /// \brief A semantic tree transformation that allows one to transform one |
| 43 | /// abstract syntax tree into another. |
| 44 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 46 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 47 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 48 | /// instantiation is implemented as a tree transformation where the |
| 49 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 50 | /// template arguments for their corresponding template parameters; a similar |
| 51 | /// transformation is performed for non-type template parameters and |
| 52 | /// template template parameters. |
| 53 | /// |
| 54 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 56 | /// override any of the transformation or rebuild operators by providing an |
| 57 | /// operation with the same signature as the default implementation. The |
| 58 | /// overridding function should not be virtual. |
| 59 | /// |
| 60 | /// Semantic tree transformations are split into two stages, either of which |
| 61 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 62 | /// or the parts of an AST node using the various transformation functions, |
| 63 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 64 | /// node of the appropriate kind from the pieces. The default transformation |
| 65 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 66 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 67 | /// were changed by the transformation, invokes the rebuild operation to create |
| 68 | /// a new AST node. |
| 69 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 71 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 9151c11 | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 72 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 73 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 74 | /// new implementations. |
| 75 | /// |
| 76 | /// For more fine-grained transformations, subclasses can replace any of the |
| 77 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 78 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 79 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 81 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 82 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 83 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 84 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 85 | /// be able to use more efficient rebuild steps. |
| 86 | /// |
| 87 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 89 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 90 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 91 | /// default locations and entity names used for type-checking |
| 92 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 93 | template<typename Derived> |
| 94 | class TreeTransform { |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 95 | /// \brief Private RAII object that helps us forget and then re-remember |
| 96 | /// the template argument corresponding to a partially-substituted parameter |
| 97 | /// pack. |
| 98 | class ForgetPartiallySubstitutedPackRAII { |
| 99 | Derived &Self; |
| 100 | TemplateArgument Old; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 102 | public: |
| 103 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 104 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 105 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 106 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 107 | ~ForgetPartiallySubstitutedPackRAII() { |
| 108 | Self.RememberPartiallySubstitutedPack(Old); |
| 109 | } |
| 110 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 111 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 112 | protected: |
| 113 | Sema &SemaRef; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 115 | /// \brief The set of local declarations that have been transformed, for |
| 116 | /// cases where we are forced to build new declarations within the transformer |
| 117 | /// rather than in the subclass (e.g., lambda closure types). |
| 118 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 119 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | public: |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 121 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 122 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 124 | /// \brief Retrieves a reference to the derived class. |
| 125 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 126 | |
| 127 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | const Derived &getDerived() const { |
| 129 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | } |
| 131 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 132 | static inline ExprResult Owned(Expr *E) { return E; } |
| 133 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 134 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 135 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 136 | /// this tree transform. |
| 137 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 139 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 140 | /// if none of the children have changed. |
| 141 | /// |
| 142 | /// Subclasses may override this function to specify when the transformation |
| 143 | /// should rebuild all AST nodes. |
| 144 | bool AlwaysRebuild() { return false; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 146 | /// \brief Returns the location of the entity being transformed, if that |
| 147 | /// information was not available elsewhere in the AST. |
| 148 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 150 | /// provide an alternative implementation that provides better location |
| 151 | /// information. |
| 152 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 154 | /// \brief Returns the name of the entity being transformed, if that |
| 155 | /// information was not available elsewhere in the AST. |
| 156 | /// |
| 157 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 158 | /// implementation with a more precise name. |
| 159 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 160 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 161 | /// \brief Sets the "base" location and entity when that |
| 162 | /// information is known based on another transformation. |
| 163 | /// |
| 164 | /// By default, the source location and entity are ignored. Subclasses can |
| 165 | /// override this function to provide a customized implementation. |
| 166 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 168 | /// \brief RAII object that temporarily sets the base location and entity |
| 169 | /// used for reporting diagnostics in types. |
| 170 | class TemporaryBase { |
| 171 | TreeTransform &Self; |
| 172 | SourceLocation OldLocation; |
| 173 | DeclarationName OldEntity; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 174 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 175 | public: |
| 176 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 178 | OldLocation = Self.getDerived().getBaseLocation(); |
| 179 | OldEntity = Self.getDerived().getBaseEntity(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 180 | |
Douglas Gregor | ae201f7 | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 181 | if (Location.isValid()) |
| 182 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 183 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 185 | ~TemporaryBase() { |
| 186 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 187 | } |
| 188 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | |
| 190 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 191 | /// transformed. |
| 192 | /// |
| 193 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 195 | /// not change. For example, template instantiation need not traverse |
| 196 | /// non-dependent types. |
| 197 | bool AlreadyTransformed(QualType T) { |
| 198 | return T.isNull(); |
| 199 | } |
| 200 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 201 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 202 | /// because it is a default argument. |
| 203 | /// |
| 204 | /// Subclasses can provide an alternative implementation of this routine to |
| 205 | /// determine which kinds of call arguments get dropped. By default, |
| 206 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 207 | bool DropCallArgument(Expr *E) { |
| 208 | return E->isDefaultArgument(); |
| 209 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 210 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 211 | /// \brief Determine whether we should expand a pack expansion with the |
| 212 | /// given set of parameter packs into separate arguments by repeatedly |
| 213 | /// transforming the pattern. |
| 214 | /// |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 215 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 216 | /// Subclasses can override this routine to provide different behavior. |
| 217 | /// |
| 218 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 219 | /// pack expansion. |
| 220 | /// |
| 221 | /// \param PatternRange The source range that covers the entire pattern of |
| 222 | /// the pack expansion. |
| 223 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 224 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 225 | /// pattern. |
| 226 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 227 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 228 | /// expand the corresponding pack expansions into separate arguments. When |
| 229 | /// set, \c NumExpansions must also be set. |
| 230 | /// |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 231 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 232 | /// pack expansion after all of the expanded arguments. This is used |
| 233 | /// when extending explicitly-specified template argument packs per |
| 234 | /// C++0x [temp.arg.explicit]p9. |
| 235 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 236 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 237 | /// the expanded form of the corresponding pack expansion. This is both an |
| 238 | /// input and an output parameter, which can be set by the caller if the |
| 239 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 240 | /// and will be set by the callee when the number of expansions is known. |
| 241 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 242 | /// set this value in other cases. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 243 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 244 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 245 | /// are to be instantiated with arguments of different lengths), false |
| 246 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 247 | /// must be set. |
| 248 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 249 | SourceRange PatternRange, |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 250 | llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 251 | bool &ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 252 | bool &RetainExpansion, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 253 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 254 | ShouldExpand = false; |
| 255 | return false; |
| 256 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 257 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 258 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 259 | /// when performing an instantiation that must preserve the parameter pack |
| 260 | /// use. |
| 261 | /// |
| 262 | /// This routine is meant to be overridden by the template instantiator. |
| 263 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 264 | return TemplateArgument(); |
| 265 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 266 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 267 | /// \brief "Remember" the partially-substituted pack template argument |
| 268 | /// after performing an instantiation that must preserve the parameter pack |
| 269 | /// use. |
| 270 | /// |
| 271 | /// This routine is meant to be overridden by the template instantiator. |
| 272 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 273 | |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 274 | /// \brief Note to the derived class when a function parameter pack is |
| 275 | /// being expanded. |
| 276 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 277 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 278 | /// \brief Transforms the given type into another type. |
| 279 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 280 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 281 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 282 | /// function. This is expensive, but we don't mind, because |
| 283 | /// this method is deprecated anyway; all users should be |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 284 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 285 | /// |
| 286 | /// \returns the transformed type. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 287 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 288 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 289 | /// \brief Transforms the given type-with-location into a new |
| 290 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 292 | /// By default, this routine transforms a type by delegating to the |
| 293 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 294 | /// may override this function (to take over all type |
| 295 | /// transformations) or some set of the TransformXXXType functions |
| 296 | /// to alter the transformation. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 297 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 298 | |
| 299 | /// \brief Transform the given type-with-location into a new |
| 300 | /// type, collecting location information in the given builder |
| 301 | /// as necessary. |
| 302 | /// |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 303 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 305 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 306 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 308 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 309 | /// statement or the TransformExpr() function to transform an expression. |
| 310 | /// Subclasses may override this function to transform statements using some |
| 311 | /// other mechanism. |
| 312 | /// |
| 313 | /// \returns the transformed statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 314 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 316 | /// \brief Transform the given expression. |
| 317 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 318 | /// By default, this routine transforms an expression by delegating to the |
| 319 | /// appropriate TransformXXXExpr function to build a new expression. |
| 320 | /// Subclasses may override this function to transform expressions using some |
| 321 | /// other mechanism. |
| 322 | /// |
| 323 | /// \returns the transformed expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 324 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 326 | /// \brief Transform the given list of expressions. |
| 327 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 328 | /// This routine transforms a list of expressions by invoking |
| 329 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 330 | /// support for variadic templates by expanding any pack expansions (if the |
| 331 | /// derived class permits such expansion) along the way. When pack expansions |
| 332 | /// are present, the number of outputs may not equal the number of inputs. |
| 333 | /// |
| 334 | /// \param Inputs The set of expressions to be transformed. |
| 335 | /// |
| 336 | /// \param NumInputs The number of expressions in \c Inputs. |
| 337 | /// |
| 338 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 339 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 340 | /// be. |
| 341 | /// |
| 342 | /// \param Outputs The transformed input expressions will be added to this |
| 343 | /// vector. |
| 344 | /// |
| 345 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 346 | /// due to transformation. |
| 347 | /// |
| 348 | /// \returns true if an error occurred, false otherwise. |
| 349 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 350 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 351 | bool *ArgChanged = 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 352 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 353 | /// \brief Transform the given declaration, which is referenced from a type |
| 354 | /// or expression. |
| 355 | /// |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 356 | /// By default, acts as the identity function on declarations, unless the |
| 357 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 358 | /// may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 359 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 360 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 361 | = TransformedLocalDecls.find(D); |
| 362 | if (Known != TransformedLocalDecls.end()) |
| 363 | return Known->second; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 364 | |
| 365 | return D; |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 366 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 367 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 368 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 369 | /// place them on the new declaration. |
| 370 | /// |
| 371 | /// By default, this operation does nothing. Subclasses may override this |
| 372 | /// behavior to transform attributes. |
| 373 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 374 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 375 | /// \brief Note that a local declaration has been transformed by this |
| 376 | /// transformer. |
| 377 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 378 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 379 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 380 | /// the transformer itself has to transform the declarations. This routine |
| 381 | /// can be overridden by a subclass that keeps track of such mappings. |
| 382 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 383 | TransformedLocalDecls[Old] = New; |
| 384 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 385 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 386 | /// \brief Transform the definition of the given declaration. |
| 387 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 389 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 390 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 391 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 394 | /// \brief Transform the given declaration, which was the first part of a |
| 395 | /// nested-name-specifier in a member access expression. |
| 396 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 397 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 398 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 399 | /// the \c T in \c x->T::member |
| 400 | /// |
| 401 | /// By default, invokes TransformDecl() to transform the declaration. |
| 402 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 403 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 404 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 405 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 407 | /// \brief Transform the given nested-name-specifier with source-location |
| 408 | /// information. |
| 409 | /// |
| 410 | /// By default, transforms all of the types and declarations within the |
| 411 | /// nested-name-specifier. Subclasses may override this function to provide |
| 412 | /// alternate behavior. |
| 413 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 414 | NestedNameSpecifierLoc NNS, |
| 415 | QualType ObjectType = QualType(), |
| 416 | NamedDecl *FirstQualifierInScope = 0); |
| 417 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 418 | /// \brief Transform the given declaration name. |
| 419 | /// |
| 420 | /// By default, transforms the types of conversion function, constructor, |
| 421 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 422 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 423 | /// override this function to provide alternate behavior. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 424 | DeclarationNameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 425 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 426 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 427 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 429 | /// \param SS The nested-name-specifier that qualifies the template |
| 430 | /// name. This nested-name-specifier must already have been transformed. |
| 431 | /// |
| 432 | /// \param Name The template name to transform. |
| 433 | /// |
| 434 | /// \param NameLoc The source location of the template name. |
| 435 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 436 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 437 | /// access expression, this is the type of the object whose member template |
| 438 | /// is being referenced. |
| 439 | /// |
| 440 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 441 | /// also refers to a name within the current (lexical) scope, this is the |
| 442 | /// declaration it refers to. |
| 443 | /// |
| 444 | /// By default, transforms the template name by transforming the declarations |
| 445 | /// and nested-name-specifiers that occur within the template name. |
| 446 | /// Subclasses may override this function to provide alternate behavior. |
| 447 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 448 | TemplateName Name, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 449 | SourceLocation NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 450 | QualType ObjectType = QualType(), |
| 451 | NamedDecl *FirstQualifierInScope = 0); |
| 452 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 453 | /// \brief Transform the given template argument. |
| 454 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | /// By default, this operation transforms the type, expression, or |
| 456 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 457 | /// new template argument from the transformed result. Subclasses may |
| 458 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 459 | /// |
| 460 | /// Returns true if there was an error. |
| 461 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 462 | TemplateArgumentLoc &Output); |
| 463 | |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 464 | /// \brief Transform the given set of template arguments. |
| 465 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 466 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 467 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 468 | /// the transformed arguments to the output list. |
| 469 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 470 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 471 | /// a convenience function. Subclasses that wish to override this behavior |
| 472 | /// should override the iterator-based member template version. |
| 473 | /// |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 474 | /// \param Inputs The set of template arguments to be transformed. |
| 475 | /// |
| 476 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 477 | /// |
| 478 | /// \param Outputs The set of transformed template arguments output by this |
| 479 | /// routine. |
| 480 | /// |
| 481 | /// Returns true if an error occurred. |
| 482 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 483 | unsigned NumInputs, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 484 | TemplateArgumentListInfo &Outputs) { |
| 485 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 486 | } |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 487 | |
| 488 | /// \brief Transform the given set of template arguments. |
| 489 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 490 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 491 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 492 | /// the transformed arguments to the output list. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 493 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 494 | /// \param First An iterator to the first template argument. |
| 495 | /// |
| 496 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 497 | /// |
| 498 | /// \param Outputs The set of transformed template arguments output by this |
| 499 | /// routine. |
| 500 | /// |
| 501 | /// Returns true if an error occurred. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 502 | template<typename InputIterator> |
| 503 | bool TransformTemplateArguments(InputIterator First, |
| 504 | InputIterator Last, |
| 505 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 506 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 507 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 508 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 509 | TemplateArgumentLoc &ArgLoc); |
| 510 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 511 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 512 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 513 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 514 | getDerived().getBaseLocation()); |
| 515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 517 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 518 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 519 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 520 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 522 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 523 | FunctionProtoTypeLoc TL, |
| 524 | CXXRecordDecl *ThisContext, |
| 525 | unsigned ThisTypeQuals); |
| 526 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 527 | StmtResult |
| 528 | TransformSEHHandler(Stmt *Handler); |
| 529 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 530 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 531 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 532 | TemplateSpecializationTypeLoc TL, |
| 533 | TemplateName Template); |
| 534 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 535 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 536 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 537 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 538 | TemplateName Template, |
| 539 | CXXScopeSpec &SS); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 540 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 541 | QualType |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 542 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 543 | DependentTemplateSpecializationTypeLoc TL, |
| 544 | NestedNameSpecifierLoc QualifierLoc); |
| 545 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 546 | /// \brief Transforms the parameters of a function type into the |
| 547 | /// given vectors. |
| 548 | /// |
| 549 | /// The result vectors should be kept in sync; null entries in the |
| 550 | /// variables vector are acceptable. |
| 551 | /// |
| 552 | /// Return true on error. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 553 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 554 | ParmVarDecl **Params, unsigned NumParams, |
| 555 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 556 | SmallVectorImpl<QualType> &PTypes, |
| 557 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 558 | |
| 559 | /// \brief Transforms a single function-type parameter. Return null |
| 560 | /// on error. |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 561 | /// |
| 562 | /// \param indexAdjustment - A number to add to the parameter's |
| 563 | /// scope index; can be negative |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 564 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 565 | int indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 566 | llvm::Optional<unsigned> NumExpansions, |
| 567 | bool ExpectParameterPack); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 568 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 569 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 570 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 571 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 572 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 574 | /// \brief Transform the captures and body of a lambda expression. |
| 575 | ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator); |
| 576 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 577 | ExprResult TransformAddressOfOperand(Expr *E); |
| 578 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| 579 | bool IsAddressOfOperand); |
| 580 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 581 | #define STMT(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 582 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 583 | #define EXPR(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 584 | ExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 585 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 586 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 587 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 588 | /// \brief Build a new pointer type given its pointee type. |
| 589 | /// |
| 590 | /// By default, performs semantic analysis when building the pointer type. |
| 591 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 592 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 593 | |
| 594 | /// \brief Build a new block pointer type given its pointee type. |
| 595 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 596 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 597 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 598 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 599 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 600 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 601 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 602 | /// By default, performs semantic analysis when building the |
| 603 | /// reference type. Subclasses may override this routine to provide |
| 604 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 605 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 606 | /// \param LValue whether the type was written with an lvalue sigil |
| 607 | /// or an rvalue sigil. |
| 608 | QualType RebuildReferenceType(QualType ReferentType, |
| 609 | bool LValue, |
| 610 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 611 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 612 | /// \brief Build a new member pointer type given the pointee type and the |
| 613 | /// class type it refers into. |
| 614 | /// |
| 615 | /// By default, performs semantic analysis when building the member pointer |
| 616 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 617 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 618 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 620 | /// \brief Build a new array type given the element type, size |
| 621 | /// modifier, size of the array (if known), size expression, and index type |
| 622 | /// qualifiers. |
| 623 | /// |
| 624 | /// By default, performs semantic analysis when building the array type. |
| 625 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 627 | QualType RebuildArrayType(QualType ElementType, |
| 628 | ArrayType::ArraySizeModifier SizeMod, |
| 629 | const llvm::APInt *Size, |
| 630 | Expr *SizeExpr, |
| 631 | unsigned IndexTypeQuals, |
| 632 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 634 | /// \brief Build a new constant array type given the element type, size |
| 635 | /// modifier, (known) size of the array, and index type qualifiers. |
| 636 | /// |
| 637 | /// By default, performs semantic analysis when building the array type. |
| 638 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 640 | ArrayType::ArraySizeModifier SizeMod, |
| 641 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 642 | unsigned IndexTypeQuals, |
| 643 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 644 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 645 | /// \brief Build a new incomplete array type given the element type, size |
| 646 | /// modifier, and index type 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 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 651 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 652 | unsigned IndexTypeQuals, |
| 653 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 654 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 656 | /// size modifier, size expression, and index type qualifiers. |
| 657 | /// |
| 658 | /// By default, performs semantic analysis when building the array type. |
| 659 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 661 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 662 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 663 | unsigned IndexTypeQuals, |
| 664 | SourceRange BracketsRange); |
| 665 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 667 | /// size modifier, size expression, and index type qualifiers. |
| 668 | /// |
| 669 | /// By default, performs semantic analysis when building the array type. |
| 670 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 672 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 673 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 674 | unsigned IndexTypeQuals, |
| 675 | SourceRange BracketsRange); |
| 676 | |
| 677 | /// \brief Build a new vector type given the element type and |
| 678 | /// number of elements. |
| 679 | /// |
| 680 | /// By default, performs semantic analysis when building the vector type. |
| 681 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 682 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 683 | VectorType::VectorKind VecKind); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 685 | /// \brief Build a new extended vector type given the element type and |
| 686 | /// number of elements. |
| 687 | /// |
| 688 | /// By default, performs semantic analysis when building the vector type. |
| 689 | /// Subclasses may override this routine to provide different behavior. |
| 690 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 691 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
| 693 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 694 | /// given the element type and number of elements. |
| 695 | /// |
| 696 | /// By default, performs semantic analysis when building the vector type. |
| 697 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 698 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 699 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 700 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 702 | /// \brief Build a new function type. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis when building the function type. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
| 706 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 708 | unsigned NumParamTypes, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 709 | bool Variadic, bool HasTrailingReturn, |
| 710 | unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 711 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 712 | const FunctionType::ExtInfo &Info); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 714 | /// \brief Build a new unprototyped function type. |
| 715 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 716 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 717 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 718 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 719 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 720 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 721 | /// \brief Build a new typedef type. |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 722 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 723 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 724 | } |
| 725 | |
| 726 | /// \brief Build a new class/struct/union type. |
| 727 | QualType RebuildRecordType(RecordDecl *Record) { |
| 728 | return SemaRef.Context.getTypeDeclType(Record); |
| 729 | } |
| 730 | |
| 731 | /// \brief Build a new Enum type. |
| 732 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 733 | return SemaRef.Context.getTypeDeclType(Enum); |
| 734 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 735 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 736 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 737 | /// |
| 738 | /// By default, performs semantic analysis when building the typeof type. |
| 739 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 740 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 741 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 743 | /// |
| 744 | /// By default, builds a new TypeOfType with the given underlying type. |
| 745 | QualType RebuildTypeOfType(QualType Underlying); |
| 746 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 747 | /// \brief Build a new unary transform type. |
| 748 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 749 | UnaryTransformType::UTTKind UKind, |
| 750 | SourceLocation Loc); |
| 751 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 753 | /// |
| 754 | /// By default, performs semantic analysis when building the decltype type. |
| 755 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 756 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 758 | /// \brief Build a new C++0x auto type. |
| 759 | /// |
| 760 | /// By default, builds a new AutoType with the given deduced type. |
| 761 | QualType RebuildAutoType(QualType Deduced) { |
| 762 | return SemaRef.Context.getAutoType(Deduced); |
| 763 | } |
| 764 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 765 | /// \brief Build a new template specialization type. |
| 766 | /// |
| 767 | /// By default, performs semantic analysis when building the template |
| 768 | /// specialization type. Subclasses may override this routine to provide |
| 769 | /// different behavior. |
| 770 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 771 | SourceLocation TemplateLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 772 | TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 773 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 774 | /// \brief Build a new parenthesized type. |
| 775 | /// |
| 776 | /// By default, builds a new ParenType type from the inner type. |
| 777 | /// Subclasses may override this routine to provide different behavior. |
| 778 | QualType RebuildParenType(QualType InnerType) { |
| 779 | return SemaRef.Context.getParenType(InnerType); |
| 780 | } |
| 781 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 782 | /// \brief Build a new qualified name type. |
| 783 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 784 | /// By default, builds a new ElaboratedType type from the keyword, |
| 785 | /// the nested-name-specifier and the named type. |
| 786 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 787 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 788 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 789 | NestedNameSpecifierLoc QualifierLoc, |
| 790 | QualType Named) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 791 | return SemaRef.Context.getElaboratedType(Keyword, |
| 792 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 793 | Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 794 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 795 | |
| 796 | /// \brief Build a new typename type that refers to a template-id. |
| 797 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 798 | /// By default, builds a new DependentNameType type from the |
| 799 | /// nested-name-specifier and the given type. Subclasses may override |
| 800 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 801 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 802 | ElaboratedTypeKeyword Keyword, |
| 803 | NestedNameSpecifierLoc QualifierLoc, |
| 804 | const IdentifierInfo *Name, |
| 805 | SourceLocation NameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 806 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 807 | // Rebuild the template name. |
| 808 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 809 | CXXScopeSpec SS; |
| 810 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 811 | TemplateName InstName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 812 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 813 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 814 | if (InstName.isNull()) |
| 815 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 816 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 817 | // If it's still dependent, make a dependent specialization. |
| 818 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 819 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 820 | QualifierLoc.getNestedNameSpecifier(), |
| 821 | Name, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 822 | Args); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 823 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 824 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 825 | // specialization. |
| 826 | QualType T = |
| 827 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 828 | if (T.isNull()) return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 829 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 830 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 831 | return T; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 832 | |
| 833 | return SemaRef.Context.getElaboratedType(Keyword, |
| 834 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 835 | T); |
| 836 | } |
| 837 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 838 | /// \brief Build a new typename type that refers to an identifier. |
| 839 | /// |
| 840 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 841 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 842 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 843 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 844 | SourceLocation KeywordLoc, |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 845 | NestedNameSpecifierLoc QualifierLoc, |
| 846 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 847 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 848 | CXXScopeSpec SS; |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 849 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 850 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 851 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 852 | // If the name is still dependent, just build a new dependent name type. |
| 853 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 854 | return SemaRef.Context.getDependentNameType(Keyword, |
| 855 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 856 | Id); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 859 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 860 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | e29425b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 861 | *Id, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 862 | |
| 863 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 864 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 865 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 866 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 867 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 868 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 869 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 870 | if (!DC) |
| 871 | return QualType(); |
| 872 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 873 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 874 | return QualType(); |
| 875 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 876 | TagDecl *Tag = 0; |
| 877 | SemaRef.LookupQualifiedName(Result, DC); |
| 878 | switch (Result.getResultKind()) { |
| 879 | case LookupResult::NotFound: |
| 880 | case LookupResult::NotFoundInCurrentInstantiation: |
| 881 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 882 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 883 | case LookupResult::Found: |
| 884 | Tag = Result.getAsSingle<TagDecl>(); |
| 885 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 886 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 887 | case LookupResult::FoundOverloaded: |
| 888 | case LookupResult::FoundUnresolvedValue: |
| 889 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 890 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 891 | case LookupResult::Ambiguous: |
| 892 | // Let the LookupResult structure handle ambiguities. |
| 893 | return QualType(); |
| 894 | } |
| 895 | |
| 896 | if (!Tag) { |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 897 | // Check where the name exists but isn't a tag type and use that to emit |
| 898 | // better diagnostics. |
| 899 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 900 | SemaRef.LookupQualifiedName(Result, DC); |
| 901 | switch (Result.getResultKind()) { |
| 902 | case LookupResult::Found: |
| 903 | case LookupResult::FoundOverloaded: |
| 904 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 905 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 906 | unsigned Kind = 0; |
| 907 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 908 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 909 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 910 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 911 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 912 | break; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 913 | } |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 914 | default: |
| 915 | // FIXME: Would be nice to highlight just the source range. |
| 916 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 917 | << Kind << Id << DC; |
| 918 | break; |
| 919 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 920 | return QualType(); |
| 921 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 922 | |
Richard Trieu | bbf34c0 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 923 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 924 | IdLoc, *Id)) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 925 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 926 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 927 | return QualType(); |
| 928 | } |
| 929 | |
| 930 | // Build the elaborated-type-specifier type. |
| 931 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 932 | return SemaRef.Context.getElaboratedType(Keyword, |
| 933 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 934 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 935 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 936 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 937 | /// \brief Build a new pack expansion type. |
| 938 | /// |
| 939 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 940 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 941 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 942 | SourceRange PatternRange, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 943 | SourceLocation EllipsisLoc, |
| 944 | llvm::Optional<unsigned> NumExpansions) { |
| 945 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 946 | NumExpansions); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 947 | } |
| 948 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 949 | /// \brief Build a new atomic type given its value type. |
| 950 | /// |
| 951 | /// By default, performs semantic analysis when building the atomic type. |
| 952 | /// Subclasses may override this routine to provide different behavior. |
| 953 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 954 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 955 | /// \brief Build a new template name given a nested name specifier, a flag |
| 956 | /// indicating whether the "template" keyword was provided, and the template |
| 957 | /// that the template name refers to. |
| 958 | /// |
| 959 | /// By default, builds the new template name directly. Subclasses may override |
| 960 | /// this routine to provide different behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 961 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 962 | bool TemplateKW, |
| 963 | TemplateDecl *Template); |
| 964 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 965 | /// \brief Build a new template name given a nested name specifier and the |
| 966 | /// name that is referred to as a template. |
| 967 | /// |
| 968 | /// By default, performs semantic analysis to determine whether the name can |
| 969 | /// be resolved to a specific template, then builds the appropriate kind of |
| 970 | /// template name. Subclasses may override this routine to provide different |
| 971 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 972 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 973 | const IdentifierInfo &Name, |
| 974 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 975 | QualType ObjectType, |
| 976 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 978 | /// \brief Build a new template name given a nested name specifier and the |
| 979 | /// overloaded operator name that is referred to as a template. |
| 980 | /// |
| 981 | /// By default, performs semantic analysis to determine whether the name can |
| 982 | /// be resolved to a specific template, then builds the appropriate kind of |
| 983 | /// template name. Subclasses may override this routine to provide different |
| 984 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 985 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 986 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 987 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 988 | QualType ObjectType); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 989 | |
| 990 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 991 | /// and the |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 992 | /// |
| 993 | /// By default, performs semantic analysis to determine whether the name can |
| 994 | /// be resolved to a specific template, then builds the appropriate kind of |
| 995 | /// template name. Subclasses may override this routine to provide different |
| 996 | /// behavior. |
| 997 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 998 | const TemplateArgument &ArgPack) { |
| 999 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1000 | } |
| 1001 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1002 | /// \brief Build a new compound statement. |
| 1003 | /// |
| 1004 | /// By default, performs semantic analysis to build the new statement. |
| 1005 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1006 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1007 | MultiStmtArg Statements, |
| 1008 | SourceLocation RBraceLoc, |
| 1009 | bool IsStmtExpr) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1010 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1011 | IsStmtExpr); |
| 1012 | } |
| 1013 | |
| 1014 | /// \brief Build a new case statement. |
| 1015 | /// |
| 1016 | /// By default, performs semantic analysis to build the new statement. |
| 1017 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1018 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1019 | Expr *LHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1020 | SourceLocation EllipsisLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1021 | Expr *RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1022 | SourceLocation ColonLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1023 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1024 | ColonLoc); |
| 1025 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1027 | /// \brief Attach the body to a new case statement. |
| 1028 | /// |
| 1029 | /// By default, performs semantic analysis to build the new statement. |
| 1030 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1031 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1032 | getSema().ActOnCaseStmtBody(S, Body); |
| 1033 | return S; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1035 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1036 | /// \brief Build a new default statement. |
| 1037 | /// |
| 1038 | /// By default, performs semantic analysis to build the new statement. |
| 1039 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1040 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1041 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1042 | Stmt *SubStmt) { |
| 1043 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1044 | /*CurScope=*/0); |
| 1045 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1047 | /// \brief Build a new label statement. |
| 1048 | /// |
| 1049 | /// By default, performs semantic analysis to build the new statement. |
| 1050 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1051 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1052 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1053 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1054 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1056 | /// \brief Build a new label statement. |
| 1057 | /// |
| 1058 | /// By default, performs semantic analysis to build the new statement. |
| 1059 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1060 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1061 | ArrayRef<const Attr*> Attrs, |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1062 | Stmt *SubStmt) { |
| 1063 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1064 | } |
| 1065 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1066 | /// \brief Build a new "if" statement. |
| 1067 | /// |
| 1068 | /// By default, performs semantic analysis to build the new statement. |
| 1069 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1070 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1071 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1072 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1073 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1074 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1076 | /// \brief Start building a new switch statement. |
| 1077 | /// |
| 1078 | /// By default, performs semantic analysis to build the new statement. |
| 1079 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1080 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1081 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1082 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1083 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1084 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1086 | /// \brief Attach the body to the switch statement. |
| 1087 | /// |
| 1088 | /// By default, performs semantic analysis to build the new statement. |
| 1089 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1090 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1091 | Stmt *Switch, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1092 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | /// \brief Build a new while statement. |
| 1096 | /// |
| 1097 | /// By default, performs semantic analysis to build the new statement. |
| 1098 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1099 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1100 | VarDecl *CondVar, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1101 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1104 | /// \brief Build a new do-while statement. |
| 1105 | /// |
| 1106 | /// By default, performs semantic analysis to build the new statement. |
| 1107 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1108 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1109 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1110 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1111 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1112 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | /// \brief Build a new for statement. |
| 1116 | /// |
| 1117 | /// By default, performs semantic analysis to build the new statement. |
| 1118 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1119 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1120 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1121 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1122 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1123 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1124 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1125 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1127 | /// \brief Build a new goto statement. |
| 1128 | /// |
| 1129 | /// By default, performs semantic analysis to build the new statement. |
| 1130 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1131 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1132 | LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1133 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | /// \brief Build a new indirect goto statement. |
| 1137 | /// |
| 1138 | /// By default, performs semantic analysis to build the new statement. |
| 1139 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1140 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1141 | SourceLocation StarLoc, |
| 1142 | Expr *Target) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1143 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1144 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1146 | /// \brief Build a new return statement. |
| 1147 | /// |
| 1148 | /// By default, performs semantic analysis to build the new statement. |
| 1149 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1150 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1151 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1154 | /// \brief Build a new declaration statement. |
| 1155 | /// |
| 1156 | /// By default, performs semantic analysis to build the new statement. |
| 1157 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1158 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1160 | SourceLocation EndLoc) { |
Richard Smith | 406c38e | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1161 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1162 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1163 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1165 | /// \brief Build a new inline asm statement. |
| 1166 | /// |
| 1167 | /// By default, performs semantic analysis to build the new statement. |
| 1168 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1169 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1170 | bool IsVolatile, unsigned NumOutputs, |
| 1171 | unsigned NumInputs, IdentifierInfo **Names, |
| 1172 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1173 | Expr *AsmString, MultiExprArg Clobbers, |
| 1174 | SourceLocation RParenLoc) { |
| 1175 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1176 | NumInputs, Names, Constraints, Exprs, |
| 1177 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1178 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1179 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1180 | /// \brief Build a new MS style inline asm statement. |
| 1181 | /// |
| 1182 | /// By default, performs semantic analysis to build the new statement. |
| 1183 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1184 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
| 1185 | ArrayRef<Token> AsmToks, SourceLocation EndLoc) { |
Chad Rosier | 7bd092b | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 1186 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1189 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1190 | /// |
| 1191 | /// By default, performs semantic analysis to build the new statement. |
| 1192 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1193 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1194 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1195 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1196 | Stmt *Finally) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1197 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1198 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1201 | /// \brief Rebuild an Objective-C exception declaration. |
| 1202 | /// |
| 1203 | /// By default, performs semantic analysis to build the new declaration. |
| 1204 | /// Subclasses may override this routine to provide different behavior. |
| 1205 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1206 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1207 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1208 | ExceptionDecl->getInnerLocStart(), |
| 1209 | ExceptionDecl->getLocation(), |
| 1210 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1211 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1212 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1213 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1214 | /// |
| 1215 | /// By default, performs semantic analysis to build the new statement. |
| 1216 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1217 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1218 | SourceLocation RParenLoc, |
| 1219 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1220 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1221 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1222 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1223 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1224 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1225 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1226 | /// |
| 1227 | /// By default, performs semantic analysis to build the new statement. |
| 1228 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1229 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1230 | Stmt *Body) { |
| 1231 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1232 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1233 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1234 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1235 | /// |
| 1236 | /// By default, performs semantic analysis to build the new statement. |
| 1237 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1238 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1239 | Expr *Operand) { |
| 1240 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1241 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1242 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1243 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1244 | /// |
| 1245 | /// By default, performs semantic analysis to build the new statement. |
| 1246 | /// Subclasses may override this routine to provide different behavior. |
| 1247 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1248 | Expr *object) { |
| 1249 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1250 | } |
| 1251 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1252 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1253 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1254 | /// By default, performs semantic analysis to build the new statement. |
| 1255 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1256 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1257 | Expr *Object, Stmt *Body) { |
| 1258 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1259 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1260 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1261 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1262 | /// |
| 1263 | /// By default, performs semantic analysis to build the new statement. |
| 1264 | /// Subclasses may override this routine to provide different behavior. |
| 1265 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1266 | Stmt *Body) { |
| 1267 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1268 | } |
John McCall | 990567c | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1269 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1270 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1271 | /// |
| 1272 | /// By default, performs semantic analysis to build the new statement. |
| 1273 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1274 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1275 | Stmt *Element, |
| 1276 | Expr *Collection, |
| 1277 | SourceLocation RParenLoc, |
| 1278 | Stmt *Body) { |
Sam Panzer | bc20bbb | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1279 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1280 | Element, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1281 | Collection, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1282 | RParenLoc); |
| 1283 | if (ForEachStmt.isInvalid()) |
| 1284 | return StmtError(); |
| 1285 | |
| 1286 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1287 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1288 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1289 | /// \brief Build a new C++ exception declaration. |
| 1290 | /// |
| 1291 | /// By default, performs semantic analysis to build the new decaration. |
| 1292 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1293 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1294 | TypeSourceInfo *Declarator, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1295 | SourceLocation StartLoc, |
| 1296 | SourceLocation IdLoc, |
| 1297 | IdentifierInfo *Id) { |
Douglas Gregor | efdf988 | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1298 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1299 | StartLoc, IdLoc, Id); |
| 1300 | if (Var) |
| 1301 | getSema().CurContext->addDecl(Var); |
| 1302 | return Var; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | /// \brief Build a new C++ catch statement. |
| 1306 | /// |
| 1307 | /// By default, performs semantic analysis to build the new statement. |
| 1308 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1309 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1310 | VarDecl *ExceptionDecl, |
| 1311 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1312 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1313 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1315 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1316 | /// \brief Build a new C++ try statement. |
| 1317 | /// |
| 1318 | /// By default, performs semantic analysis to build the new statement. |
| 1319 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1320 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1321 | Stmt *TryBlock, |
| 1322 | MultiStmtArg Handlers) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1323 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1324 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1326 | /// \brief Build a new C++0x range-based for statement. |
| 1327 | /// |
| 1328 | /// By default, performs semantic analysis to build the new statement. |
| 1329 | /// Subclasses may override this routine to provide different behavior. |
| 1330 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1331 | SourceLocation ColonLoc, |
| 1332 | Stmt *Range, Stmt *BeginEnd, |
| 1333 | Expr *Cond, Expr *Inc, |
| 1334 | Stmt *LoopVar, |
| 1335 | SourceLocation RParenLoc) { |
| 1336 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | 8b533d9 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1337 | Cond, Inc, LoopVar, RParenLoc, |
| 1338 | Sema::BFRK_Rebuild); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1339 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1340 | |
| 1341 | /// \brief Build a new C++0x range-based for statement. |
| 1342 | /// |
| 1343 | /// By default, performs semantic analysis to build the new statement. |
| 1344 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1345 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1346 | bool IsIfExists, |
| 1347 | NestedNameSpecifierLoc QualifierLoc, |
| 1348 | DeclarationNameInfo NameInfo, |
| 1349 | Stmt *Nested) { |
| 1350 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1351 | QualifierLoc, NameInfo, Nested); |
| 1352 | } |
| 1353 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1354 | /// \brief Attach body to a C++0x range-based for statement. |
| 1355 | /// |
| 1356 | /// By default, performs semantic analysis to finish the new statement. |
| 1357 | /// Subclasses may override this routine to provide different behavior. |
| 1358 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1359 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1360 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1361 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1362 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, |
| 1363 | SourceLocation TryLoc, |
| 1364 | Stmt *TryBlock, |
| 1365 | Stmt *Handler) { |
| 1366 | return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1367 | } |
| 1368 | |
| 1369 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, |
| 1370 | Expr *FilterExpr, |
| 1371 | Stmt *Block) { |
| 1372 | return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); |
| 1373 | } |
| 1374 | |
| 1375 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, |
| 1376 | Stmt *Block) { |
| 1377 | return getSema().ActOnSEHFinallyBlock(Loc,Block); |
| 1378 | } |
| 1379 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | /// \brief Build a new expression that references a declaration. |
| 1381 | /// |
| 1382 | /// By default, performs semantic analysis to build the new expression. |
| 1383 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1384 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1385 | LookupResult &R, |
| 1386 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1387 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | /// \brief Build a new expression that references a declaration. |
| 1392 | /// |
| 1393 | /// By default, performs semantic analysis to build the new expression. |
| 1394 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1395 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1396 | ValueDecl *VD, |
| 1397 | const DeclarationNameInfo &NameInfo, |
| 1398 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1399 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1400 | SS.Adopt(QualifierLoc); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1401 | |
| 1402 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1403 | |
| 1404 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1406 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1407 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | /// By default, performs semantic analysis to build the new expression. |
| 1410 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1411 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1413 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1416 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1418 | /// By default, performs semantic analysis to build the new expression. |
| 1419 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1420 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1421 | SourceLocation OperatorLoc, |
| 1422 | bool isArrow, |
| 1423 | CXXScopeSpec &SS, |
| 1424 | TypeSourceInfo *ScopeType, |
| 1425 | SourceLocation CCLoc, |
| 1426 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1427 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1429 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1431 | /// By default, performs semantic analysis to build the new expression. |
| 1432 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1433 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1434 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1435 | Expr *SubExpr) { |
| 1436 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1437 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1438 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1439 | /// \brief Build a new builtin offsetof expression. |
| 1440 | /// |
| 1441 | /// By default, performs semantic analysis to build the new expression. |
| 1442 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1443 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1444 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1445 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1446 | unsigned NumComponents, |
| 1447 | SourceLocation RParenLoc) { |
| 1448 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1449 | NumComponents, RParenLoc); |
| 1450 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1451 | |
| 1452 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1453 | /// type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1454 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1455 | /// By default, performs semantic analysis to build the new expression. |
| 1456 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1457 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1458 | SourceLocation OpLoc, |
| 1459 | UnaryExprOrTypeTrait ExprKind, |
| 1460 | SourceRange R) { |
| 1461 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1464 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1465 | /// expression argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1466 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1467 | /// By default, performs semantic analysis to build the new expression. |
| 1468 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1469 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1470 | UnaryExprOrTypeTrait ExprKind, |
| 1471 | SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1472 | ExprResult Result |
Chandler Carruth | e72c55b | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1473 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1474 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1475 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1476 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1477 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1478 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1479 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1481 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1482 | /// By default, performs semantic analysis to build the new expression. |
| 1483 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1484 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1486 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1487 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1488 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1489 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1490 | RBracketLoc); |
| 1491 | } |
| 1492 | |
| 1493 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | /// By default, performs semantic analysis to build the new expression. |
| 1496 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1497 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | MultiExprArg Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1499 | SourceLocation RParenLoc, |
| 1500 | Expr *ExecConfig = 0) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1501 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1502 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1506 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | /// By default, performs semantic analysis to build the new expression. |
| 1508 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1509 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1510 | bool isArrow, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1511 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1512 | SourceLocation TemplateKWLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1513 | const DeclarationNameInfo &MemberNameInfo, |
| 1514 | ValueDecl *Member, |
| 1515 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1516 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1517 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1518 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1519 | isArrow); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1520 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1521 | // We have a reference to an unnamed field. This is always the |
| 1522 | // base of an anonymous struct/union member access, i.e. the |
| 1523 | // field is always of record type. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1524 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1525 | assert(Member->getType()->isRecordType() && |
| 1526 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1527 | |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1528 | BaseResult = |
| 1529 | getSema().PerformObjectMemberConversion(BaseResult.take(), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1530 | QualifierLoc.getNestedNameSpecifier(), |
| 1531 | FoundDecl, Member); |
| 1532 | if (BaseResult.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1533 | return ExprError(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1534 | Base = BaseResult.take(); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1535 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1536 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1537 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1538 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1539 | cast<FieldDecl>(Member)->getType(), |
| 1540 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1541 | return getSema().Owned(ME); |
| 1542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1543 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1544 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1545 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1546 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1547 | Base = BaseResult.take(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1548 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1549 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1550 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1551 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1552 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1553 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1554 | R.resolveKind(); |
| 1555 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1556 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1557 | SS, TemplateKWLoc, |
| 1558 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1559 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1561 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1562 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1564 | /// By default, performs semantic analysis to build the new expression. |
| 1565 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1566 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1567 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1568 | Expr *LHS, Expr *RHS) { |
| 1569 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | /// By default, performs semantic analysis to build the new expression. |
| 1575 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1576 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1577 | SourceLocation QuestionLoc, |
| 1578 | Expr *LHS, |
| 1579 | SourceLocation ColonLoc, |
| 1580 | Expr *RHS) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1581 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1582 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1585 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1586 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | /// By default, performs semantic analysis to build the new expression. |
| 1588 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1589 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1590 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1592 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1593 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1594 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1595 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1596 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1597 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1598 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1599 | /// By default, performs semantic analysis to build the new expression. |
| 1600 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1601 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1602 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1603 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1604 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1605 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1606 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1608 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1609 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1611 | /// By default, performs semantic analysis to build the new expression. |
| 1612 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1613 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | SourceLocation OpLoc, |
| 1615 | SourceLocation AccessorLoc, |
| 1616 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1617 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1618 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1619 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1620 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1621 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1622 | SS, SourceLocation(), |
| 1623 | /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1624 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1625 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1628 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | /// By default, performs semantic analysis to build the new expression. |
| 1631 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1632 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1633 | MultiExprArg Inits, |
| 1634 | SourceLocation RBraceLoc, |
| 1635 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1636 | ExprResult Result |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1637 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1638 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1639 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1640 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1641 | // Patch in the result type we were given, which may have been computed |
| 1642 | // when the initial InitListExpr was built. |
| 1643 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1644 | ILE->setType(ResultTy); |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1645 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | /// By default, performs semantic analysis to build the new expression. |
| 1651 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1652 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1653 | MultiExprArg ArrayExprs, |
| 1654 | SourceLocation EqualOrColonLoc, |
| 1655 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1656 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1657 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1659 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1661 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1663 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1664 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1665 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1666 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1667 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1668 | /// By default, builds the implicit value initialization without performing |
| 1669 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1670 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1671 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1672 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1674 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1675 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1677 | /// By default, performs semantic analysis to build the new expression. |
| 1678 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1679 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1680 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1681 | SourceLocation RParenLoc) { |
| 1682 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1683 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1684 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1688 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | /// By default, performs semantic analysis to build the new expression. |
| 1690 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1691 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1692 | MultiExprArg SubExprs, |
| 1693 | SourceLocation RParenLoc) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1694 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | } |
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 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1698 | /// |
| 1699 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1700 | /// rather than attempting to map the label statement itself. |
| 1701 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1702 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1703 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1704 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1705 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1706 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1707 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1709 | /// By default, performs semantic analysis to build the new expression. |
| 1710 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1711 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1712 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1713 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1714 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1715 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1716 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1717 | /// \brief Build a new __builtin_choose_expr expression. |
| 1718 | /// |
| 1719 | /// By default, performs semantic analysis to build the new expression. |
| 1720 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1721 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1722 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | SourceLocation RParenLoc) { |
| 1724 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1725 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1726 | RParenLoc); |
| 1727 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1728 | |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1729 | /// \brief Build a new generic selection expression. |
| 1730 | /// |
| 1731 | /// By default, performs semantic analysis to build the new expression. |
| 1732 | /// Subclasses may override this routine to provide different behavior. |
| 1733 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1734 | SourceLocation DefaultLoc, |
| 1735 | SourceLocation RParenLoc, |
| 1736 | Expr *ControllingExpr, |
| 1737 | TypeSourceInfo **Types, |
| 1738 | Expr **Exprs, |
| 1739 | unsigned NumAssocs) { |
| 1740 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 1741 | ControllingExpr, Types, Exprs, |
| 1742 | NumAssocs); |
| 1743 | } |
| 1744 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1745 | /// \brief Build a new overloaded operator call expression. |
| 1746 | /// |
| 1747 | /// By default, performs semantic analysis to build the new expression. |
| 1748 | /// The semantic analysis provides the behavior of template instantiation, |
| 1749 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1751 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1752 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1753 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1754 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1755 | Expr *Callee, |
| 1756 | Expr *First, |
| 1757 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
| 1759 | /// \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] | 1760 | /// reinterpret_cast. |
| 1761 | /// |
| 1762 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1764 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1765 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1766 | Stmt::StmtClass Class, |
| 1767 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1768 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1769 | SourceLocation RAngleLoc, |
| 1770 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1771 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1772 | SourceLocation RParenLoc) { |
| 1773 | switch (Class) { |
| 1774 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1775 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1777 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1778 | |
| 1779 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1780 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1781 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1782 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1784 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1785 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1786 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1787 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1788 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1790 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1791 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1793 | SubExpr, RParenLoc); |
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 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1796 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1798 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1799 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1800 | /// \brief Build a new C++ static_cast expression. |
| 1801 | /// |
| 1802 | /// By default, performs semantic analysis to build the new expression. |
| 1803 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1804 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1805 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1806 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1807 | SourceLocation RAngleLoc, |
| 1808 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1809 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1810 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1811 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1812 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1813 | SourceRange(LAngleLoc, RAngleLoc), |
| 1814 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | /// \brief Build a new C++ dynamic_cast expression. |
| 1818 | /// |
| 1819 | /// By default, performs semantic analysis to build the new expression. |
| 1820 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1821 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1822 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1823 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1824 | SourceLocation RAngleLoc, |
| 1825 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1826 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1827 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1828 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1829 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1830 | SourceRange(LAngleLoc, RAngleLoc), |
| 1831 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1835 | /// |
| 1836 | /// By default, performs semantic analysis to build the new expression. |
| 1837 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1838 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1839 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1840 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1841 | SourceLocation RAngleLoc, |
| 1842 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1843 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1844 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1845 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1846 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1847 | SourceRange(LAngleLoc, RAngleLoc), |
| 1848 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | /// \brief Build a new C++ const_cast expression. |
| 1852 | /// |
| 1853 | /// By default, performs semantic analysis to build the new expression. |
| 1854 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1855 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1856 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1857 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1858 | SourceLocation RAngleLoc, |
| 1859 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1860 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1861 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1862 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1863 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1864 | SourceRange(LAngleLoc, RAngleLoc), |
| 1865 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1866 | } |
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 | /// \brief Build a new C++ functional-style cast expression. |
| 1869 | /// |
| 1870 | /// By default, performs semantic analysis to build the new expression. |
| 1871 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1872 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1873 | SourceLocation LParenLoc, |
| 1874 | Expr *Sub, |
| 1875 | SourceLocation RParenLoc) { |
| 1876 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1877 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1878 | RParenLoc); |
| 1879 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1881 | /// \brief Build a new C++ typeid(type) expression. |
| 1882 | /// |
| 1883 | /// By default, performs semantic analysis to build the new expression. |
| 1884 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1885 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1886 | SourceLocation TypeidLoc, |
| 1887 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1888 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1889 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1890 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1891 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1892 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1893 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1894 | /// \brief Build a new C++ typeid(expr) expression. |
| 1895 | /// |
| 1896 | /// By default, performs semantic analysis to build the new expression. |
| 1897 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1898 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1899 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1900 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1901 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1902 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1903 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1906 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1907 | /// |
| 1908 | /// By default, performs semantic analysis to build the new expression. |
| 1909 | /// Subclasses may override this routine to provide different behavior. |
| 1910 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1911 | SourceLocation TypeidLoc, |
| 1912 | TypeSourceInfo *Operand, |
| 1913 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1914 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1915 | RParenLoc); |
| 1916 | } |
| 1917 | |
| 1918 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1919 | /// |
| 1920 | /// By default, performs semantic analysis to build the new expression. |
| 1921 | /// Subclasses may override this routine to provide different behavior. |
| 1922 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1923 | SourceLocation TypeidLoc, |
| 1924 | Expr *Operand, |
| 1925 | SourceLocation RParenLoc) { |
| 1926 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1927 | RParenLoc); |
| 1928 | } |
| 1929 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1930 | /// \brief Build a new C++ "this" expression. |
| 1931 | /// |
| 1932 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1933 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1934 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1935 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1936 | QualType ThisType, |
| 1937 | bool isImplicit) { |
Eli Friedman | b69b42c | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 1938 | getSema().CheckCXXThisCapture(ThisLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1939 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1940 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1941 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | /// \brief Build a new C++ throw expression. |
| 1945 | /// |
| 1946 | /// By default, performs semantic analysis to build the new expression. |
| 1947 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 1948 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 1949 | bool IsThrownVariableInScope) { |
| 1950 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | /// \brief Build a new C++ default-argument expression. |
| 1954 | /// |
| 1955 | /// By default, builds a new default-argument expression, which does not |
| 1956 | /// require any semantic analysis. Subclasses may override this routine to |
| 1957 | /// provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1958 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1959 | ParmVarDecl *Param) { |
| 1960 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1961 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | /// \brief Build a new C++ zero-initialization expression. |
| 1965 | /// |
| 1966 | /// By default, performs semantic analysis to build the new expression. |
| 1967 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1968 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1969 | SourceLocation LParenLoc, |
| 1970 | SourceLocation RParenLoc) { |
| 1971 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 1972 | MultiExprArg(), RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1973 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1974 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1975 | /// \brief Build a new C++ "new" expression. |
| 1976 | /// |
| 1977 | /// By default, performs semantic analysis to build the new expression. |
| 1978 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1979 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1980 | bool UseGlobal, |
| 1981 | SourceLocation PlacementLParen, |
| 1982 | MultiExprArg PlacementArgs, |
| 1983 | SourceLocation PlacementRParen, |
| 1984 | SourceRange TypeIdParens, |
| 1985 | QualType AllocatedType, |
| 1986 | TypeSourceInfo *AllocatedTypeInfo, |
| 1987 | Expr *ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 1988 | SourceRange DirectInitRange, |
| 1989 | Expr *Initializer) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1990 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1991 | PlacementLParen, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1992 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1994 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1995 | AllocatedType, |
| 1996 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1997 | ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 1998 | DirectInitRange, |
| 1999 | Initializer); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2000 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2001 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2002 | /// \brief Build a new C++ "delete" expression. |
| 2003 | /// |
| 2004 | /// By default, performs semantic analysis to build the new expression. |
| 2005 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2006 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2007 | bool IsGlobalDelete, |
| 2008 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2009 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2010 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2011 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2012 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2013 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | /// \brief Build a new unary type trait expression. |
| 2015 | /// |
| 2016 | /// By default, performs semantic analysis to build the new expression. |
| 2017 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2018 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 2019 | SourceLocation StartLoc, |
| 2020 | TypeSourceInfo *T, |
| 2021 | SourceLocation RParenLoc) { |
| 2022 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2025 | /// \brief Build a new binary type trait expression. |
| 2026 | /// |
| 2027 | /// By default, performs semantic analysis to build the new expression. |
| 2028 | /// Subclasses may override this routine to provide different behavior. |
| 2029 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 2030 | SourceLocation StartLoc, |
| 2031 | TypeSourceInfo *LhsT, |
| 2032 | TypeSourceInfo *RhsT, |
| 2033 | SourceLocation RParenLoc) { |
| 2034 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 2035 | } |
| 2036 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2037 | /// \brief Build a new type trait expression. |
| 2038 | /// |
| 2039 | /// By default, performs semantic analysis to build the new expression. |
| 2040 | /// Subclasses may override this routine to provide different behavior. |
| 2041 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2042 | SourceLocation StartLoc, |
| 2043 | ArrayRef<TypeSourceInfo *> Args, |
| 2044 | SourceLocation RParenLoc) { |
| 2045 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2046 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2047 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2048 | /// \brief Build a new array type trait expression. |
| 2049 | /// |
| 2050 | /// By default, performs semantic analysis to build the new expression. |
| 2051 | /// Subclasses may override this routine to provide different behavior. |
| 2052 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2053 | SourceLocation StartLoc, |
| 2054 | TypeSourceInfo *TSInfo, |
| 2055 | Expr *DimExpr, |
| 2056 | SourceLocation RParenLoc) { |
| 2057 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2058 | } |
| 2059 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2060 | /// \brief Build a new expression trait expression. |
| 2061 | /// |
| 2062 | /// By default, performs semantic analysis to build the new expression. |
| 2063 | /// Subclasses may override this routine to provide different behavior. |
| 2064 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2065 | SourceLocation StartLoc, |
| 2066 | Expr *Queried, |
| 2067 | SourceLocation RParenLoc) { |
| 2068 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2069 | } |
| 2070 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2071 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2072 | /// expression. |
| 2073 | /// |
| 2074 | /// By default, performs semantic analysis to build the new expression. |
| 2075 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2076 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2077 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2078 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2079 | const DeclarationNameInfo &NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2080 | const TemplateArgumentListInfo *TemplateArgs, |
| 2081 | bool IsAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2082 | CXXScopeSpec SS; |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2083 | SS.Adopt(QualifierLoc); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2084 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2085 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2086 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2087 | NameInfo, TemplateArgs); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2088 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2089 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo, |
| 2090 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | /// \brief Build a new template-id expression. |
| 2094 | /// |
| 2095 | /// By default, performs semantic analysis to build the new expression. |
| 2096 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2097 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2098 | SourceLocation TemplateKWLoc, |
| 2099 | LookupResult &R, |
| 2100 | bool RequiresADL, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2101 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2102 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2103 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | /// \brief Build a new object-construction expression. |
| 2107 | /// |
| 2108 | /// By default, performs semantic analysis to build the new expression. |
| 2109 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2110 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2111 | SourceLocation Loc, |
| 2112 | CXXConstructorDecl *Constructor, |
| 2113 | bool IsElidable, |
| 2114 | MultiExprArg Args, |
| 2115 | bool HadMultipleCandidates, |
| 2116 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2117 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2118 | SourceRange ParenRange) { |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2119 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2120 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2121 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2122 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2123 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2124 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2125 | ConvertedArgs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2126 | HadMultipleCandidates, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2127 | RequiresZeroInit, ConstructKind, |
| 2128 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | /// \brief Build a new object-construction expression. |
| 2132 | /// |
| 2133 | /// By default, performs semantic analysis to build the new expression. |
| 2134 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2135 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2136 | SourceLocation LParenLoc, |
| 2137 | MultiExprArg Args, |
| 2138 | SourceLocation RParenLoc) { |
| 2139 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2140 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2141 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2142 | RParenLoc); |
| 2143 | } |
| 2144 | |
| 2145 | /// \brief Build a new object-construction expression. |
| 2146 | /// |
| 2147 | /// By default, performs semantic analysis to build the new expression. |
| 2148 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2149 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2150 | SourceLocation LParenLoc, |
| 2151 | MultiExprArg Args, |
| 2152 | SourceLocation RParenLoc) { |
| 2153 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2154 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2155 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2156 | RParenLoc); |
| 2157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2159 | /// \brief Build a new member reference expression. |
| 2160 | /// |
| 2161 | /// By default, performs semantic analysis to build the new expression. |
| 2162 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2163 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2164 | QualType BaseType, |
| 2165 | bool IsArrow, |
| 2166 | SourceLocation OperatorLoc, |
| 2167 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2168 | SourceLocation TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2169 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2170 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2171 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2172 | CXXScopeSpec SS; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2173 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2174 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2175 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2176 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2177 | SS, TemplateKWLoc, |
| 2178 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2179 | MemberNameInfo, |
| 2180 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2183 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2184 | /// |
| 2185 | /// By default, performs semantic analysis to build the new expression. |
| 2186 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2187 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2188 | SourceLocation OperatorLoc, |
| 2189 | bool IsArrow, |
| 2190 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2191 | SourceLocation TemplateKWLoc, |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2192 | NamedDecl *FirstQualifierInScope, |
| 2193 | LookupResult &R, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2194 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2195 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2196 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2197 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2198 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2199 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2200 | SS, TemplateKWLoc, |
| 2201 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2202 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2203 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2204 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2205 | /// \brief Build a new noexcept expression. |
| 2206 | /// |
| 2207 | /// By default, performs semantic analysis to build the new expression. |
| 2208 | /// Subclasses may override this routine to provide different behavior. |
| 2209 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2210 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2211 | } |
| 2212 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2213 | /// \brief Build a new expression to compute the length of a parameter pack. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2214 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2215 | SourceLocation PackLoc, |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2216 | SourceLocation RParenLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2217 | llvm::Optional<unsigned> Length) { |
| 2218 | if (Length) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2219 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2220 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2221 | RParenLoc, *Length); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2222 | |
| 2223 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2224 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2225 | RParenLoc); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2226 | } |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2227 | |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2228 | /// \brief Build a new Objective-C boxed expression. |
| 2229 | /// |
| 2230 | /// By default, performs semantic analysis to build the new expression. |
| 2231 | /// Subclasses may override this routine to provide different behavior. |
| 2232 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2233 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2234 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2235 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2236 | /// \brief Build a new Objective-C array literal. |
| 2237 | /// |
| 2238 | /// By default, performs semantic analysis to build the new expression. |
| 2239 | /// Subclasses may override this routine to provide different behavior. |
| 2240 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2241 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2242 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2243 | MultiExprArg(Elements, NumElements)); |
| 2244 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2245 | |
| 2246 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2247 | Expr *Base, Expr *Key, |
| 2248 | ObjCMethodDecl *getterMethod, |
| 2249 | ObjCMethodDecl *setterMethod) { |
| 2250 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2251 | getterMethod, setterMethod); |
| 2252 | } |
| 2253 | |
| 2254 | /// \brief Build a new Objective-C dictionary literal. |
| 2255 | /// |
| 2256 | /// By default, performs semantic analysis to build the new expression. |
| 2257 | /// Subclasses may override this routine to provide different behavior. |
| 2258 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2259 | ObjCDictionaryElement *Elements, |
| 2260 | unsigned NumElements) { |
| 2261 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2262 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2263 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2264 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2265 | /// |
| 2266 | /// By default, performs semantic analysis to build the new expression. |
| 2267 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2268 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2269 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2270 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2271 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2272 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2273 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2275 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2276 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2277 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2278 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2279 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2280 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2281 | MultiExprArg Args, |
| 2282 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2283 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2284 | ReceiverTypeInfo->getType(), |
| 2285 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2286 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2287 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2291 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2292 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2293 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2294 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2295 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2296 | MultiExprArg Args, |
| 2297 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2298 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2299 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2300 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2301 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2302 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2305 | /// \brief Build a new Objective-C ivar reference expression. |
| 2306 | /// |
| 2307 | /// By default, performs semantic analysis to build the new expression. |
| 2308 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2309 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2310 | SourceLocation IvarLoc, |
| 2311 | bool IsArrow, bool IsFreeIvar) { |
| 2312 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2313 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2314 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2315 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2316 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2317 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2318 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2319 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2320 | false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2321 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2322 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2323 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2324 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2325 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2326 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2327 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2328 | /*FIXME:*/IvarLoc, IsArrow, |
| 2329 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2330 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2331 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2332 | /*TemplateArgs=*/0); |
| 2333 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2334 | |
| 2335 | /// \brief Build a new Objective-C property reference expression. |
| 2336 | /// |
| 2337 | /// By default, performs semantic analysis to build the new expression. |
| 2338 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2339 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2340 | ObjCPropertyDecl *Property, |
| 2341 | SourceLocation PropertyLoc) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2342 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2343 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2344 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2345 | Sema::LookupMemberName); |
| 2346 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2347 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2348 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2349 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2350 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2351 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2352 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2353 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2354 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2355 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2356 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2357 | /*FIXME:*/PropertyLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2358 | SS, SourceLocation(), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2359 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2360 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2361 | /*TemplateArgs=*/0); |
| 2362 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2363 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2364 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2365 | /// |
| 2366 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2367 | /// Subclasses may override this routine to provide different behavior. |
| 2368 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2369 | ObjCMethodDecl *Getter, |
| 2370 | ObjCMethodDecl *Setter, |
| 2371 | SourceLocation PropertyLoc) { |
| 2372 | // Since these expressions can only be value-dependent, we do not |
| 2373 | // need to perform semantic analysis again. |
| 2374 | return Owned( |
| 2375 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2376 | VK_LValue, OK_ObjCProperty, |
| 2377 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2380 | /// \brief Build a new Objective-C "isa" expression. |
| 2381 | /// |
| 2382 | /// By default, performs semantic analysis to build the new expression. |
| 2383 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2384 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2385 | bool IsArrow) { |
| 2386 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2387 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2388 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2389 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2390 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2391 | /*FIME:*/IsaLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2392 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2393 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2394 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2395 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2396 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2397 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2398 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2399 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2400 | /*FIXME:*/IsaLoc, IsArrow, |
| 2401 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2402 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2403 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2404 | /*TemplateArgs=*/0); |
| 2405 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2406 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2407 | /// \brief Build a new shuffle vector expression. |
| 2408 | /// |
| 2409 | /// By default, performs semantic analysis to build the new expression. |
| 2410 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2411 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2412 | MultiExprArg SubExprs, |
| 2413 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2414 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2415 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2416 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2417 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2418 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2419 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2420 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2421 | // Build a reference to the __builtin_shufflevector builtin |
| 2422 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2423 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2424 | SemaRef.Context.BuiltinFnTy, |
| 2425 | VK_RValue, BuiltinLoc); |
| 2426 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2427 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| 2428 | CK_BuiltinFnToFnPtr).take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2429 | |
| 2430 | // Build the CallExpr |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2431 | ExprResult TheCall = SemaRef.Owned( |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2432 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs, |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2433 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2434 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2435 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2436 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2437 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2438 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2439 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2440 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2441 | /// \brief Build a new template argument pack expansion. |
| 2442 | /// |
| 2443 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2444 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2445 | /// different behavior. |
| 2446 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2447 | SourceLocation EllipsisLoc, |
| 2448 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2449 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2450 | case TemplateArgument::Expression: { |
| 2451 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2452 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2453 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2454 | if (Result.isInvalid()) |
| 2455 | return TemplateArgumentLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2456 | |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2457 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2458 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2459 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2460 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2461 | return TemplateArgumentLoc(TemplateArgument( |
| 2462 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2463 | NumExpansions), |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2464 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2465 | Pattern.getTemplateNameLoc(), |
| 2466 | EllipsisLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2467 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2468 | case TemplateArgument::Null: |
| 2469 | case TemplateArgument::Integral: |
| 2470 | case TemplateArgument::Declaration: |
| 2471 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2472 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2473 | case TemplateArgument::NullPtr: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2474 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2475 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2476 | case TemplateArgument::Type: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2477 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2478 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2479 | EllipsisLoc, |
| 2480 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2481 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2482 | Expansion); |
| 2483 | break; |
| 2484 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2485 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2486 | return TemplateArgumentLoc(); |
| 2487 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2488 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2489 | /// \brief Build a new expression pack expansion. |
| 2490 | /// |
| 2491 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2492 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2493 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2494 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2495 | llvm::Optional<unsigned> NumExpansions) { |
| 2496 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2497 | } |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2498 | |
| 2499 | /// \brief Build a new atomic operation expression. |
| 2500 | /// |
| 2501 | /// By default, performs semantic analysis to build the new expression. |
| 2502 | /// Subclasses may override this routine to provide different behavior. |
| 2503 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2504 | MultiExprArg SubExprs, |
| 2505 | QualType RetTy, |
| 2506 | AtomicExpr::AtomicOp Op, |
| 2507 | SourceLocation RParenLoc) { |
| 2508 | // Just create the expression; there is not any interesting semantic |
| 2509 | // analysis here because we can't actually build an AtomicExpr until |
| 2510 | // we are sure it is semantically sound. |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2511 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2512 | RParenLoc); |
| 2513 | } |
| 2514 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2515 | private: |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2516 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2517 | QualType ObjectType, |
| 2518 | NamedDecl *FirstQualifierInScope, |
| 2519 | CXXScopeSpec &SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2520 | |
| 2521 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2522 | QualType ObjectType, |
| 2523 | NamedDecl *FirstQualifierInScope, |
| 2524 | CXXScopeSpec &SS); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2525 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2526 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2527 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2528 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2529 | if (!S) |
| 2530 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2531 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2532 | switch (S->getStmtClass()) { |
| 2533 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2535 | // Transform individual statement nodes |
| 2536 | #define STMT(Node, Parent) \ |
| 2537 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2538 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2539 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2540 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2541 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2542 | // Transform expressions by calling TransformExpr. |
| 2543 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2544 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2545 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2546 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2547 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2548 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2549 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2550 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2551 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2552 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2556 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2558 | |
| 2559 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2560 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2561 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2562 | if (!E) |
| 2563 | return SemaRef.Owned(E); |
| 2564 | |
| 2565 | switch (E->getStmtClass()) { |
| 2566 | case Stmt::NoStmtClass: break; |
| 2567 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2568 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2569 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2570 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2571 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2574 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2578 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2579 | unsigned NumInputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2580 | bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2581 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2582 | bool *ArgChanged) { |
| 2583 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2584 | // If requested, drop call arguments that need to be dropped. |
| 2585 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2586 | if (ArgChanged) |
| 2587 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2588 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2589 | break; |
| 2590 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2591 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2592 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2593 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2594 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2595 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2596 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2597 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2598 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2599 | // Determine whether the set of unexpanded parameter packs can and should |
| 2600 | // be expanded. |
| 2601 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2602 | bool RetainExpansion = false; |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2603 | llvm::Optional<unsigned> OrigNumExpansions |
| 2604 | = Expansion->getNumExpansions(); |
| 2605 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2606 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2607 | Pattern->getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2608 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2609 | Expand, RetainExpansion, |
| 2610 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2611 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2612 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2613 | if (!Expand) { |
| 2614 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2615 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2616 | // expansion. |
| 2617 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2618 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2619 | if (OutPattern.isInvalid()) |
| 2620 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2621 | |
| 2622 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2623 | Expansion->getEllipsisLoc(), |
| 2624 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2625 | if (Out.isInvalid()) |
| 2626 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2627 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2628 | if (ArgChanged) |
| 2629 | *ArgChanged = true; |
| 2630 | Outputs.push_back(Out.get()); |
| 2631 | continue; |
| 2632 | } |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2633 | |
| 2634 | // Record right away that the argument was changed. This needs |
| 2635 | // to happen even if the array expands to nothing. |
| 2636 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2637 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2638 | // The transform has determined that we should perform an elementwise |
| 2639 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2640 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2641 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2642 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2643 | if (Out.isInvalid()) |
| 2644 | return true; |
| 2645 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2646 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2647 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2648 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2649 | if (Out.isInvalid()) |
| 2650 | return true; |
| 2651 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2652 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2653 | Outputs.push_back(Out.get()); |
| 2654 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2655 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2656 | continue; |
| 2657 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2658 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2659 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2660 | if (Result.isInvalid()) |
| 2661 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2662 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2663 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2664 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2665 | |
| 2666 | Outputs.push_back(Result.get()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2667 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2668 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2669 | return false; |
| 2670 | } |
| 2671 | |
| 2672 | template<typename Derived> |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2673 | NestedNameSpecifierLoc |
| 2674 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2675 | NestedNameSpecifierLoc NNS, |
| 2676 | QualType ObjectType, |
| 2677 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2678 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2679 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2680 | Qualifier = Qualifier.getPrefix()) |
| 2681 | Qualifiers.push_back(Qualifier); |
| 2682 | |
| 2683 | CXXScopeSpec SS; |
| 2684 | while (!Qualifiers.empty()) { |
| 2685 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2686 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2687 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2688 | switch (QNNS->getKind()) { |
| 2689 | case NestedNameSpecifier::Identifier: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2690 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2691 | *QNNS->getAsIdentifier(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2692 | Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2693 | Q.getLocalEndLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2694 | ObjectType, false, SS, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2695 | FirstQualifierInScope, false)) |
| 2696 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2697 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2698 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2699 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2700 | case NestedNameSpecifier::Namespace: { |
| 2701 | NamespaceDecl *NS |
| 2702 | = cast_or_null<NamespaceDecl>( |
| 2703 | getDerived().TransformDecl( |
| 2704 | Q.getLocalBeginLoc(), |
| 2705 | QNNS->getAsNamespace())); |
| 2706 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2707 | break; |
| 2708 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2709 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2710 | case NestedNameSpecifier::NamespaceAlias: { |
| 2711 | NamespaceAliasDecl *Alias |
| 2712 | = cast_or_null<NamespaceAliasDecl>( |
| 2713 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2714 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2715 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2716 | Q.getLocalEndLoc()); |
| 2717 | break; |
| 2718 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2719 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2720 | case NestedNameSpecifier::Global: |
| 2721 | // There is no meaningful transformation that one could perform on the |
| 2722 | // global scope. |
| 2723 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2724 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2725 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2726 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2727 | case NestedNameSpecifier::TypeSpec: { |
| 2728 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2729 | FirstQualifierInScope, SS); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2730 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2731 | if (!TL) |
| 2732 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2733 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2734 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2735 | (SemaRef.getLangOpts().CPlusPlus0x && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2736 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2737 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2738 | "Can't get cv-qualifiers here"); |
Richard Smith | 95aafb2 | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 2739 | if (TL.getType()->isEnumeralType()) |
| 2740 | SemaRef.Diag(TL.getBeginLoc(), |
| 2741 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2742 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2743 | Q.getLocalEndLoc()); |
| 2744 | break; |
| 2745 | } |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2746 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2747 | // error because a previous error should have already been emitted. |
| 2748 | TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); |
| 2749 | if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2750 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2751 | << TL.getType() << SS.getRange(); |
| 2752 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2753 | return NestedNameSpecifierLoc(); |
| 2754 | } |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2755 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2756 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2757 | // 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] | 2758 | FirstQualifierInScope = 0; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2759 | ObjectType = QualType(); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2760 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2761 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2762 | // 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] | 2763 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2764 | !getDerived().AlwaysRebuild()) |
| 2765 | return NNS; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2766 | |
| 2767 | // If we can re-use the source-location data from the original |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2768 | // nested-name-specifier, do so. |
| 2769 | if (SS.location_size() == NNS.getDataLength() && |
| 2770 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2771 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2772 | |
| 2773 | // Allocate new nested-name-specifier location information. |
| 2774 | return SS.getWithLocInContext(SemaRef.Context); |
| 2775 | } |
| 2776 | |
| 2777 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2778 | DeclarationNameInfo |
| 2779 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2780 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2781 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2782 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2783 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2784 | |
| 2785 | switch (Name.getNameKind()) { |
| 2786 | case DeclarationName::Identifier: |
| 2787 | case DeclarationName::ObjCZeroArgSelector: |
| 2788 | case DeclarationName::ObjCOneArgSelector: |
| 2789 | case DeclarationName::ObjCMultiArgSelector: |
| 2790 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2791 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2792 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2793 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2794 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2795 | case DeclarationName::CXXConstructorName: |
| 2796 | case DeclarationName::CXXDestructorName: |
| 2797 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2798 | TypeSourceInfo *NewTInfo; |
| 2799 | CanQualType NewCanTy; |
| 2800 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2801 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2802 | if (!NewTInfo) |
| 2803 | return DeclarationNameInfo(); |
| 2804 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2805 | } |
| 2806 | else { |
| 2807 | NewTInfo = 0; |
| 2808 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2809 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2810 | if (NewT.isNull()) |
| 2811 | return DeclarationNameInfo(); |
| 2812 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2813 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2814 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2815 | DeclarationName NewName |
| 2816 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2817 | NewCanTy); |
| 2818 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2819 | NewNameInfo.setName(NewName); |
| 2820 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2821 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2822 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2823 | } |
| 2824 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2825 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2829 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2830 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 2831 | TemplateName Name, |
| 2832 | SourceLocation NameLoc, |
| 2833 | QualType ObjectType, |
| 2834 | NamedDecl *FirstQualifierInScope) { |
| 2835 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 2836 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 2837 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2838 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2839 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2840 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2841 | Template)); |
| 2842 | if (!TransTemplate) |
| 2843 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2844 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2845 | if (!getDerived().AlwaysRebuild() && |
| 2846 | SS.getScopeRep() == QTN->getQualifier() && |
| 2847 | TransTemplate == Template) |
| 2848 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2849 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2850 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 2851 | TransTemplate); |
| 2852 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2853 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2854 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 2855 | if (SS.getScopeRep()) { |
| 2856 | // These apply to the scope specifier, not the template. |
| 2857 | ObjectType = QualType(); |
| 2858 | FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2861 | if (!getDerived().AlwaysRebuild() && |
| 2862 | SS.getScopeRep() == DTN->getQualifier() && |
| 2863 | ObjectType.isNull()) |
| 2864 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2865 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2866 | if (DTN->isIdentifier()) { |
| 2867 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2868 | *DTN->getIdentifier(), |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2869 | NameLoc, |
| 2870 | ObjectType, |
| 2871 | FirstQualifierInScope); |
| 2872 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2873 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2874 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 2875 | ObjectType); |
| 2876 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2877 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2878 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 2879 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2880 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2881 | Template)); |
| 2882 | if (!TransTemplate) |
| 2883 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2884 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2885 | if (!getDerived().AlwaysRebuild() && |
| 2886 | TransTemplate == Template) |
| 2887 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2888 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2889 | return TemplateName(TransTemplate); |
| 2890 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2891 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2892 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2893 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2894 | TemplateTemplateParmDecl *TransParam |
| 2895 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2896 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 2897 | if (!TransParam) |
| 2898 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2899 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2900 | if (!getDerived().AlwaysRebuild() && |
| 2901 | TransParam == SubstPack->getParameterPack()) |
| 2902 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2903 | |
| 2904 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2905 | SubstPack->getArgumentPack()); |
| 2906 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2907 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2908 | // These should be getting filtered out before they reach the AST. |
| 2909 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2913 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2914 | const TemplateArgument &Arg, |
| 2915 | TemplateArgumentLoc &Output) { |
| 2916 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2917 | switch (Arg.getKind()) { |
| 2918 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2919 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2920 | break; |
| 2921 | |
| 2922 | case TemplateArgument::Type: |
| 2923 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2924 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2925 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2926 | break; |
| 2927 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2928 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2929 | case TemplateArgument::TemplateExpansion: { |
| 2930 | NestedNameSpecifierLocBuilder Builder; |
| 2931 | TemplateName Template = Arg.getAsTemplate(); |
| 2932 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 2933 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 2934 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 2935 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2936 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2937 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2938 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2939 | Builder.getWithLocInContext(SemaRef.Context), |
| 2940 | Loc); |
| 2941 | else |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2942 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2943 | Builder.getWithLocInContext(SemaRef.Context), |
| 2944 | Loc, Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2945 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2946 | break; |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2947 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2948 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2949 | case TemplateArgument::Expression: |
| 2950 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2951 | break; |
| 2952 | |
| 2953 | case TemplateArgument::Declaration: |
| 2954 | case TemplateArgument::Integral: |
| 2955 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2956 | case TemplateArgument::NullPtr: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2957 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2958 | break; |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | template<typename Derived> |
| 2963 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2964 | const TemplateArgumentLoc &Input, |
| 2965 | TemplateArgumentLoc &Output) { |
| 2966 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2967 | switch (Arg.getKind()) { |
| 2968 | case TemplateArgument::Null: |
| 2969 | case TemplateArgument::Integral: |
Eli Friedman | 511e3ae | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 2970 | case TemplateArgument::Pack: |
| 2971 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2972 | case TemplateArgument::NullPtr: |
| 2973 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2974 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2975 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2976 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2977 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2978 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2979 | |
| 2980 | DI = getDerived().TransformType(DI); |
| 2981 | if (!DI) return true; |
| 2982 | |
| 2983 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2984 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2985 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2987 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2988 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 2989 | if (QualifierLoc) { |
| 2990 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 2991 | if (!QualifierLoc) |
| 2992 | return true; |
| 2993 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2994 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2995 | CXXScopeSpec SS; |
| 2996 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2997 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2998 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 2999 | Input.getTemplateNameLoc()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3000 | if (Template.isNull()) |
| 3001 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3002 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3003 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3004 | Input.getTemplateNameLoc()); |
| 3005 | return false; |
| 3006 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3007 | |
| 3008 | case TemplateArgument::TemplateExpansion: |
| 3009 | llvm_unreachable("Caller should expand pack expansions"); |
| 3010 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3011 | case TemplateArgument::Expression: { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3012 | // Template argument expressions are constant expressions. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3013 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3014 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3015 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3016 | Expr *InputExpr = Input.getSourceExpression(); |
| 3017 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3018 | |
Chris Lattner | 223de24 | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3019 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3020 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3021 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3022 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3023 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3024 | } |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3025 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3026 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3027 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3028 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3029 | } |
| 3030 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3031 | /// \brief Iterator adaptor that invents template argument location information |
| 3032 | /// for each of the template arguments in its underlying iterator. |
| 3033 | template<typename Derived, typename InputIterator> |
| 3034 | class TemplateArgumentLocInventIterator { |
| 3035 | TreeTransform<Derived> &Self; |
| 3036 | InputIterator Iter; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3037 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3038 | public: |
| 3039 | typedef TemplateArgumentLoc value_type; |
| 3040 | typedef TemplateArgumentLoc reference; |
| 3041 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3042 | difference_type; |
| 3043 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3044 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3045 | class pointer { |
| 3046 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3047 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3048 | public: |
| 3049 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3050 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3051 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3052 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3053 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3054 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3055 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3056 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3057 | InputIterator Iter) |
| 3058 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3059 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3060 | TemplateArgumentLocInventIterator &operator++() { |
| 3061 | ++Iter; |
| 3062 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3063 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3064 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3065 | TemplateArgumentLocInventIterator operator++(int) { |
| 3066 | TemplateArgumentLocInventIterator Old(*this); |
| 3067 | ++(*this); |
| 3068 | return Old; |
| 3069 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3070 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3071 | reference operator*() const { |
| 3072 | TemplateArgumentLoc Result; |
| 3073 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3074 | return Result; |
| 3075 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3076 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3077 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3078 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3079 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3080 | const TemplateArgumentLocInventIterator &Y) { |
| 3081 | return X.Iter == Y.Iter; |
| 3082 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3083 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3084 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3085 | const TemplateArgumentLocInventIterator &Y) { |
| 3086 | return X.Iter != Y.Iter; |
| 3087 | } |
| 3088 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3089 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3090 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3091 | template<typename InputIterator> |
| 3092 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3093 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3094 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3095 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3096 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3097 | TemplateArgumentLoc In = *First; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3098 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3099 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3100 | // Unpack argument packs, which we translate them into separate |
| 3101 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3102 | // FIXME: We could do much better if we could guarantee that the |
| 3103 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3104 | // all of the template arguments in the argument pack. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3105 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3106 | TemplateArgument::pack_iterator> |
| 3107 | PackLocIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3108 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3109 | In.getArgument().pack_begin()), |
| 3110 | PackLocIterator(*this, |
| 3111 | In.getArgument().pack_end()), |
| 3112 | Outputs)) |
| 3113 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3114 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3115 | continue; |
| 3116 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3117 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3118 | if (In.getArgument().isPackExpansion()) { |
| 3119 | // We have a pack expansion, for which we will be substituting into |
| 3120 | // the pattern. |
| 3121 | SourceLocation Ellipsis; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3122 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3123 | TemplateArgumentLoc Pattern |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3124 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3125 | getSema().Context); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3126 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3127 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3128 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3129 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3130 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3131 | // Determine whether the set of unexpanded parameter packs can and should |
| 3132 | // be expanded. |
| 3133 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3134 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3135 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3136 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3137 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3138 | Unexpanded, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3139 | Expand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3140 | RetainExpansion, |
| 3141 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3142 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3143 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3144 | if (!Expand) { |
| 3145 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3146 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3147 | // expansion. |
| 3148 | TemplateArgumentLoc OutPattern; |
| 3149 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3150 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3151 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3152 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3153 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3154 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3155 | if (Out.getArgument().isNull()) |
| 3156 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3157 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3158 | Outputs.addArgument(Out); |
| 3159 | continue; |
| 3160 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3161 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3162 | // The transform has determined that we should perform an elementwise |
| 3163 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3164 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3165 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3166 | |
| 3167 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3168 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3169 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3170 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3171 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3172 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3173 | if (Out.getArgument().isNull()) |
| 3174 | return true; |
| 3175 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3176 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3177 | Outputs.addArgument(Out); |
| 3178 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3179 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3180 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3181 | // forgetting the partially-substituted parameter pack. |
| 3182 | if (RetainExpansion) { |
| 3183 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3184 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3185 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3186 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3187 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3188 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3189 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3190 | if (Out.getArgument().isNull()) |
| 3191 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3192 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3193 | Outputs.addArgument(Out); |
| 3194 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3195 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3196 | continue; |
| 3197 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3198 | |
| 3199 | // The simple case: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3200 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3201 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3202 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3203 | Outputs.addArgument(Out); |
| 3204 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3205 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3206 | return false; |
| 3207 | |
| 3208 | } |
| 3209 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3210 | //===----------------------------------------------------------------------===// |
| 3211 | // Type transformation |
| 3212 | //===----------------------------------------------------------------------===// |
| 3213 | |
| 3214 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3215 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3216 | if (getDerived().AlreadyTransformed(T)) |
| 3217 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3218 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3219 | // Temporary workaround. All of these transformations should |
| 3220 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3221 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3222 | getDerived().getBaseLocation()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3223 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3224 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3225 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3226 | if (!NewDI) |
| 3227 | return QualType(); |
| 3228 | |
| 3229 | return NewDI->getType(); |
| 3230 | } |
| 3231 | |
| 3232 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3233 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3234 | // Refine the base location to the type's location. |
| 3235 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3236 | getDerived().getBaseEntity()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3237 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3238 | return DI; |
| 3239 | |
| 3240 | TypeLocBuilder TLB; |
| 3241 | |
| 3242 | TypeLoc TL = DI->getTypeLoc(); |
| 3243 | TLB.reserve(TL.getFullDataSize()); |
| 3244 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3245 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3246 | if (Result.isNull()) |
| 3247 | return 0; |
| 3248 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3249 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | template<typename Derived> |
| 3253 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3254 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3255 | switch (T.getTypeLocClass()) { |
| 3256 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3257 | #define TYPELOC(CLASS, PARENT) \ |
| 3258 | case TypeLoc::CLASS: \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3259 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3260 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3261 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3262 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3263 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3267 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3268 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3269 | /// types). This is the right thing for template instantiation, but |
| 3270 | /// probably not for other clients. |
| 3271 | template<typename Derived> |
| 3272 | QualType |
| 3273 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3274 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3275 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3276 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3277 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3278 | if (Result.isNull()) |
| 3279 | return QualType(); |
| 3280 | |
| 3281 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3282 | // FIXME: this is the right thing for template instantiation, but |
| 3283 | // probably not for other clients. |
| 3284 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3285 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3287 | // 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] | 3288 | // resulting type. |
| 3289 | if (Quals.hasObjCLifetime()) { |
| 3290 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3291 | Quals.removeObjCLifetime(); |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3292 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3293 | // Objective-C ARC: |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3294 | // A lifetime qualifier applied to a substituted template parameter |
| 3295 | // overrides the lifetime qualifier from the template argument. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3296 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3297 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3298 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3299 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3300 | Qs.removeObjCLifetime(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3301 | Replacement |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3302 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3303 | Qs); |
| 3304 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3305 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3306 | Replacement); |
| 3307 | TLB.TypeWasModifiedSafely(Result); |
| 3308 | } else { |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3309 | // Otherwise, complain about the addition of a qualifier to an |
| 3310 | // already-qualified type. |
| 3311 | SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3312 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3313 | << Result << R; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3314 | |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3315 | Quals.removeObjCLifetime(); |
| 3316 | } |
| 3317 | } |
| 3318 | } |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3319 | if (!Quals.empty()) { |
| 3320 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3321 | TLB.push<QualifiedTypeLoc>(Result); |
| 3322 | // No location information to preserve. |
| 3323 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3324 | |
| 3325 | return Result; |
| 3326 | } |
| 3327 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3328 | template<typename Derived> |
| 3329 | TypeLoc |
| 3330 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3331 | QualType ObjectType, |
| 3332 | NamedDecl *UnqualLookup, |
| 3333 | CXXScopeSpec &SS) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3334 | QualType T = TL.getType(); |
| 3335 | if (getDerived().AlreadyTransformed(T)) |
| 3336 | return TL; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3337 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3338 | TypeLocBuilder TLB; |
| 3339 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3340 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3341 | if (isa<TemplateSpecializationType>(T)) { |
| 3342 | TemplateSpecializationTypeLoc SpecTL |
| 3343 | = cast<TemplateSpecializationTypeLoc>(TL); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3344 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3345 | TemplateName Template = |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3346 | getDerived().TransformTemplateName(SS, |
| 3347 | SpecTL.getTypePtr()->getTemplateName(), |
| 3348 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3349 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3350 | if (Template.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3351 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3352 | |
| 3353 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3354 | Template); |
| 3355 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3356 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3357 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3358 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3359 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3360 | = getDerived().RebuildTemplateName(SS, |
| 3361 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3362 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3363 | ObjectType, UnqualLookup); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3364 | if (Template.isNull()) |
| 3365 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3366 | |
| 3367 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3368 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3369 | Template, |
| 3370 | SS); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3371 | } else { |
| 3372 | // Nothing special needs to be done for these. |
| 3373 | Result = getDerived().TransformType(TLB, TL); |
| 3374 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3375 | |
| 3376 | if (Result.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3377 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3378 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3379 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3380 | } |
| 3381 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3382 | template<typename Derived> |
| 3383 | TypeSourceInfo * |
| 3384 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3385 | QualType ObjectType, |
| 3386 | NamedDecl *UnqualLookup, |
| 3387 | CXXScopeSpec &SS) { |
| 3388 | // FIXME: Painfully copy-paste from the above! |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3389 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3390 | QualType T = TSInfo->getType(); |
| 3391 | if (getDerived().AlreadyTransformed(T)) |
| 3392 | return TSInfo; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3393 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3394 | TypeLocBuilder TLB; |
| 3395 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3396 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3397 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3398 | if (isa<TemplateSpecializationType>(T)) { |
| 3399 | TemplateSpecializationTypeLoc SpecTL |
| 3400 | = cast<TemplateSpecializationTypeLoc>(TL); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3401 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3402 | TemplateName Template |
| 3403 | = getDerived().TransformTemplateName(SS, |
| 3404 | SpecTL.getTypePtr()->getTemplateName(), |
| 3405 | SpecTL.getTemplateNameLoc(), |
| 3406 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3407 | if (Template.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3408 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3409 | |
| 3410 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3411 | Template); |
| 3412 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3413 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3414 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3415 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3416 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3417 | = getDerived().RebuildTemplateName(SS, |
| 3418 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3419 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3420 | ObjectType, UnqualLookup); |
| 3421 | if (Template.isNull()) |
| 3422 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3423 | |
| 3424 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3425 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3426 | Template, |
| 3427 | SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3428 | } else { |
| 3429 | // Nothing special needs to be done for these. |
| 3430 | Result = getDerived().TransformType(TLB, TL); |
| 3431 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3432 | |
| 3433 | if (Result.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3434 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3435 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3436 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3437 | } |
| 3438 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3439 | template <class TyLoc> static inline |
| 3440 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3441 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3442 | NewT.setNameLoc(T.getNameLoc()); |
| 3443 | return T.getType(); |
| 3444 | } |
| 3445 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3446 | template<typename Derived> |
| 3447 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3448 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3449 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3450 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3451 | if (T.needsExtraLocalData()) |
| 3452 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3453 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3454 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3455 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3456 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3457 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3458 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3459 | // FIXME: recurse? |
| 3460 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3461 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3463 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3464 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3465 | PointerTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3466 | QualType PointeeType |
| 3467 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3468 | if (PointeeType.isNull()) |
| 3469 | return QualType(); |
| 3470 | |
| 3471 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3472 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3473 | // A dependent pointer type 'T *' has is being transformed such |
| 3474 | // that an Objective-C class type is being replaced for 'T'. The |
| 3475 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3476 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3477 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3478 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3479 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3480 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3481 | return Result; |
| 3482 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3483 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3484 | if (getDerived().AlwaysRebuild() || |
| 3485 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3486 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3487 | if (Result.isNull()) |
| 3488 | return QualType(); |
| 3489 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3490 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3491 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3492 | // pointing to. |
| 3493 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3494 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3495 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3496 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3497 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3498 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3499 | |
| 3500 | template<typename Derived> |
| 3501 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3502 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3503 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3504 | QualType PointeeType |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3505 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3506 | if (PointeeType.isNull()) |
| 3507 | return QualType(); |
| 3508 | |
| 3509 | QualType Result = TL.getType(); |
| 3510 | if (getDerived().AlwaysRebuild() || |
| 3511 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3512 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3513 | TL.getSigilLoc()); |
| 3514 | if (Result.isNull()) |
| 3515 | return QualType(); |
| 3516 | } |
| 3517 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3518 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3519 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3520 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3521 | } |
| 3522 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3523 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3524 | /// don't care whether the type itself is an l-value type or an r-value |
| 3525 | /// type; we only care if the type was *written* as an l-value type |
| 3526 | /// or an r-value type. |
| 3527 | template<typename Derived> |
| 3528 | QualType |
| 3529 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3530 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3531 | const ReferenceType *T = TL.getTypePtr(); |
| 3532 | |
| 3533 | // Note that this works with the pointee-as-written. |
| 3534 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3535 | if (PointeeType.isNull()) |
| 3536 | return QualType(); |
| 3537 | |
| 3538 | QualType Result = TL.getType(); |
| 3539 | if (getDerived().AlwaysRebuild() || |
| 3540 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3541 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3542 | T->isSpelledAsLValue(), |
| 3543 | TL.getSigilLoc()); |
| 3544 | if (Result.isNull()) |
| 3545 | return QualType(); |
| 3546 | } |
| 3547 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3548 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3549 | // referring to. |
| 3550 | TLB.TypeWasModifiedSafely( |
| 3551 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3552 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3553 | // r-value references can be rebuilt as l-value references. |
| 3554 | ReferenceTypeLoc NewTL; |
| 3555 | if (isa<LValueReferenceType>(Result)) |
| 3556 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3557 | else |
| 3558 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3559 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3560 | |
| 3561 | return Result; |
| 3562 | } |
| 3563 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3564 | template<typename Derived> |
| 3565 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3566 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3567 | LValueReferenceTypeLoc TL) { |
| 3568 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3569 | } |
| 3570 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3571 | template<typename Derived> |
| 3572 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3573 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3574 | RValueReferenceTypeLoc TL) { |
| 3575 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3576 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3577 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3578 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3579 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3580 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3581 | MemberPointerTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3582 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3583 | if (PointeeType.isNull()) |
| 3584 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3586 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3587 | TypeSourceInfo* NewClsTInfo = 0; |
| 3588 | if (OldClsTInfo) { |
| 3589 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3590 | if (!NewClsTInfo) |
| 3591 | return QualType(); |
| 3592 | } |
| 3593 | |
| 3594 | const MemberPointerType *T = TL.getTypePtr(); |
| 3595 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3596 | QualType NewClsType; |
| 3597 | if (NewClsTInfo) |
| 3598 | NewClsType = NewClsTInfo->getType(); |
| 3599 | else { |
| 3600 | NewClsType = getDerived().TransformType(OldClsType); |
| 3601 | if (NewClsType.isNull()) |
| 3602 | return QualType(); |
| 3603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3605 | QualType Result = TL.getType(); |
| 3606 | if (getDerived().AlwaysRebuild() || |
| 3607 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3608 | NewClsType != OldClsType) { |
| 3609 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3610 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3611 | if (Result.isNull()) |
| 3612 | return QualType(); |
| 3613 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3614 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3615 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3616 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3617 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3618 | |
| 3619 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | template<typename Derived> |
| 3623 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3624 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3625 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3626 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3627 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3628 | if (ElementType.isNull()) |
| 3629 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3630 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3631 | QualType Result = TL.getType(); |
| 3632 | if (getDerived().AlwaysRebuild() || |
| 3633 | ElementType != T->getElementType()) { |
| 3634 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3635 | T->getSizeModifier(), |
| 3636 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3637 | T->getIndexTypeCVRQualifiers(), |
| 3638 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3639 | if (Result.isNull()) |
| 3640 | return QualType(); |
| 3641 | } |
Eli Friedman | 457a377 | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 3642 | |
| 3643 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 3644 | // a ConstantArrayType is allowed to have an element type which is a |
| 3645 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 3646 | // types have the same location layout. |
| 3647 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3648 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3649 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3650 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3651 | Expr *Size = TL.getSizeExpr(); |
| 3652 | if (Size) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3653 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3654 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3655 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3656 | Size = SemaRef.ActOnConstantExpression(Size).take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3657 | } |
| 3658 | NewTL.setSizeExpr(Size); |
| 3659 | |
| 3660 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3661 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3662 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3663 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3664 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3665 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3666 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3667 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3668 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3669 | if (ElementType.isNull()) |
| 3670 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3671 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3672 | QualType Result = TL.getType(); |
| 3673 | if (getDerived().AlwaysRebuild() || |
| 3674 | ElementType != T->getElementType()) { |
| 3675 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3676 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3677 | T->getIndexTypeCVRQualifiers(), |
| 3678 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3679 | if (Result.isNull()) |
| 3680 | return QualType(); |
| 3681 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3682 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3683 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3684 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3685 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3686 | NewTL.setSizeExpr(0); |
| 3687 | |
| 3688 | return Result; |
| 3689 | } |
| 3690 | |
| 3691 | template<typename Derived> |
| 3692 | QualType |
| 3693 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3694 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3695 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3696 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3697 | if (ElementType.isNull()) |
| 3698 | return QualType(); |
| 3699 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3700 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3701 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3702 | if (SizeResult.isInvalid()) |
| 3703 | return QualType(); |
| 3704 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3705 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3706 | |
| 3707 | QualType Result = TL.getType(); |
| 3708 | if (getDerived().AlwaysRebuild() || |
| 3709 | ElementType != T->getElementType() || |
| 3710 | Size != T->getSizeExpr()) { |
| 3711 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3712 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3713 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3714 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3715 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3716 | if (Result.isNull()) |
| 3717 | return QualType(); |
| 3718 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3719 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3720 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3721 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3722 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3723 | NewTL.setSizeExpr(Size); |
| 3724 | |
| 3725 | return Result; |
| 3726 | } |
| 3727 | |
| 3728 | template<typename Derived> |
| 3729 | QualType |
| 3730 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3731 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3732 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3733 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3734 | if (ElementType.isNull()) |
| 3735 | return QualType(); |
| 3736 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3737 | // Array bounds are constant expressions. |
| 3738 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3739 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3740 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3741 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3742 | Expr *origSize = TL.getSizeExpr(); |
| 3743 | if (!origSize) origSize = T->getSizeExpr(); |
| 3744 | |
| 3745 | ExprResult sizeResult |
| 3746 | = getDerived().TransformExpr(origSize); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3747 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3748 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3749 | return QualType(); |
| 3750 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3751 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3752 | |
| 3753 | QualType Result = TL.getType(); |
| 3754 | if (getDerived().AlwaysRebuild() || |
| 3755 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3756 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3757 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3758 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3759 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3760 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3761 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3762 | if (Result.isNull()) |
| 3763 | return QualType(); |
| 3764 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3765 | |
| 3766 | // We might have any sort of array type now, but fortunately they |
| 3767 | // all have the same location layout. |
| 3768 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3769 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3770 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3771 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3772 | |
| 3773 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3774 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3775 | |
| 3776 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3777 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3778 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3779 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3780 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3781 | |
| 3782 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3783 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3784 | if (ElementType.isNull()) |
| 3785 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3786 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3787 | // Vector sizes are constant expressions. |
| 3788 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3789 | Sema::ConstantEvaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3790 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3791 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3792 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3793 | if (Size.isInvalid()) |
| 3794 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3796 | QualType Result = TL.getType(); |
| 3797 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3798 | ElementType != T->getElementType() || |
| 3799 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3800 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3801 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3802 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3803 | if (Result.isNull()) |
| 3804 | return QualType(); |
| 3805 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3806 | |
| 3807 | // Result might be dependent or not. |
| 3808 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3809 | DependentSizedExtVectorTypeLoc NewTL |
| 3810 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3811 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3812 | } else { |
| 3813 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3814 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3815 | } |
| 3816 | |
| 3817 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3818 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | |
| 3820 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3821 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3822 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3823 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3824 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3825 | if (ElementType.isNull()) |
| 3826 | return QualType(); |
| 3827 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3828 | QualType Result = TL.getType(); |
| 3829 | if (getDerived().AlwaysRebuild() || |
| 3830 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3831 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3832 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3833 | if (Result.isNull()) |
| 3834 | return QualType(); |
| 3835 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3836 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3837 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3838 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3839 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3840 | return Result; |
| 3841 | } |
| 3842 | |
| 3843 | template<typename Derived> |
| 3844 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3845 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3846 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3847 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3848 | if (ElementType.isNull()) |
| 3849 | return QualType(); |
| 3850 | |
| 3851 | QualType Result = TL.getType(); |
| 3852 | if (getDerived().AlwaysRebuild() || |
| 3853 | ElementType != T->getElementType()) { |
| 3854 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3855 | T->getNumElements(), |
| 3856 | /*FIXME*/ SourceLocation()); |
| 3857 | if (Result.isNull()) |
| 3858 | return QualType(); |
| 3859 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3860 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3861 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3862 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3863 | |
| 3864 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3865 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | |
| 3867 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3868 | ParmVarDecl * |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3869 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3870 | int indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 3871 | llvm::Optional<unsigned> NumExpansions, |
| 3872 | bool ExpectParameterPack) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3873 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3874 | TypeSourceInfo *NewDI = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3875 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3876 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3877 | // 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] | 3878 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3879 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3880 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3881 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3882 | TypeLocBuilder TLB; |
| 3883 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3884 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3885 | |
| 3886 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3887 | OldExpansionTL.getPatternLoc()); |
| 3888 | if (Result.isNull()) |
| 3889 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3890 | |
| 3891 | Result = RebuildPackExpansionType(Result, |
| 3892 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3893 | OldExpansionTL.getEllipsisLoc(), |
| 3894 | NumExpansions); |
| 3895 | if (Result.isNull()) |
| 3896 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3897 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3898 | PackExpansionTypeLoc NewExpansionTL |
| 3899 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3900 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3901 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3902 | } else |
| 3903 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3904 | if (!NewDI) |
| 3905 | return 0; |
| 3906 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3907 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3908 | return OldParm; |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3909 | |
| 3910 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 3911 | OldParm->getDeclContext(), |
| 3912 | OldParm->getInnerLocStart(), |
| 3913 | OldParm->getLocation(), |
| 3914 | OldParm->getIdentifier(), |
| 3915 | NewDI->getType(), |
| 3916 | NewDI, |
| 3917 | OldParm->getStorageClass(), |
| 3918 | OldParm->getStorageClassAsWritten(), |
| 3919 | /* DefArg */ NULL); |
| 3920 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 3921 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 3922 | return newParm; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | template<typename Derived> |
| 3926 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3927 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3928 | ParmVarDecl **Params, unsigned NumParams, |
| 3929 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3930 | SmallVectorImpl<QualType> &OutParamTypes, |
| 3931 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3932 | int indexAdjustment = 0; |
| 3933 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3934 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3935 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3936 | assert(OldParm->getFunctionScopeIndex() == i); |
| 3937 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3938 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3939 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3940 | if (OldParm->isParameterPack()) { |
| 3941 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3942 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3943 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3944 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3945 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3946 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3947 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3948 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3949 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 3950 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3951 | // Determine whether we should expand the parameter packs. |
| 3952 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3953 | bool RetainExpansion = false; |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3954 | llvm::Optional<unsigned> OrigNumExpansions |
| 3955 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3956 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3957 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3958 | Pattern.getSourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3959 | Unexpanded, |
| 3960 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3961 | RetainExpansion, |
| 3962 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3963 | return true; |
| 3964 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3965 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3966 | if (ShouldExpand) { |
| 3967 | // Expand the function parameter pack into multiple, separate |
| 3968 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3969 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3970 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3971 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3972 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3973 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3974 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 3975 | OrigNumExpansions, |
| 3976 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3977 | if (!NewParm) |
| 3978 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3980 | OutParamTypes.push_back(NewParm->getType()); |
| 3981 | if (PVars) |
| 3982 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3983 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3984 | |
| 3985 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3986 | // forgetting the partially-substituted parameter pack. |
| 3987 | if (RetainExpansion) { |
| 3988 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3989 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3990 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3991 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 3992 | OrigNumExpansions, |
| 3993 | /*ExpectParameterPack=*/false); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3994 | if (!NewParm) |
| 3995 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3996 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3997 | OutParamTypes.push_back(NewParm->getType()); |
| 3998 | if (PVars) |
| 3999 | PVars->push_back(NewParm); |
| 4000 | } |
| 4001 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4002 | // The next parameter should have the same adjustment as the |
| 4003 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4004 | // on every push. Also, if we push nothing, the adjustment should |
| 4005 | // go down by one. |
| 4006 | indexAdjustment--; |
| 4007 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4008 | // We're done with the pack expansion. |
| 4009 | continue; |
| 4010 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4011 | |
| 4012 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4013 | // expansion. |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4014 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4015 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4016 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4017 | NumExpansions, |
| 4018 | /*ExpectParameterPack=*/true); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4019 | } else { |
| 4020 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4021 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4022 | llvm::Optional<unsigned>(), |
| 4023 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4024 | } |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4025 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4026 | if (!NewParm) |
| 4027 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4028 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4029 | OutParamTypes.push_back(NewParm->getType()); |
| 4030 | if (PVars) |
| 4031 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4032 | continue; |
| 4033 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4034 | |
| 4035 | // Deal with the possibility that we don't have a parameter |
| 4036 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4037 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4038 | bool IsPackExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4039 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4040 | QualType NewType; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4041 | if (const PackExpansionType *Expansion |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4042 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4043 | // We have a function parameter pack that may need to be expanded. |
| 4044 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4045 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4046 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4047 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4048 | // Determine whether we should expand the parameter packs. |
| 4049 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4050 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4051 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4052 | Unexpanded, |
| 4053 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4054 | RetainExpansion, |
| 4055 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4056 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4057 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4059 | if (ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4060 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4061 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4062 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4063 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4064 | QualType NewType = getDerived().TransformType(Pattern); |
| 4065 | if (NewType.isNull()) |
| 4066 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4067 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4068 | OutParamTypes.push_back(NewType); |
| 4069 | if (PVars) |
| 4070 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4071 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4072 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4073 | // We're done with the pack expansion. |
| 4074 | continue; |
| 4075 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4076 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4077 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4078 | // forgetting the partially-substituted parameter pack. |
| 4079 | if (RetainExpansion) { |
| 4080 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4081 | QualType NewType = getDerived().TransformType(Pattern); |
| 4082 | if (NewType.isNull()) |
| 4083 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4084 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4085 | OutParamTypes.push_back(NewType); |
| 4086 | if (PVars) |
| 4087 | PVars->push_back(0); |
| 4088 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4089 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4090 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4091 | // expansion. |
| 4092 | OldType = Expansion->getPattern(); |
| 4093 | IsPackExpansion = true; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4094 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4095 | NewType = getDerived().TransformType(OldType); |
| 4096 | } else { |
| 4097 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4098 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4099 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4100 | if (NewType.isNull()) |
| 4101 | return true; |
| 4102 | |
| 4103 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4104 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4105 | NumExpansions); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4106 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4107 | OutParamTypes.push_back(NewType); |
| 4108 | if (PVars) |
| 4109 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4110 | } |
| 4111 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4112 | #ifndef NDEBUG |
| 4113 | if (PVars) { |
| 4114 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4115 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4116 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4117 | } |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4118 | #endif |
| 4119 | |
| 4120 | return false; |
| 4121 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4122 | |
| 4123 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4124 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4125 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4126 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4127 | return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); |
| 4128 | } |
| 4129 | |
| 4130 | template<typename Derived> |
| 4131 | QualType |
| 4132 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4133 | FunctionProtoTypeLoc TL, |
| 4134 | CXXRecordDecl *ThisContext, |
| 4135 | unsigned ThisTypeQuals) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4136 | // Transform the parameters and return type. |
| 4137 | // |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4138 | // 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] | 4139 | // When the function has a trailing return type, we instantiate the |
| 4140 | // parameters before the return type, since the return type can then refer |
| 4141 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4142 | // |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4143 | SmallVector<QualType, 4> ParamTypes; |
| 4144 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4145 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4146 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4147 | QualType ResultType; |
| 4148 | |
Richard Smith | 9fbf327 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4149 | if (T->hasTrailingReturn()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4150 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4151 | TL.getParmArray(), |
| 4152 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4153 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4154 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4155 | return QualType(); |
| 4156 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4157 | { |
| 4158 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4159 | // If a declaration declares a member function or member function |
| 4160 | // 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] | 4161 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4162 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4163 | // declarator. |
| 4164 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4165 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4166 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4167 | if (ResultType.isNull()) |
| 4168 | return QualType(); |
| 4169 | } |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4170 | } |
| 4171 | else { |
| 4172 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4173 | if (ResultType.isNull()) |
| 4174 | return QualType(); |
| 4175 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4176 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4177 | TL.getParmArray(), |
| 4178 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4179 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4180 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4181 | return QualType(); |
| 4182 | } |
| 4183 | |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4184 | // FIXME: Need to transform the exception-specification too. |
| 4185 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4186 | QualType Result = TL.getType(); |
| 4187 | if (getDerived().AlwaysRebuild() || |
| 4188 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4189 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4190 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 4191 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 4192 | ParamTypes.data(), |
| 4193 | ParamTypes.size(), |
| 4194 | T->isVariadic(), |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 4195 | T->hasTrailingReturn(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4196 | T->getTypeQuals(), |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 4197 | T->getRefQualifier(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4198 | T->getExtInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4199 | if (Result.isNull()) |
| 4200 | return QualType(); |
| 4201 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4202 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4203 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4204 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4205 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4206 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4207 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4208 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4209 | NewTL.setArg(i, ParamDecls[i]); |
| 4210 | |
| 4211 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4214 | template<typename Derived> |
| 4215 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4216 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4217 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4218 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4219 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4220 | if (ResultType.isNull()) |
| 4221 | return QualType(); |
| 4222 | |
| 4223 | QualType Result = TL.getType(); |
| 4224 | if (getDerived().AlwaysRebuild() || |
| 4225 | ResultType != T->getResultType()) |
| 4226 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4227 | |
| 4228 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4229 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4230 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4231 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4232 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4233 | |
| 4234 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4235 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4237 | template<typename Derived> QualType |
| 4238 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4239 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4240 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4241 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4242 | if (!D) |
| 4243 | return QualType(); |
| 4244 | |
| 4245 | QualType Result = TL.getType(); |
| 4246 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4247 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4248 | if (Result.isNull()) |
| 4249 | return QualType(); |
| 4250 | } |
| 4251 | |
| 4252 | // We might get an arbitrary type spec type back. We should at |
| 4253 | // least always get a type spec type, though. |
| 4254 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4255 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4256 | |
| 4257 | return Result; |
| 4258 | } |
| 4259 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4260 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4261 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4262 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4263 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4264 | TypedefNameDecl *Typedef |
| 4265 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4266 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4267 | if (!Typedef) |
| 4268 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4269 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4270 | QualType Result = TL.getType(); |
| 4271 | if (getDerived().AlwaysRebuild() || |
| 4272 | Typedef != T->getDecl()) { |
| 4273 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4274 | if (Result.isNull()) |
| 4275 | return QualType(); |
| 4276 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4277 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4278 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4279 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4280 | |
| 4281 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4282 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4283 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4284 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4285 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4286 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4287 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4288 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4289 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4291 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4292 | if (E.isInvalid()) |
| 4293 | return QualType(); |
| 4294 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4295 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4296 | if (E.isInvalid()) |
| 4297 | return QualType(); |
| 4298 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4299 | QualType Result = TL.getType(); |
| 4300 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4301 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4302 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4303 | if (Result.isNull()) |
| 4304 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4305 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4306 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4307 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4308 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4309 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4310 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4311 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4312 | |
| 4313 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4315 | |
| 4316 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4317 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4318 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4319 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4320 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4321 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4322 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4323 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4324 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4325 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4326 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4327 | if (Result.isNull()) |
| 4328 | return QualType(); |
| 4329 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4331 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4332 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4333 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4334 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4335 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4336 | |
| 4337 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | |
| 4340 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4341 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4342 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4343 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4344 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4345 | // decltype expressions are not potentially evaluated contexts |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4346 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, |
| 4347 | /*IsDecltype=*/ true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4348 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4349 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4350 | if (E.isInvalid()) |
| 4351 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4352 | |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4353 | E = getSema().ActOnDecltypeExpression(E.take()); |
| 4354 | if (E.isInvalid()) |
| 4355 | return QualType(); |
| 4356 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4357 | QualType Result = TL.getType(); |
| 4358 | if (getDerived().AlwaysRebuild() || |
| 4359 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4360 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4361 | if (Result.isNull()) |
| 4362 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4363 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4364 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4366 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4367 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4368 | |
| 4369 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4373 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4374 | TypeLocBuilder &TLB, |
| 4375 | UnaryTransformTypeLoc TL) { |
| 4376 | QualType Result = TL.getType(); |
| 4377 | if (Result->isDependentType()) { |
| 4378 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4379 | QualType NewBase = |
| 4380 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4381 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4382 | T->getUTTKind(), |
| 4383 | TL.getKWLoc()); |
| 4384 | if (Result.isNull()) |
| 4385 | return QualType(); |
| 4386 | } |
| 4387 | |
| 4388 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4389 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4390 | NewTL.setParensRange(TL.getParensRange()); |
| 4391 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4392 | return Result; |
| 4393 | } |
| 4394 | |
| 4395 | template<typename Derived> |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4396 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4397 | AutoTypeLoc TL) { |
| 4398 | const AutoType *T = TL.getTypePtr(); |
| 4399 | QualType OldDeduced = T->getDeducedType(); |
| 4400 | QualType NewDeduced; |
| 4401 | if (!OldDeduced.isNull()) { |
| 4402 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4403 | if (NewDeduced.isNull()) |
| 4404 | return QualType(); |
| 4405 | } |
| 4406 | |
| 4407 | QualType Result = TL.getType(); |
| 4408 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4409 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4410 | if (Result.isNull()) |
| 4411 | return QualType(); |
| 4412 | } |
| 4413 | |
| 4414 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4415 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4416 | |
| 4417 | return Result; |
| 4418 | } |
| 4419 | |
| 4420 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4421 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4422 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4423 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4424 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4425 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4426 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4427 | if (!Record) |
| 4428 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4429 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4430 | QualType Result = TL.getType(); |
| 4431 | if (getDerived().AlwaysRebuild() || |
| 4432 | Record != T->getDecl()) { |
| 4433 | Result = getDerived().RebuildRecordType(Record); |
| 4434 | if (Result.isNull()) |
| 4435 | return QualType(); |
| 4436 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4437 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4438 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4439 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4440 | |
| 4441 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4442 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4443 | |
| 4444 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4445 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4446 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4447 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4448 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4449 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4450 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4451 | if (!Enum) |
| 4452 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4453 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4454 | QualType Result = TL.getType(); |
| 4455 | if (getDerived().AlwaysRebuild() || |
| 4456 | Enum != T->getDecl()) { |
| 4457 | Result = getDerived().RebuildEnumType(Enum); |
| 4458 | if (Result.isNull()) |
| 4459 | return QualType(); |
| 4460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4461 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4462 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4463 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4464 | |
| 4465 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4466 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4467 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4468 | template<typename Derived> |
| 4469 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4470 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4471 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4472 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4473 | TL.getTypePtr()->getDecl()); |
| 4474 | if (!D) return QualType(); |
| 4475 | |
| 4476 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4477 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4478 | return T; |
| 4479 | } |
| 4480 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4481 | template<typename Derived> |
| 4482 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4483 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4484 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4485 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4486 | } |
| 4487 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4488 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4489 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4490 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4491 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4492 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4493 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4494 | // Substitute into the replacement type, which itself might involve something |
| 4495 | // that needs to be transformed. This only tends to occur with default |
| 4496 | // template arguments of template template parameters. |
| 4497 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4498 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4499 | if (Replacement.isNull()) |
| 4500 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4501 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4502 | // Always canonicalize the replacement type. |
| 4503 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4504 | QualType Result |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4505 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4506 | Replacement); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4507 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4508 | // Propagate type-source information. |
| 4509 | SubstTemplateTypeParmTypeLoc NewTL |
| 4510 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4511 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4512 | return Result; |
| 4513 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4517 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4518 | TypeLocBuilder &TLB, |
| 4519 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4520 | return TransformTypeSpecType(TLB, TL); |
| 4521 | } |
| 4522 | |
| 4523 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4524 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4525 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4526 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4527 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4528 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4529 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4530 | // because we can't have a dependent nested-name-specifier anyway. |
| 4531 | CXXScopeSpec SS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4533 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4534 | TL.getTemplateNameLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4535 | if (Template.isNull()) |
| 4536 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4537 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4538 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4539 | } |
| 4540 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4541 | template<typename Derived> |
| 4542 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4543 | AtomicTypeLoc TL) { |
| 4544 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4545 | if (ValueType.isNull()) |
| 4546 | return QualType(); |
| 4547 | |
| 4548 | QualType Result = TL.getType(); |
| 4549 | if (getDerived().AlwaysRebuild() || |
| 4550 | ValueType != TL.getValueLoc().getType()) { |
| 4551 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4552 | if (Result.isNull()) |
| 4553 | return QualType(); |
| 4554 | } |
| 4555 | |
| 4556 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4557 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4558 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4559 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4560 | |
| 4561 | return Result; |
| 4562 | } |
| 4563 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4564 | namespace { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4565 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4566 | /// container that provides a \c getArgLoc() member function. |
| 4567 | /// |
| 4568 | /// This iterator is intended to be used with the iterator form of |
| 4569 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4570 | template<typename ArgLocContainer> |
| 4571 | class TemplateArgumentLocContainerIterator { |
| 4572 | ArgLocContainer *Container; |
| 4573 | unsigned Index; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4574 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4575 | public: |
| 4576 | typedef TemplateArgumentLoc value_type; |
| 4577 | typedef TemplateArgumentLoc reference; |
| 4578 | typedef int difference_type; |
| 4579 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4580 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4581 | class pointer { |
| 4582 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4583 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4584 | public: |
| 4585 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4586 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4587 | const TemplateArgumentLoc *operator->() const { |
| 4588 | return &Arg; |
| 4589 | } |
| 4590 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4591 | |
| 4592 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4593 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4594 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4595 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4596 | unsigned Index) |
| 4597 | : Container(&Container), Index(Index) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4598 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4599 | TemplateArgumentLocContainerIterator &operator++() { |
| 4600 | ++Index; |
| 4601 | return *this; |
| 4602 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4603 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4604 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4605 | TemplateArgumentLocContainerIterator Old(*this); |
| 4606 | ++(*this); |
| 4607 | return Old; |
| 4608 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4609 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4610 | TemplateArgumentLoc operator*() const { |
| 4611 | return Container->getArgLoc(Index); |
| 4612 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4613 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4614 | pointer operator->() const { |
| 4615 | return pointer(Container->getArgLoc(Index)); |
| 4616 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4617 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4618 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4619 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4620 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4621 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4622 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4623 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4624 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4625 | return !(X == Y); |
| 4626 | } |
| 4627 | }; |
| 4628 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4629 | |
| 4630 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4631 | template <typename Derived> |
| 4632 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4633 | TypeLocBuilder &TLB, |
| 4634 | TemplateSpecializationTypeLoc TL, |
| 4635 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4636 | TemplateArgumentListInfo NewTemplateArgs; |
| 4637 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4638 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4639 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4640 | ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4641 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4642 | ArgIterator(TL, TL.getNumArgs()), |
| 4643 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4644 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4645 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4646 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4647 | |
| 4648 | QualType Result = |
| 4649 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4650 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4651 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4652 | |
| 4653 | if (!Result.isNull()) { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4654 | // Specializations of template template parameters are represented as |
| 4655 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4656 | // within a dependent context can transform them into |
| 4657 | // DependentTemplateSpecializationTypes. |
| 4658 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4659 | DependentTemplateSpecializationTypeLoc NewTL |
| 4660 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4661 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4662 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4663 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4664 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4665 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4666 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4667 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4668 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4669 | return Result; |
| 4670 | } |
| 4671 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4672 | TemplateSpecializationTypeLoc NewTL |
| 4673 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4674 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4675 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4676 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4677 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4678 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4679 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4681 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4682 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4683 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4684 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4685 | template <typename Derived> |
| 4686 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4687 | TypeLocBuilder &TLB, |
| 4688 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4689 | TemplateName Template, |
| 4690 | CXXScopeSpec &SS) { |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4691 | TemplateArgumentListInfo NewTemplateArgs; |
| 4692 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4693 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4694 | typedef TemplateArgumentLocContainerIterator< |
| 4695 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4696 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4697 | ArgIterator(TL, TL.getNumArgs()), |
| 4698 | NewTemplateArgs)) |
| 4699 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4700 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4701 | // 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] | 4702 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4703 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4704 | QualType Result |
| 4705 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4706 | TL.getTypePtr()->getKeyword(), |
| 4707 | DTN->getQualifier(), |
| 4708 | DTN->getIdentifier(), |
| 4709 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4710 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4711 | DependentTemplateSpecializationTypeLoc NewTL |
| 4712 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4713 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4714 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4715 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4716 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4717 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4718 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4719 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4720 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4721 | return Result; |
| 4722 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4723 | |
| 4724 | QualType Result |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4725 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4726 | TL.getTemplateNameLoc(), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4727 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4728 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4729 | if (!Result.isNull()) { |
| 4730 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4731 | TemplateSpecializationTypeLoc NewTL |
| 4732 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4733 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4734 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4735 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4736 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4737 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4738 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4739 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4740 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4741 | return Result; |
| 4742 | } |
| 4743 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4744 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4745 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4746 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4747 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4748 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4749 | |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4750 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4751 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4752 | if (TL.getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4753 | QualifierLoc |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4754 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4755 | if (!QualifierLoc) |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4756 | return QualType(); |
| 4757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4758 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4759 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4760 | if (NamedT.isNull()) |
| 4761 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4762 | |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4763 | // C++0x [dcl.type.elab]p2: |
| 4764 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4765 | // resolves to an alias template specialization, the |
| 4766 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 1804174 | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 4767 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 4768 | if (const TemplateSpecializationType *TST = |
| 4769 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4770 | TemplateName Template = TST->getTemplateName(); |
| 4771 | if (TypeAliasTemplateDecl *TAT = |
| 4772 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4773 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4774 | diag::err_tag_reference_non_tag) << 4; |
| 4775 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4776 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4777 | } |
| 4778 | } |
| 4779 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4780 | QualType Result = TL.getType(); |
| 4781 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4782 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4783 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4784 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4785 | T->getKeyword(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4786 | QualifierLoc, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4787 | if (Result.isNull()) |
| 4788 | return QualType(); |
| 4789 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4790 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4791 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4792 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4793 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4794 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4795 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4796 | |
| 4797 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4798 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4799 | TypeLocBuilder &TLB, |
| 4800 | AttributedTypeLoc TL) { |
| 4801 | const AttributedType *oldType = TL.getTypePtr(); |
| 4802 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4803 | if (modifiedType.isNull()) |
| 4804 | return QualType(); |
| 4805 | |
| 4806 | QualType result = TL.getType(); |
| 4807 | |
| 4808 | // FIXME: dependent operand expressions? |
| 4809 | if (getDerived().AlwaysRebuild() || |
| 4810 | modifiedType != oldType->getModifiedType()) { |
| 4811 | // TODO: this is really lame; we should really be rebuilding the |
| 4812 | // equivalent type from first principles. |
| 4813 | QualType equivalentType |
| 4814 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4815 | if (equivalentType.isNull()) |
| 4816 | return QualType(); |
| 4817 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4818 | modifiedType, |
| 4819 | equivalentType); |
| 4820 | } |
| 4821 | |
| 4822 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4823 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4824 | if (TL.hasAttrOperand()) |
| 4825 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4826 | if (TL.hasAttrExprOperand()) |
| 4827 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4828 | else if (TL.hasAttrEnumOperand()) |
| 4829 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4830 | |
| 4831 | return result; |
| 4832 | } |
| 4833 | |
| 4834 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4835 | QualType |
| 4836 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4837 | ParenTypeLoc TL) { |
| 4838 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4839 | if (Inner.isNull()) |
| 4840 | return QualType(); |
| 4841 | |
| 4842 | QualType Result = TL.getType(); |
| 4843 | if (getDerived().AlwaysRebuild() || |
| 4844 | Inner != TL.getInnerLoc().getType()) { |
| 4845 | Result = getDerived().RebuildParenType(Inner); |
| 4846 | if (Result.isNull()) |
| 4847 | return QualType(); |
| 4848 | } |
| 4849 | |
| 4850 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4851 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4852 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4853 | return Result; |
| 4854 | } |
| 4855 | |
| 4856 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4857 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4858 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4859 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4860 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4861 | NestedNameSpecifierLoc QualifierLoc |
| 4862 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4863 | if (!QualifierLoc) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4864 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4865 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4866 | QualType Result |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4867 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4868 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4869 | QualifierLoc, |
| 4870 | T->getIdentifier(), |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4871 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4872 | if (Result.isNull()) |
| 4873 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4874 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4875 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4876 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4877 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4878 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4879 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4880 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4881 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4882 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4883 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4884 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4885 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4886 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4887 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4888 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4889 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4890 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4891 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4892 | QualType TreeTransform<Derived>:: |
| 4893 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4894 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4895 | NestedNameSpecifierLoc QualifierLoc; |
| 4896 | if (TL.getQualifierLoc()) { |
| 4897 | QualifierLoc |
| 4898 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4899 | if (!QualifierLoc) |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4900 | return QualType(); |
| 4901 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4902 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4903 | return getDerived() |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4904 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | template<typename Derived> |
| 4908 | QualType TreeTransform<Derived>:: |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4909 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4910 | DependentTemplateSpecializationTypeLoc TL, |
| 4911 | NestedNameSpecifierLoc QualifierLoc) { |
| 4912 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4913 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4914 | TemplateArgumentListInfo NewTemplateArgs; |
| 4915 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4916 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4917 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4918 | typedef TemplateArgumentLocContainerIterator< |
| 4919 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4920 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4921 | ArgIterator(TL, TL.getNumArgs()), |
| 4922 | NewTemplateArgs)) |
| 4923 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4924 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4925 | QualType Result |
| 4926 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4927 | QualifierLoc, |
| 4928 | T->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4929 | TL.getTemplateNameLoc(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4930 | NewTemplateArgs); |
| 4931 | if (Result.isNull()) |
| 4932 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4933 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4934 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4935 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4936 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4937 | // Copy information relevant to the template specialization. |
| 4938 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4939 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4940 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4941 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4942 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4943 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4944 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4945 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4946 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4947 | // Copy information relevant to the elaborated type. |
| 4948 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4949 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4950 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4951 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4952 | DependentTemplateSpecializationTypeLoc SpecTL |
| 4953 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4954 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4955 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4956 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4957 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4958 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4959 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4960 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4961 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4962 | } else { |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4963 | TemplateSpecializationTypeLoc SpecTL |
| 4964 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4965 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4966 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4967 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4968 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4969 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4970 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4971 | } |
| 4972 | return Result; |
| 4973 | } |
| 4974 | |
| 4975 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4976 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4977 | PackExpansionTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4978 | QualType Pattern |
| 4979 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4980 | if (Pattern.isNull()) |
| 4981 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4982 | |
| 4983 | QualType Result = TL.getType(); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4984 | if (getDerived().AlwaysRebuild() || |
| 4985 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4986 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4987 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4988 | TL.getEllipsisLoc(), |
| 4989 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4990 | if (Result.isNull()) |
| 4991 | return QualType(); |
| 4992 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4993 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4994 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4995 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4996 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
| 4999 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5000 | QualType |
| 5001 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5002 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5003 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5004 | TLB.pushFullCopy(TL); |
| 5005 | return TL.getType(); |
| 5006 | } |
| 5007 | |
| 5008 | template<typename Derived> |
| 5009 | QualType |
| 5010 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5011 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5012 | // ObjCObjectType is never dependent. |
| 5013 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5014 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5015 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5016 | |
| 5017 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5018 | QualType |
| 5019 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5020 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5021 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5022 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5023 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5024 | } |
| 5025 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5026 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5027 | // Statement transformation |
| 5028 | //===----------------------------------------------------------------------===// |
| 5029 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5030 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5031 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5032 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5036 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5037 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5038 | return getDerived().TransformCompoundStmt(S, false); |
| 5039 | } |
| 5040 | |
| 5041 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5042 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5043 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5044 | bool IsStmtExpr) { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5045 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5046 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5047 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5048 | bool SubStmtChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5049 | SmallVector<Stmt*, 8> Statements; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5050 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 5051 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5052 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5053 | if (Result.isInvalid()) { |
| 5054 | // Immediately fail if this was a DeclStmt, since it's very |
| 5055 | // likely that this will cause problems for future statements. |
| 5056 | if (isa<DeclStmt>(*B)) |
| 5057 | return StmtError(); |
| 5058 | |
| 5059 | // Otherwise, just keep processing substatements and fail later. |
| 5060 | SubStmtInvalid = true; |
| 5061 | continue; |
| 5062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5063 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5064 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 5065 | Statements.push_back(Result.takeAs<Stmt>()); |
| 5066 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5067 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5068 | if (SubStmtInvalid) |
| 5069 | return StmtError(); |
| 5070 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5071 | if (!getDerived().AlwaysRebuild() && |
| 5072 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5073 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5074 | |
| 5075 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5076 | Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5077 | S->getRBracLoc(), |
| 5078 | IsStmtExpr); |
| 5079 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5080 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5081 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5082 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5083 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5084 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5085 | { |
Eli Friedman | 6b3014b | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5086 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5087 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5088 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5089 | // Transform the left-hand case value. |
| 5090 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5091 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5092 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5093 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5094 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5095 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5096 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5097 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5098 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5099 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5100 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5101 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5102 | // Build the case statement. |
| 5103 | // Case statements are always rebuilt so that they will attached to their |
| 5104 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5105 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5106 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5107 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5108 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5109 | S->getColonLoc()); |
| 5110 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5111 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5112 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5113 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5114 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5115 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5116 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5117 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5118 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5119 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5123 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5124 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5125 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5126 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5127 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5128 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5129 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5130 | // Default statements are always rebuilt |
| 5131 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5132 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5133 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5135 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5136 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5137 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5138 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5139 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5140 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5141 | |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5142 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5143 | S->getDecl()); |
| 5144 | if (!LD) |
| 5145 | return StmtError(); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5146 | |
| 5147 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5148 | // FIXME: Pass the real colon location in. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5149 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5150 | cast<LabelDecl>(LD), SourceLocation(), |
| 5151 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5154 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5155 | StmtResult |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5156 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5157 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5158 | if (SubStmt.isInvalid()) |
| 5159 | return StmtError(); |
| 5160 | |
| 5161 | // TODO: transform attributes |
| 5162 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5163 | return S; |
| 5164 | |
| 5165 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5166 | S->getAttrs(), |
| 5167 | SubStmt.get()); |
| 5168 | } |
| 5169 | |
| 5170 | template<typename Derived> |
| 5171 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5173 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5174 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5175 | VarDecl *ConditionVar = 0; |
| 5176 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5177 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5178 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5179 | getDerived().TransformDefinition( |
| 5180 | S->getConditionVariable()->getLocation(), |
| 5181 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5182 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5183 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5184 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5185 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5187 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5188 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5189 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5190 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5191 | if (S->getCond()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5192 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5193 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5194 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5195 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5196 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5197 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5198 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5199 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5200 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5201 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5202 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5203 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5204 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5205 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5206 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5207 | if (Then.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5208 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5210 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5211 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5212 | if (Else.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5213 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5214 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5215 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5216 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5217 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5218 | Then.get() == S->getThen() && |
| 5219 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5220 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5221 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5222 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5223 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5224 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5228 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5229 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5230 | // Transform the condition. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5231 | ExprResult Cond; |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5232 | VarDecl *ConditionVar = 0; |
| 5233 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5234 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5235 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5236 | getDerived().TransformDefinition( |
| 5237 | S->getConditionVariable()->getLocation(), |
| 5238 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5239 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5240 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5241 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5242 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5243 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5244 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5245 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5246 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5247 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5248 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5249 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5250 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5251 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5252 | if (Switch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5253 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5254 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5255 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5256 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5257 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5258 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5259 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5260 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5261 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5262 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5266 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5267 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5268 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5269 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5270 | VarDecl *ConditionVar = 0; |
| 5271 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5272 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5273 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5274 | getDerived().TransformDefinition( |
| 5275 | S->getConditionVariable()->getLocation(), |
| 5276 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5277 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5278 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5279 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5280 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5281 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5282 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5283 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5284 | |
| 5285 | if (S->getCond()) { |
| 5286 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5287 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5288 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5289 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5290 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5291 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5292 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5293 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5294 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5295 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5296 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5297 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5298 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5299 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5300 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5301 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5302 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5303 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5304 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5305 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5306 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5307 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5308 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5309 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5310 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5311 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5312 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5315 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5316 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5317 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5318 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5319 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5320 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5321 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5322 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5323 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5324 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5325 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5326 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5327 | if (!getDerived().AlwaysRebuild() && |
| 5328 | Cond.get() == S->getCond() && |
| 5329 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5330 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5331 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5332 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5333 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5334 | S->getRParenLoc()); |
| 5335 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5336 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5337 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5338 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5339 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5340 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5341 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5342 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5343 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5344 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5345 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5346 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5347 | VarDecl *ConditionVar = 0; |
| 5348 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5349 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5350 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5351 | getDerived().TransformDefinition( |
| 5352 | S->getConditionVariable()->getLocation(), |
| 5353 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5354 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5355 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5356 | } else { |
| 5357 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5358 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5359 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5360 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5361 | |
| 5362 | if (S->getCond()) { |
| 5363 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5364 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5365 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5366 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5367 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5368 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5369 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5370 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5372 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5373 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5374 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5375 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5376 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5377 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5378 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5379 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5380 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5382 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 5383 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5384 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5385 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5386 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5387 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5388 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5389 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5391 | if (!getDerived().AlwaysRebuild() && |
| 5392 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5393 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5394 | Inc.get() == S->getInc() && |
| 5395 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5396 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5397 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5398 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5399 | Init.get(), FullCond, ConditionVar, |
| 5400 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5404 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5406 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5407 | S->getLabel()); |
| 5408 | if (!LD) |
| 5409 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5410 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5411 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5412 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5413 | cast<LabelDecl>(LD)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5417 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5418 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5419 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5420 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5421 | return StmtError(); |
Eli Friedman | d29975f | 2012-01-31 22:47:07 +0000 | [diff] [blame] | 5422 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5423 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5424 | if (!getDerived().AlwaysRebuild() && |
| 5425 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5426 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5427 | |
| 5428 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5429 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5433 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5434 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5435 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5436 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5437 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5438 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5439 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5440 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5441 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5442 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5443 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5444 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5445 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5446 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5447 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5448 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5449 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5450 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5451 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5452 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5453 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5454 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5457 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5458 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5459 | bool DeclChanged = false; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5460 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5461 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5462 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5463 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5464 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5465 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5466 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5467 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5468 | if (Transformed != *D) |
| 5469 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5470 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5471 | Decls.push_back(Transformed); |
| 5472 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5473 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5474 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5475 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | |
| 5477 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5478 | S->getStartLoc(), S->getEndLoc()); |
| 5479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5480 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5481 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5482 | StmtResult |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5483 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5484 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5485 | SmallVector<Expr*, 8> Constraints; |
| 5486 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5487 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5488 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5489 | ExprResult AsmString; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5490 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5491 | |
| 5492 | bool ExprsChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5493 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5494 | // Go through the outputs. |
| 5495 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5496 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5497 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5498 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5499 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5500 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5501 | // Transform the output expr. |
| 5502 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5503 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5504 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5505 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5506 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5507 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5508 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5509 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5510 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5511 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5512 | // Go through the inputs. |
| 5513 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5514 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5515 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5516 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5517 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5518 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5519 | // Transform the input expr. |
| 5520 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5521 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5522 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5523 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5524 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5525 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5526 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5527 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5528 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5529 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5530 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5531 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5532 | |
| 5533 | // Go through the clobbers. |
| 5534 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | 5c7f594 | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5535 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5536 | |
| 5537 | // No need to transform the asm string literal. |
| 5538 | AsmString = SemaRef.Owned(S->getAsmString()); |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5539 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5540 | S->isVolatile(), S->getNumOutputs(), |
| 5541 | S->getNumInputs(), Names.data(), |
| 5542 | Constraints, Exprs, AsmString.get(), |
| 5543 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5544 | } |
| 5545 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5546 | template<typename Derived> |
| 5547 | StmtResult |
| 5548 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5549 | ArrayRef<Token> AsmToks = |
| 5550 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 62f22b8 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5551 | |
Chad Rosier | 7bd092b | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 5552 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
| 5553 | AsmToks, S->getEndLoc()); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5554 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5555 | |
| 5556 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5557 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5558 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5559 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5560 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5561 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5562 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5563 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5564 | // Transform the @catch statements (if present). |
| 5565 | bool AnyCatchChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5566 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5567 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5568 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5569 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5570 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5571 | if (Catch.get() != S->getCatchStmt(I)) |
| 5572 | AnyCatchChanged = true; |
| 5573 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5574 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5575 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5576 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5577 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5578 | if (S->getFinallyStmt()) { |
| 5579 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5580 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5581 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | // If nothing changed, just retain this statement. |
| 5585 | if (!getDerived().AlwaysRebuild() && |
| 5586 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5587 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5588 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5589 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5590 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5591 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5592 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5593 | CatchStmts, Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5595 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5596 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5597 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5598 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5599 | // Transform the @catch parameter, if there is one. |
| 5600 | VarDecl *Var = 0; |
| 5601 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5602 | TypeSourceInfo *TSInfo = 0; |
| 5603 | if (FromVar->getTypeSourceInfo()) { |
| 5604 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5605 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5606 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5607 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5608 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5609 | QualType T; |
| 5610 | if (TSInfo) |
| 5611 | T = TSInfo->getType(); |
| 5612 | else { |
| 5613 | T = getDerived().TransformType(FromVar->getType()); |
| 5614 | if (T.isNull()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5615 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5616 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5617 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5618 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5619 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5620 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5621 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5622 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5623 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5624 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5625 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5626 | |
| 5627 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5628 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5629 | Var, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5630 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5631 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5632 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5633 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5635 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5636 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5637 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5638 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5639 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5640 | // If nothing changed, just retain this statement. |
| 5641 | if (!getDerived().AlwaysRebuild() && |
| 5642 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5643 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5644 | |
| 5645 | // Build a new statement. |
| 5646 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5647 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5648 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5649 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5650 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5651 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5652 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5653 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5654 | if (S->getThrowExpr()) { |
| 5655 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5656 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5657 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5658 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5659 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5660 | if (!getDerived().AlwaysRebuild() && |
| 5661 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5662 | return getSema().Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5663 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5664 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5665 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5666 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5667 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5668 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5669 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5671 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5672 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5673 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5674 | return StmtError(); |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5675 | Object = |
| 5676 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5677 | Object.get()); |
| 5678 | if (Object.isInvalid()) |
| 5679 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5680 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5681 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5682 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5683 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5684 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5685 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5686 | // If nothing change, just retain the current statement. |
| 5687 | if (!getDerived().AlwaysRebuild() && |
| 5688 | Object.get() == S->getSynchExpr() && |
| 5689 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5690 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5691 | |
| 5692 | // Build a new statement. |
| 5693 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5694 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5698 | StmtResult |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5699 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5700 | ObjCAutoreleasePoolStmt *S) { |
| 5701 | // Transform the body. |
| 5702 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5703 | if (Body.isInvalid()) |
| 5704 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5705 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5706 | // If nothing changed, just retain this statement. |
| 5707 | if (!getDerived().AlwaysRebuild() && |
| 5708 | Body.get() == S->getSubStmt()) |
| 5709 | return SemaRef.Owned(S); |
| 5710 | |
| 5711 | // Build a new statement. |
| 5712 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5713 | S->getAtLoc(), Body.get()); |
| 5714 | } |
| 5715 | |
| 5716 | template<typename Derived> |
| 5717 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5718 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5719 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5720 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5721 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5722 | if (Element.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 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5725 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5726 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5727 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5728 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5729 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5730 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5731 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5732 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5733 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5734 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5735 | // If nothing changed, just retain this statement. |
| 5736 | if (!getDerived().AlwaysRebuild() && |
| 5737 | Element.get() == S->getElement() && |
| 5738 | Collection.get() == S->getCollection() && |
| 5739 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5740 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5741 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5742 | // Build a new statement. |
| 5743 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5744 | Element.get(), |
| 5745 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5746 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5747 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | |
| 5751 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5752 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5753 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5754 | // Transform the exception declaration, if any. |
| 5755 | VarDecl *Var = 0; |
| 5756 | if (S->getExceptionDecl()) { |
| 5757 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5758 | TypeSourceInfo *T = getDerived().TransformType( |
| 5759 | ExceptionDecl->getTypeSourceInfo()); |
| 5760 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5761 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5762 | |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5763 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 5764 | ExceptionDecl->getInnerLocStart(), |
| 5765 | ExceptionDecl->getLocation(), |
| 5766 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5767 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5768 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5769 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5770 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5771 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5772 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5773 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5774 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5775 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5776 | if (!getDerived().AlwaysRebuild() && |
| 5777 | !Var && |
| 5778 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5779 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5780 | |
| 5781 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5782 | Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5783 | Handler.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5784 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5785 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5786 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5787 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5788 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5789 | // Transform the try block itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5790 | StmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5791 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5792 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5793 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5794 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5795 | // Transform the handlers. |
| 5796 | bool HandlerChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5797 | SmallVector<Stmt*, 8> Handlers; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5798 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5799 | StmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5800 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5801 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5802 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5803 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5804 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5805 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5807 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5808 | if (!getDerived().AlwaysRebuild() && |
| 5809 | TryBlock.get() == S->getTryBlock() && |
| 5810 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5811 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5812 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5813 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5814 | Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5815 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5816 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5817 | template<typename Derived> |
| 5818 | StmtResult |
| 5819 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5820 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 5821 | if (Range.isInvalid()) |
| 5822 | return StmtError(); |
| 5823 | |
| 5824 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 5825 | if (BeginEnd.isInvalid()) |
| 5826 | return StmtError(); |
| 5827 | |
| 5828 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 5829 | if (Cond.isInvalid()) |
| 5830 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 5831 | if (Cond.get()) |
| 5832 | Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); |
| 5833 | if (Cond.isInvalid()) |
| 5834 | return StmtError(); |
| 5835 | if (Cond.get()) |
| 5836 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5837 | |
| 5838 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 5839 | if (Inc.isInvalid()) |
| 5840 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 5841 | if (Inc.get()) |
| 5842 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5843 | |
| 5844 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 5845 | if (LoopVar.isInvalid()) |
| 5846 | return StmtError(); |
| 5847 | |
| 5848 | StmtResult NewStmt = S; |
| 5849 | if (getDerived().AlwaysRebuild() || |
| 5850 | Range.get() != S->getRangeStmt() || |
| 5851 | BeginEnd.get() != S->getBeginEndStmt() || |
| 5852 | Cond.get() != S->getCond() || |
| 5853 | Inc.get() != S->getInc() || |
| 5854 | LoopVar.get() != S->getLoopVarStmt()) |
| 5855 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5856 | S->getColonLoc(), Range.get(), |
| 5857 | BeginEnd.get(), Cond.get(), |
| 5858 | Inc.get(), LoopVar.get(), |
| 5859 | S->getRParenLoc()); |
| 5860 | |
| 5861 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 5862 | if (Body.isInvalid()) |
| 5863 | return StmtError(); |
| 5864 | |
| 5865 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 5866 | // it now so we have a new statement to attach the body to. |
| 5867 | if (Body.get() != S->getBody() && NewStmt.get() == S) |
| 5868 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5869 | S->getColonLoc(), Range.get(), |
| 5870 | BeginEnd.get(), Cond.get(), |
| 5871 | Inc.get(), LoopVar.get(), |
| 5872 | S->getRParenLoc()); |
| 5873 | |
| 5874 | if (NewStmt.get() == S) |
| 5875 | return SemaRef.Owned(S); |
| 5876 | |
| 5877 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 5878 | } |
| 5879 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 5880 | template<typename Derived> |
| 5881 | StmtResult |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5882 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 5883 | MSDependentExistsStmt *S) { |
| 5884 | // Transform the nested-name-specifier, if any. |
| 5885 | NestedNameSpecifierLoc QualifierLoc; |
| 5886 | if (S->getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5887 | QualifierLoc |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5888 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 5889 | if (!QualifierLoc) |
| 5890 | return StmtError(); |
| 5891 | } |
| 5892 | |
| 5893 | // Transform the declaration name. |
| 5894 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 5895 | if (NameInfo.getName()) { |
| 5896 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5897 | if (!NameInfo.getName()) |
| 5898 | return StmtError(); |
| 5899 | } |
| 5900 | |
| 5901 | // Check whether anything changed. |
| 5902 | if (!getDerived().AlwaysRebuild() && |
| 5903 | QualifierLoc == S->getQualifierLoc() && |
| 5904 | NameInfo.getName() == S->getNameInfo().getName()) |
| 5905 | return S; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5906 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5907 | // Determine whether this name exists, if we can. |
| 5908 | CXXScopeSpec SS; |
| 5909 | SS.Adopt(QualifierLoc); |
| 5910 | bool Dependent = false; |
| 5911 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { |
| 5912 | case Sema::IER_Exists: |
| 5913 | if (S->isIfExists()) |
| 5914 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5915 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5916 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 5917 | |
| 5918 | case Sema::IER_DoesNotExist: |
| 5919 | if (S->isIfNotExists()) |
| 5920 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5921 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5922 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5923 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5924 | case Sema::IER_Dependent: |
| 5925 | Dependent = true; |
| 5926 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5927 | |
Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 5928 | case Sema::IER_Error: |
| 5929 | return StmtError(); |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5930 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5931 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5932 | // We need to continue with the instantiation, so do so now. |
| 5933 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 5934 | if (SubStmt.isInvalid()) |
| 5935 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5936 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5937 | // If we have resolved the name, just transform to the substatement. |
| 5938 | if (!Dependent) |
| 5939 | return SubStmt; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5940 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 5941 | // The name is still dependent, so build a dependent expression again. |
| 5942 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 5943 | S->isIfExists(), |
| 5944 | QualifierLoc, |
| 5945 | NameInfo, |
| 5946 | SubStmt.get()); |
| 5947 | } |
| 5948 | |
| 5949 | template<typename Derived> |
| 5950 | StmtResult |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 5951 | TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 5952 | StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5953 | if(TryBlock.isInvalid()) return StmtError(); |
| 5954 | |
| 5955 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 5956 | if(!getDerived().AlwaysRebuild() && |
| 5957 | TryBlock.get() == S->getTryBlock() && |
| 5958 | Handler.get() == S->getHandler()) |
| 5959 | return SemaRef.Owned(S); |
| 5960 | |
| 5961 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), |
| 5962 | S->getTryLoc(), |
| 5963 | TryBlock.take(), |
| 5964 | Handler.take()); |
| 5965 | } |
| 5966 | |
| 5967 | template<typename Derived> |
| 5968 | StmtResult |
| 5969 | TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 5970 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 5971 | if(Block.isInvalid()) return StmtError(); |
| 5972 | |
| 5973 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), |
| 5974 | Block.take()); |
| 5975 | } |
| 5976 | |
| 5977 | template<typename Derived> |
| 5978 | StmtResult |
| 5979 | TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 5980 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 5981 | if(FilterExpr.isInvalid()) return StmtError(); |
| 5982 | |
| 5983 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 5984 | if(Block.isInvalid()) return StmtError(); |
| 5985 | |
| 5986 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), |
| 5987 | FilterExpr.take(), |
| 5988 | Block.take()); |
| 5989 | } |
| 5990 | |
| 5991 | template<typename Derived> |
| 5992 | StmtResult |
| 5993 | TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 5994 | if(isa<SEHFinallyStmt>(Handler)) |
| 5995 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 5996 | else |
| 5997 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 5998 | } |
| 5999 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6000 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6001 | // Expression transformation |
| 6002 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6003 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6004 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6005 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6006 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6007 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6008 | |
| 6009 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6010 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6011 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6012 | NestedNameSpecifierLoc QualifierLoc; |
| 6013 | if (E->getQualifierLoc()) { |
| 6014 | QualifierLoc |
| 6015 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6016 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6017 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6018 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6019 | |
| 6020 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6021 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6022 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6023 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6024 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6025 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6026 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6027 | if (NameInfo.getName()) { |
| 6028 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6029 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6030 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6031 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6032 | |
| 6033 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6034 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6035 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6036 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6037 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6038 | |
| 6039 | // Mark it referenced in the new context regardless. |
| 6040 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6041 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6042 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6043 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6044 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6045 | |
| 6046 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6047 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6048 | TemplateArgs = &TransArgs; |
| 6049 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6050 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6051 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6052 | E->getNumTemplateArgs(), |
| 6053 | TransArgs)) |
| 6054 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6055 | } |
| 6056 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6057 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6058 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6059 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6060 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6061 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6062 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6063 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6064 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6065 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6066 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6067 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6068 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6069 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6070 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6072 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6073 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6074 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6075 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6076 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6078 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6079 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6080 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6081 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6082 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6083 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6084 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6085 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6086 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6087 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6088 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6092 | ExprResult |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6093 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
| 6094 | return SemaRef.MaybeBindToTemporary(E); |
| 6095 | } |
| 6096 | |
| 6097 | template<typename Derived> |
| 6098 | ExprResult |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6099 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6100 | ExprResult ControllingExpr = |
| 6101 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6102 | if (ControllingExpr.isInvalid()) |
| 6103 | return ExprError(); |
| 6104 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6105 | SmallVector<Expr *, 4> AssocExprs; |
| 6106 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6107 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6108 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6109 | if (TS) { |
| 6110 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6111 | if (!AssocType) |
| 6112 | return ExprError(); |
| 6113 | AssocTypes.push_back(AssocType); |
| 6114 | } else { |
| 6115 | AssocTypes.push_back(0); |
| 6116 | } |
| 6117 | |
| 6118 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6119 | if (AssocExpr.isInvalid()) |
| 6120 | return ExprError(); |
| 6121 | AssocExprs.push_back(AssocExpr.release()); |
| 6122 | } |
| 6123 | |
| 6124 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6125 | E->getDefaultLoc(), |
| 6126 | E->getRParenLoc(), |
| 6127 | ControllingExpr.release(), |
| 6128 | AssocTypes.data(), |
| 6129 | AssocExprs.data(), |
| 6130 | E->getNumAssocs()); |
| 6131 | } |
| 6132 | |
| 6133 | template<typename Derived> |
| 6134 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6135 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6136 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6137 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6138 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6139 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6140 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6141 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6142 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6143 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6144 | E->getRParen()); |
| 6145 | } |
| 6146 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6147 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 6148 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 6149 | /// object available. |
| 6150 | template<typename Derived> |
| 6151 | ExprResult |
| 6152 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 6153 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| 6154 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true); |
| 6155 | else |
| 6156 | return getDerived().TransformExpr(E); |
| 6157 | } |
| 6158 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6159 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6160 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6161 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6162 | ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6163 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6164 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6165 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6166 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6167 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6168 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6169 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 6170 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6171 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6173 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6174 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6175 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6176 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 6177 | // Transform the type. |
| 6178 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6179 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6180 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6181 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6182 | // Transform all of the components into components similar to what the |
| 6183 | // parser uses. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6184 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 6185 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 6186 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6187 | // template code that we don't care. |
| 6188 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6189 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6190 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6191 | SmallVector<Component, 4> Components; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6192 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 6193 | const Node &ON = E->getComponent(I); |
| 6194 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 6195 | Comp.isBrackets = true; |
Abramo Bagnara | 06dec89 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 6196 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 6197 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6198 | switch (ON.getKind()) { |
| 6199 | case Node::Array: { |
| 6200 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6201 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6202 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6203 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6204 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6205 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 6206 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6207 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6208 | break; |
| 6209 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6210 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6211 | case Node::Field: |
| 6212 | case Node::Identifier: |
| 6213 | Comp.isBrackets = false; |
| 6214 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 6215 | if (!Comp.U.IdentInfo) |
| 6216 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6217 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6218 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6219 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 6220 | case Node::Base: |
| 6221 | // Will be recomputed during the rebuild. |
| 6222 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6223 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6224 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6225 | Components.push_back(Comp); |
| 6226 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6227 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6228 | // If nothing changed, retain the existing expression. |
| 6229 | if (!getDerived().AlwaysRebuild() && |
| 6230 | Type == E->getTypeSourceInfo() && |
| 6231 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6232 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6233 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6234 | // Build a new offsetof expression. |
| 6235 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 6236 | Components.data(), Components.size(), |
| 6237 | E->getRParenLoc()); |
| 6238 | } |
| 6239 | |
| 6240 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6241 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 6242 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6243 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 6244 | "opaque value expression requires transformation"); |
| 6245 | return SemaRef.Owned(E); |
| 6246 | } |
| 6247 | |
| 6248 | template<typename Derived> |
| 6249 | ExprResult |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6250 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | 01e19be | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 6251 | // Rebuild the syntactic form. The original syntactic form has |
| 6252 | // opaque-value expressions in it, so strip those away and rebuild |
| 6253 | // the result. This is a really awful way of doing this, but the |
| 6254 | // better solution (rebuilding the semantic expressions and |
| 6255 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 6256 | // TreeTransform to not strip away implicit conversions. |
| 6257 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 6258 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6259 | if (result.isInvalid()) return ExprError(); |
| 6260 | |
| 6261 | // If that gives us a pseudo-object result back, the pseudo-object |
| 6262 | // expression must have been an lvalue-to-rvalue conversion which we |
| 6263 | // should reapply. |
| 6264 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 6265 | result = SemaRef.checkPseudoObjectRValue(result.take()); |
| 6266 | |
| 6267 | return result; |
| 6268 | } |
| 6269 | |
| 6270 | template<typename Derived> |
| 6271 | ExprResult |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6272 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 6273 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6274 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6275 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6276 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6277 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6278 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6279 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6280 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6281 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6282 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6283 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6284 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 6285 | E->getKind(), |
| 6286 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6287 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6288 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6289 | // C++0x [expr.sizeof]p1: |
| 6290 | // The operand is either an expression, which is an unevaluated operand |
| 6291 | // [...] |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 6292 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 6293 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6294 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6295 | ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 6296 | if (SubExpr.isInvalid()) |
| 6297 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6298 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6299 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 6300 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6301 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6302 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6303 | E->getOperatorLoc(), |
| 6304 | E->getKind(), |
| 6305 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6307 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6308 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6309 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6310 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6311 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6312 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6313 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6314 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6315 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6316 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6317 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6318 | |
| 6319 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6320 | if (!getDerived().AlwaysRebuild() && |
| 6321 | LHS.get() == E->getLHS() && |
| 6322 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6323 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6324 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6325 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6326 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6327 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6328 | E->getRBracketLoc()); |
| 6329 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6330 | |
| 6331 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6332 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6333 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6334 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6335 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6336 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6337 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6338 | |
| 6339 | // Transform arguments. |
| 6340 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6341 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6342 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6343 | &ArgChanged)) |
| 6344 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6345 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6346 | if (!getDerived().AlwaysRebuild() && |
| 6347 | Callee.get() == E->getCallee() && |
| 6348 | !ArgChanged) |
Dmitri Gribenko | 1ad23d6 | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 6349 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6350 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6351 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6352 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6353 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6354 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6355 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6356 | E->getRParenLoc()); |
| 6357 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6358 | |
| 6359 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6360 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6361 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6362 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6363 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6364 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6365 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6366 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6367 | if (E->hasQualifier()) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6368 | QualifierLoc |
| 6369 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6370 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6371 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6372 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6373 | } |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6374 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6375 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6376 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6377 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6378 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6379 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6380 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6381 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6382 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6383 | if (FoundDecl == E->getMemberDecl()) { |
| 6384 | FoundDecl = Member; |
| 6385 | } else { |
| 6386 | FoundDecl = cast_or_null<NamedDecl>( |
| 6387 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6388 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6389 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6390 | } |
| 6391 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6392 | if (!getDerived().AlwaysRebuild() && |
| 6393 | Base.get() == E->getBase() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6394 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6395 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6396 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6397 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6398 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6399 | // Mark it referenced in the new context regardless. |
| 6400 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6401 | SemaRef.MarkMemberReferenced(E); |
| 6402 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6403 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6404 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6405 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6406 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6407 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6408 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6409 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6410 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6411 | E->getNumTemplateArgs(), |
| 6412 | TransArgs)) |
| 6413 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6414 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6415 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6416 | // FIXME: Bogus source location for the operator |
| 6417 | SourceLocation FakeOperatorLoc |
| 6418 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6419 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6420 | // FIXME: to do this check properly, we will need to preserve the |
| 6421 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6422 | // base (and therefore couldn't do the check) and a |
| 6423 | // nested-name-qualifier (and therefore could do the lookup). |
| 6424 | NamedDecl *FirstQualifierInScope = 0; |
| 6425 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6426 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6427 | E->isArrow(), |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6428 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6429 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6430 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6431 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6432 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6433 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6434 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6435 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6436 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6437 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6438 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6439 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6440 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6441 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6442 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6443 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6444 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6445 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6446 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6447 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6448 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6449 | if (!getDerived().AlwaysRebuild() && |
| 6450 | LHS.get() == E->getLHS() && |
| 6451 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6452 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6453 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 6454 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 6455 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 6456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6457 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6458 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6459 | } |
| 6460 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6461 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6462 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6463 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6464 | CompoundAssignOperator *E) { |
| 6465 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6466 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6467 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6468 | template<typename Derived> |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6469 | ExprResult TreeTransform<Derived>:: |
| 6470 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6471 | // Just rebuild the common and RHS expressions and see whether we |
| 6472 | // get any changes. |
| 6473 | |
| 6474 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6475 | if (commonExpr.isInvalid()) |
| 6476 | return ExprError(); |
| 6477 | |
| 6478 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6479 | if (rhs.isInvalid()) |
| 6480 | return ExprError(); |
| 6481 | |
| 6482 | if (!getDerived().AlwaysRebuild() && |
| 6483 | commonExpr.get() == e->getCommon() && |
| 6484 | rhs.get() == e->getFalseExpr()) |
| 6485 | return SemaRef.Owned(e); |
| 6486 | |
| 6487 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6488 | e->getQuestionLoc(), |
| 6489 | 0, |
| 6490 | e->getColonLoc(), |
| 6491 | rhs.get()); |
| 6492 | } |
| 6493 | |
| 6494 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6495 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6496 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6497 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6498 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6499 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6500 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6501 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6502 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6503 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6504 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6505 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6506 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6507 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6509 | if (!getDerived().AlwaysRebuild() && |
| 6510 | Cond.get() == E->getCond() && |
| 6511 | LHS.get() == E->getLHS() && |
| 6512 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6513 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6515 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6516 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6517 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6518 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6519 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6520 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6521 | |
| 6522 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6523 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6524 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6525 | // Implicit casts are eliminated during transformation, since they |
| 6526 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6527 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6528 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6529 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6530 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6531 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6532 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6533 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6534 | if (!Type) |
| 6535 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6536 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6537 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6538 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6539 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6540 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6541 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6542 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6543 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6544 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6545 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6546 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6547 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6548 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6549 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6550 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6551 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6552 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6553 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6554 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6555 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6556 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6557 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6558 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6559 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6560 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6561 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6562 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6563 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6565 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6566 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6567 | Init.get() == E->getInitializer()) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6568 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6569 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6570 | // Note: the expression type doesn't necessarily match the |
| 6571 | // type-as-written, but that's okay, because it should always be |
| 6572 | // derivable from the initializer. |
| 6573 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6574 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6575 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6576 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6577 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6578 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6579 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6580 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6581 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6582 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6583 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6584 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6585 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6586 | if (!getDerived().AlwaysRebuild() && |
| 6587 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6588 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6589 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6590 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6591 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6592 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6593 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6594 | E->getAccessorLoc(), |
| 6595 | E->getAccessor()); |
| 6596 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6597 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6598 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6599 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6600 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6601 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6602 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6603 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6604 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6605 | Inits, &InitChanged)) |
| 6606 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6607 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6608 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6609 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6610 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6611 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6612 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6613 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6614 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6615 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6616 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6617 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6618 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6619 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6620 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6621 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6622 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6623 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6624 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6625 | // transform the designators. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6626 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6627 | bool ExprChanged = false; |
| 6628 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6629 | DEnd = E->designators_end(); |
| 6630 | D != DEnd; ++D) { |
| 6631 | if (D->isFieldDesignator()) { |
| 6632 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6633 | D->getDotLoc(), |
| 6634 | D->getFieldLoc())); |
| 6635 | continue; |
| 6636 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6637 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6638 | if (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6639 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6640 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6641 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6642 | |
| 6643 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6644 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6645 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6646 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6647 | ArrayExprs.push_back(Index.release()); |
| 6648 | continue; |
| 6649 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6651 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6652 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6653 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6654 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6655 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6656 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6657 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6658 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6659 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6660 | |
| 6661 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6662 | End.get(), |
| 6663 | D->getLBracketLoc(), |
| 6664 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6665 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6666 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6667 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6668 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6669 | ArrayExprs.push_back(Start.release()); |
| 6670 | ArrayExprs.push_back(End.release()); |
| 6671 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6672 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6673 | if (!getDerived().AlwaysRebuild() && |
| 6674 | Init.get() == E->getInit() && |
| 6675 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6676 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6677 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6678 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6679 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6680 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6681 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6682 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6683 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6684 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6685 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6686 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6687 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6688 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6689 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6690 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6691 | QualType T = getDerived().TransformType(E->getType()); |
| 6692 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6693 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6694 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6695 | if (!getDerived().AlwaysRebuild() && |
| 6696 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6697 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6698 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6699 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6700 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6701 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6702 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6703 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6704 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6705 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6706 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6707 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6708 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6709 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6710 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6711 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6712 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6713 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6714 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6715 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6716 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6717 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6718 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6719 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6720 | } |
| 6721 | |
| 6722 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6723 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6724 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6725 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6726 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6727 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6728 | &ArgumentChanged)) |
| 6729 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6730 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6731 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6732 | Inits, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6733 | E->getRParenLoc()); |
| 6734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6735 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6736 | /// \brief Transform an address-of-label expression. |
| 6737 | /// |
| 6738 | /// By default, the transformation of an address-of-label expression always |
| 6739 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6740 | /// the corresponding label statement by semantic analysis. |
| 6741 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6742 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6743 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6744 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6745 | E->getLabel()); |
| 6746 | if (!LD) |
| 6747 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6749 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6750 | cast<LabelDecl>(LD)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6751 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6752 | |
| 6753 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6754 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6755 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6756 | SemaRef.ActOnStartStmtExpr(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6757 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6758 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6759 | if (SubStmt.isInvalid()) { |
| 6760 | SemaRef.ActOnStmtExprError(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6761 | return ExprError(); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6762 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6763 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6764 | if (!getDerived().AlwaysRebuild() && |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6765 | SubStmt.get() == E->getSubStmt()) { |
| 6766 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 6767 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6768 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 6769 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6770 | |
| 6771 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6772 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6773 | E->getRParenLoc()); |
| 6774 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6775 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6776 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6777 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6778 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6779 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6780 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6781 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6782 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6783 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6784 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6785 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6786 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6787 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6788 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6789 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6790 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6791 | if (!getDerived().AlwaysRebuild() && |
| 6792 | Cond.get() == E->getCond() && |
| 6793 | LHS.get() == E->getLHS() && |
| 6794 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6795 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6796 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6797 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6798 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6799 | E->getRParenLoc()); |
| 6800 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6801 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6802 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6803 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6804 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6805 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6806 | } |
| 6807 | |
| 6808 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6809 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6810 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6811 | switch (E->getOperator()) { |
| 6812 | case OO_New: |
| 6813 | case OO_Delete: |
| 6814 | case OO_Array_New: |
| 6815 | case OO_Array_Delete: |
| 6816 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6817 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6818 | case OO_Call: { |
| 6819 | // This is a call to an object's operator(). |
| 6820 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6821 | |
| 6822 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6823 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6824 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6825 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6826 | |
| 6827 | // FIXME: Poor location information |
| 6828 | SourceLocation FakeLParenLoc |
| 6829 | = SemaRef.PP.getLocForEndOfToken( |
| 6830 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6831 | |
| 6832 | // Transform the call arguments. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6833 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6834 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6835 | Args)) |
| 6836 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6837 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6838 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6839 | Args, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6840 | E->getLocEnd()); |
| 6841 | } |
| 6842 | |
| 6843 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6844 | case OO_##Name: |
| 6845 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6846 | #include "clang/Basic/OperatorKinds.def" |
| 6847 | case OO_Subscript: |
| 6848 | // Handled below. |
| 6849 | break; |
| 6850 | |
| 6851 | case OO_Conditional: |
| 6852 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6853 | |
| 6854 | case OO_None: |
| 6855 | case NUM_OVERLOADED_OPERATORS: |
| 6856 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6857 | } |
| 6858 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6859 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6860 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6861 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6862 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6863 | ExprResult First; |
| 6864 | if (E->getOperator() == OO_Amp) |
| 6865 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 6866 | else |
| 6867 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6868 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6869 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6870 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6871 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6872 | if (E->getNumArgs() == 2) { |
| 6873 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6874 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6875 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6876 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6877 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6878 | if (!getDerived().AlwaysRebuild() && |
| 6879 | Callee.get() == E->getCallee() && |
| 6880 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6881 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6882 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6883 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 6884 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 6885 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 6886 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6887 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 6888 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6889 | Callee.get(), |
| 6890 | First.get(), |
| 6891 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6892 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6893 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6894 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6895 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6896 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6897 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6898 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6899 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6900 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6901 | ExprResult |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6902 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 6903 | // Transform the callee. |
| 6904 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 6905 | if (Callee.isInvalid()) |
| 6906 | return ExprError(); |
| 6907 | |
| 6908 | // Transform exec config. |
| 6909 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 6910 | if (EC.isInvalid()) |
| 6911 | return ExprError(); |
| 6912 | |
| 6913 | // Transform arguments. |
| 6914 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6915 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6916 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6917 | &ArgChanged)) |
| 6918 | return ExprError(); |
| 6919 | |
| 6920 | if (!getDerived().AlwaysRebuild() && |
| 6921 | Callee.get() == E->getCallee() && |
| 6922 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6923 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6924 | |
| 6925 | // FIXME: Wrong source location information for the '('. |
| 6926 | SourceLocation FakeLParenLoc |
| 6927 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 6928 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6929 | Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6930 | E->getRParenLoc(), EC.get()); |
| 6931 | } |
| 6932 | |
| 6933 | template<typename Derived> |
| 6934 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6935 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6936 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6937 | if (!Type) |
| 6938 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6939 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6940 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6941 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6942 | if (SubExpr.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 | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6945 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6946 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6947 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6948 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6949 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6950 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6951 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6952 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 6953 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6954 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6955 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6956 | FakeLAngleLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6957 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6958 | FakeRAngleLoc, |
| 6959 | FakeRAngleLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6960 | SubExpr.get(), |
Abramo Bagnara | 6cf7d7d | 2012-10-15 21:08:58 +0000 | [diff] [blame] | 6961 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6962 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6963 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6964 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6965 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6966 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 6967 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6968 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6969 | |
| 6970 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6971 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6972 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 6973 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6974 | } |
| 6975 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6976 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6977 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6978 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6979 | CXXReinterpretCastExpr *E) { |
| 6980 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6981 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6982 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6983 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6984 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6985 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 6986 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6987 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6990 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6991 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6992 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6993 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6994 | if (!Type) |
| 6995 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6996 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6997 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6998 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6999 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7000 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7001 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7002 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7003 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7004 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7005 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7006 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7007 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7008 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7009 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7010 | E->getRParenLoc()); |
| 7011 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7012 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7013 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7014 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7015 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7016 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7017 | TypeSourceInfo *TInfo |
| 7018 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7019 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7020 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7023 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7024 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7025 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7026 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7027 | E->getLocStart(), |
| 7028 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7029 | E->getLocEnd()); |
| 7030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7031 | |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7032 | // We don't know whether the subexpression is potentially evaluated until |
| 7033 | // after we perform semantic analysis. We speculatively assume it is |
| 7034 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7035 | // potentially evaluated. |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7036 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7037 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7038 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7039 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7040 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7041 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7042 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7043 | if (!getDerived().AlwaysRebuild() && |
| 7044 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7045 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7046 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7047 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7048 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7049 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7050 | E->getLocEnd()); |
| 7051 | } |
| 7052 | |
| 7053 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7054 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7055 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7056 | if (E->isTypeOperand()) { |
| 7057 | TypeSourceInfo *TInfo |
| 7058 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7059 | if (!TInfo) |
| 7060 | return ExprError(); |
| 7061 | |
| 7062 | if (!getDerived().AlwaysRebuild() && |
| 7063 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7064 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7065 | |
Douglas Gregor | 3c52a21 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7066 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7067 | E->getLocStart(), |
| 7068 | TInfo, |
| 7069 | E->getLocEnd()); |
| 7070 | } |
| 7071 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7072 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7073 | |
| 7074 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7075 | if (SubExpr.isInvalid()) |
| 7076 | return ExprError(); |
| 7077 | |
| 7078 | if (!getDerived().AlwaysRebuild() && |
| 7079 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7080 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7081 | |
| 7082 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7083 | E->getLocStart(), |
| 7084 | SubExpr.get(), |
| 7085 | E->getLocEnd()); |
| 7086 | } |
| 7087 | |
| 7088 | template<typename Derived> |
| 7089 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7090 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7091 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7092 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7094 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7095 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7096 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7097 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7098 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7099 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7100 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7101 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7102 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7103 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7104 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 7105 | QualType T; |
| 7106 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) |
| 7107 | T = MD->getThisType(getSema().Context); |
| 7108 | else |
| 7109 | T = getSema().Context.getPointerType( |
| 7110 | getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7111 | |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7112 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7113 | // Make sure that we capture 'this'. |
| 7114 | getSema().CheckCXXThisCapture(E->getLocStart()); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7115 | return SemaRef.Owned(E); |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7116 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7117 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7118 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7119 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7121 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7122 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7123 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7124 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7125 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7126 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7128 | if (!getDerived().AlwaysRebuild() && |
| 7129 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7130 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7131 | |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7132 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7133 | E->isThrownVariableInScope()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7135 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7136 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7137 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7138 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7139 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7140 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7141 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7142 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7143 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7144 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7145 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7146 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7147 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7148 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7149 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7150 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7151 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7152 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7153 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7154 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 7155 | CXXScalarValueInitExpr *E) { |
| 7156 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7157 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7158 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7159 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7160 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7161 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7162 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7163 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7164 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7165 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 7166 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7167 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7168 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7169 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7170 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7171 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7172 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7173 | TypeSourceInfo *AllocTypeInfo |
| 7174 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 7175 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7176 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7177 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7178 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7179 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7180 | if (ArraySize.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 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7183 | // Transform the placement arguments (if any). |
| 7184 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7185 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7186 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7187 | E->getNumPlacementArgs(), true, |
| 7188 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7189 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7190 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7191 | // Transform the initializer (if any). |
| 7192 | Expr *OldInit = E->getInitializer(); |
| 7193 | ExprResult NewInit; |
| 7194 | if (OldInit) |
| 7195 | NewInit = getDerived().TransformExpr(OldInit); |
| 7196 | if (NewInit.isInvalid()) |
| 7197 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7198 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7199 | // Transform new operator and delete operator. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7200 | FunctionDecl *OperatorNew = 0; |
| 7201 | if (E->getOperatorNew()) { |
| 7202 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7203 | getDerived().TransformDecl(E->getLocStart(), |
| 7204 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7205 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7206 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7207 | } |
| 7208 | |
| 7209 | FunctionDecl *OperatorDelete = 0; |
| 7210 | if (E->getOperatorDelete()) { |
| 7211 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7212 | getDerived().TransformDecl(E->getLocStart(), |
| 7213 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7214 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7215 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7216 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7218 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7219 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7220 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7221 | NewInit.get() == OldInit && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7222 | OperatorNew == E->getOperatorNew() && |
| 7223 | OperatorDelete == E->getOperatorDelete() && |
| 7224 | !ArgumentChanged) { |
| 7225 | // Mark any declarations we need as referenced. |
| 7226 | // FIXME: instantiation-specific. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7227 | if (OperatorNew) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7228 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7229 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7230 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7231 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7232 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7233 | QualType ElementType |
| 7234 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 7235 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 7236 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 7237 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7238 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7239 | } |
| 7240 | } |
| 7241 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7242 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7243 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7244 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7245 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7246 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7247 | if (!ArraySize.get()) { |
| 7248 | // If no array size was specified, but the new expression was |
| 7249 | // instantiated with an array type (e.g., "new T" where T is |
| 7250 | // instantiated with "int[4]"), extract the outer bound from the |
| 7251 | // array type as our array size. We do this with constant and |
| 7252 | // dependently-sized array types. |
| 7253 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 7254 | if (!ArrayT) { |
| 7255 | // Do nothing |
| 7256 | } else if (const ConstantArrayType *ConsArrayT |
| 7257 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7258 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7259 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7260 | ConsArrayT->getSize(), |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7261 | SemaRef.Context.getSizeType(), |
| 7262 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7263 | AllocType = ConsArrayT->getElementType(); |
| 7264 | } else if (const DependentSizedArrayType *DepArrayT |
| 7265 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 7266 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7267 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7268 | AllocType = DepArrayT->getElementType(); |
| 7269 | } |
| 7270 | } |
| 7271 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7272 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7273 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 7274 | E->isGlobalNew(), |
| 7275 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7276 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7277 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 7278 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7279 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7280 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7281 | ArraySize.get(), |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7282 | E->getDirectInitRange(), |
| 7283 | NewInit.take()); |
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 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7289 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7290 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7291 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7292 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7293 | // Transform the delete operator, if known. |
| 7294 | FunctionDecl *OperatorDelete = 0; |
| 7295 | if (E->getOperatorDelete()) { |
| 7296 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7297 | getDerived().TransformDecl(E->getLocStart(), |
| 7298 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7299 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7300 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7301 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7302 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7303 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7304 | Operand.get() == E->getArgument() && |
| 7305 | OperatorDelete == E->getOperatorDelete()) { |
| 7306 | // Mark any declarations we need as referenced. |
| 7307 | // FIXME: instantiation-specific. |
| 7308 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7309 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7310 | |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7311 | if (!E->getArgument()->isTypeDependent()) { |
| 7312 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7313 | E->getDestroyedType()); |
| 7314 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7315 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7316 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7317 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7318 | } |
| 7319 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7320 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7321 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7323 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7324 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7325 | E->isGlobalDelete(), |
| 7326 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7327 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7328 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7329 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7330 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7331 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7332 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7333 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7334 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7335 | if (Base.isInvalid()) |
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 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7338 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7339 | bool MayBePseudoDestructor = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7340 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7341 | E->getOperatorLoc(), |
| 7342 | E->isArrow()? tok::arrow : tok::period, |
| 7343 | ObjectTypePtr, |
| 7344 | MayBePseudoDestructor); |
| 7345 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7346 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7347 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7348 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7349 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7350 | if (QualifierLoc) { |
| 7351 | QualifierLoc |
| 7352 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7353 | if (!QualifierLoc) |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7354 | return ExprError(); |
| 7355 | } |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7356 | CXXScopeSpec SS; |
| 7357 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7358 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7359 | PseudoDestructorTypeStorage Destroyed; |
| 7360 | if (E->getDestroyedTypeInfo()) { |
| 7361 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7362 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7363 | ObjectType, 0, SS); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7364 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7365 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7366 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 7367 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7368 | // We aren't likely to be able to resolve the identifier down to a type |
| 7369 | // now anyway, so just retain the identifier. |
| 7370 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7371 | E->getDestroyedTypeLoc()); |
| 7372 | } else { |
| 7373 | // Look for a destructor known with the given name. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7374 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7375 | *E->getDestroyedTypeIdentifier(), |
| 7376 | E->getDestroyedTypeLoc(), |
| 7377 | /*Scope=*/0, |
| 7378 | SS, ObjectTypePtr, |
| 7379 | false); |
| 7380 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7381 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7382 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7383 | Destroyed |
| 7384 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7385 | E->getDestroyedTypeLoc()); |
| 7386 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7387 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7388 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7389 | if (E->getScopeTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7390 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7391 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7392 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7393 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7394 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7395 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7396 | E->getOperatorLoc(), |
| 7397 | E->isArrow(), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7398 | SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7399 | ScopeTypeInfo, |
| 7400 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7401 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7402 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7403 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7404 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7405 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7406 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7407 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7408 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7409 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7410 | Sema::LookupOrdinaryName); |
| 7411 | |
| 7412 | // Transform all the decls. |
| 7413 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7414 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7415 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7416 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7417 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7418 | if (!InstD) { |
| 7419 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7420 | // This can happen because of dependent hiding. |
| 7421 | if (isa<UsingShadowDecl>(*I)) |
| 7422 | continue; |
| 7423 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7424 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7425 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7426 | |
| 7427 | // Expand using declarations. |
| 7428 | if (isa<UsingDecl>(InstD)) { |
| 7429 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7430 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7431 | E = UD->shadow_end(); I != E; ++I) |
| 7432 | R.addDecl(*I); |
| 7433 | continue; |
| 7434 | } |
| 7435 | |
| 7436 | R.addDecl(InstD); |
| 7437 | } |
| 7438 | |
| 7439 | // Resolve a kind, but don't do any further analysis. If it's |
| 7440 | // ambiguous, the callee needs to deal with it. |
| 7441 | R.resolveKind(); |
| 7442 | |
| 7443 | // Rebuild the nested-name qualifier, if present. |
| 7444 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7445 | if (Old->getQualifierLoc()) { |
| 7446 | NestedNameSpecifierLoc QualifierLoc |
| 7447 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7448 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7449 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7450 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7451 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7452 | } |
| 7453 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7454 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7455 | CXXRecordDecl *NamingClass |
| 7456 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7457 | Old->getNameLoc(), |
| 7458 | Old->getNamingClass())); |
| 7459 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7460 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7461 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7462 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7463 | } |
| 7464 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7465 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7466 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7467 | // If we have neither explicit template arguments, nor the template keyword, |
| 7468 | // it's a normal declaration name. |
| 7469 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7470 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7471 | |
| 7472 | // If we have template arguments, rebuild them, then rebuild the |
| 7473 | // templateid expression. |
| 7474 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 02e221b | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 7475 | if (Old->hasExplicitTemplateArgs() && |
| 7476 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7477 | Old->getNumTemplateArgs(), |
| 7478 | TransArgs)) |
| 7479 | return ExprError(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7480 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7481 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7482 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7484 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7485 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7486 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7487 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7488 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7489 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7490 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7491 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7492 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7493 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7494 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7495 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7496 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7497 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7498 | T, |
| 7499 | E->getLocEnd()); |
| 7500 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7501 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7502 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7503 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7504 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7505 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7506 | if (!LhsT) |
| 7507 | return ExprError(); |
| 7508 | |
| 7509 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7510 | if (!RhsT) |
| 7511 | return ExprError(); |
| 7512 | |
| 7513 | if (!getDerived().AlwaysRebuild() && |
| 7514 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7515 | return SemaRef.Owned(E); |
| 7516 | |
| 7517 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7518 | E->getLocStart(), |
| 7519 | LhsT, RhsT, |
| 7520 | E->getLocEnd()); |
| 7521 | } |
| 7522 | |
| 7523 | template<typename Derived> |
| 7524 | ExprResult |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7525 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 7526 | bool ArgChanged = false; |
| 7527 | llvm::SmallVector<TypeSourceInfo *, 4> Args; |
| 7528 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 7529 | TypeSourceInfo *From = E->getArg(I); |
| 7530 | TypeLoc FromTL = From->getTypeLoc(); |
| 7531 | if (!isa<PackExpansionTypeLoc>(FromTL)) { |
| 7532 | TypeLocBuilder TLB; |
| 7533 | TLB.reserve(FromTL.getFullDataSize()); |
| 7534 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 7535 | if (To.isNull()) |
| 7536 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7537 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7538 | if (To == From->getType()) |
| 7539 | Args.push_back(From); |
| 7540 | else { |
| 7541 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7542 | ArgChanged = true; |
| 7543 | } |
| 7544 | continue; |
| 7545 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7546 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7547 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7548 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7549 | // We have a pack expansion. Instantiate it. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7550 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL); |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7551 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 7552 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7553 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7554 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7555 | // Determine whether the set of unexpanded parameter packs can and should |
| 7556 | // be expanded. |
| 7557 | bool Expand = true; |
| 7558 | bool RetainExpansion = false; |
| 7559 | llvm::Optional<unsigned> OrigNumExpansions |
| 7560 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 7561 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 7562 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 7563 | PatternTL.getSourceRange(), |
| 7564 | Unexpanded, |
| 7565 | Expand, RetainExpansion, |
| 7566 | NumExpansions)) |
| 7567 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7568 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7569 | if (!Expand) { |
| 7570 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7571 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7572 | // expansion. |
| 7573 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7574 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7575 | TypeLocBuilder TLB; |
| 7576 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 7577 | |
| 7578 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7579 | if (To.isNull()) |
| 7580 | return ExprError(); |
| 7581 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7582 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7583 | PatternTL.getSourceRange(), |
| 7584 | ExpansionTL.getEllipsisLoc(), |
| 7585 | NumExpansions); |
| 7586 | if (To.isNull()) |
| 7587 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7588 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7589 | PackExpansionTypeLoc ToExpansionTL |
| 7590 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7591 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7592 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7593 | continue; |
| 7594 | } |
| 7595 | |
| 7596 | // Expand the pack expansion by substituting for each argument in the |
| 7597 | // pack(s). |
| 7598 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7599 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 7600 | TypeLocBuilder TLB; |
| 7601 | TLB.reserve(PatternTL.getFullDataSize()); |
| 7602 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7603 | if (To.isNull()) |
| 7604 | return ExprError(); |
| 7605 | |
| 7606 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7607 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7608 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7609 | if (!RetainExpansion) |
| 7610 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7611 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7612 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 7613 | // forgetting the partially-substituted parameter pack. |
| 7614 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 7615 | |
| 7616 | TypeLocBuilder TLB; |
| 7617 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7618 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7619 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7620 | if (To.isNull()) |
| 7621 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7622 | |
| 7623 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7624 | PatternTL.getSourceRange(), |
| 7625 | ExpansionTL.getEllipsisLoc(), |
| 7626 | NumExpansions); |
| 7627 | if (To.isNull()) |
| 7628 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7629 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7630 | PackExpansionTypeLoc ToExpansionTL |
| 7631 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7632 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7633 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7634 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7635 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7636 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 7637 | return SemaRef.Owned(E); |
| 7638 | |
| 7639 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 7640 | E->getLocStart(), |
| 7641 | Args, |
| 7642 | E->getLocEnd()); |
| 7643 | } |
| 7644 | |
| 7645 | template<typename Derived> |
| 7646 | ExprResult |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 7647 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 7648 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7649 | if (!T) |
| 7650 | return ExprError(); |
| 7651 | |
| 7652 | if (!getDerived().AlwaysRebuild() && |
| 7653 | T == E->getQueriedTypeSourceInfo()) |
| 7654 | return SemaRef.Owned(E); |
| 7655 | |
| 7656 | ExprResult SubExpr; |
| 7657 | { |
| 7658 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7659 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 7660 | if (SubExpr.isInvalid()) |
| 7661 | return ExprError(); |
| 7662 | |
| 7663 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 7664 | return SemaRef.Owned(E); |
| 7665 | } |
| 7666 | |
| 7667 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 7668 | E->getLocStart(), |
| 7669 | T, |
| 7670 | SubExpr.get(), |
| 7671 | E->getLocEnd()); |
| 7672 | } |
| 7673 | |
| 7674 | template<typename Derived> |
| 7675 | ExprResult |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 7676 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 7677 | ExprResult SubExpr; |
| 7678 | { |
| 7679 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7680 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 7681 | if (SubExpr.isInvalid()) |
| 7682 | return ExprError(); |
| 7683 | |
| 7684 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 7685 | return SemaRef.Owned(E); |
| 7686 | } |
| 7687 | |
| 7688 | return getDerived().RebuildExpressionTrait( |
| 7689 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 7690 | } |
| 7691 | |
| 7692 | template<typename Derived> |
| 7693 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7694 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7695 | DependentScopeDeclRefExpr *E) { |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7696 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false); |
| 7697 | } |
| 7698 | |
| 7699 | template<typename Derived> |
| 7700 | ExprResult |
| 7701 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 7702 | DependentScopeDeclRefExpr *E, |
| 7703 | bool IsAddressOfOperand) { |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7704 | NestedNameSpecifierLoc QualifierLoc |
| 7705 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7706 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7707 | return ExprError(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7708 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7709 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7710 | // TODO: If this is a conversion-function-id, verify that the |
| 7711 | // destination type name (if present) resolves the same way after |
| 7712 | // instantiation as it did in the local scope. |
| 7713 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7714 | DeclarationNameInfo NameInfo |
| 7715 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 7716 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7717 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7718 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7719 | if (!E->hasExplicitTemplateArgs()) { |
| 7720 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7721 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7722 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 7723 | // if name has not changed, DNLoc has not changed either. |
| 7724 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7725 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7726 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7727 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7728 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7729 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7730 | /*TemplateArgs*/ 0, |
| 7731 | IsAddressOfOperand); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 7732 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7733 | |
| 7734 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7735 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7736 | E->getNumTemplateArgs(), |
| 7737 | TransArgs)) |
| 7738 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7739 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7740 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7741 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7742 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7743 | &TransArgs, |
| 7744 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7745 | } |
| 7746 | |
| 7747 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7748 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7749 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 7750 | // CXXConstructExprs are always implicit, so when we have a |
| 7751 | // 1-argument construction we just transform that argument. |
Richard Smith | 73ed67c | 2012-11-26 08:32:48 +0000 | [diff] [blame^] | 7752 | if ((E->getNumArgs() == 1 || |
| 7753 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
| 7754 | (!getDerived().DropCallArgument(E->getArg(0)))) |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 7755 | return getDerived().TransformExpr(E->getArg(0)); |
| 7756 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7757 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 7758 | |
| 7759 | QualType T = getDerived().TransformType(E->getType()); |
| 7760 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7761 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7762 | |
| 7763 | CXXConstructorDecl *Constructor |
| 7764 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7765 | getDerived().TransformDecl(E->getLocStart(), |
| 7766 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7767 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7768 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7769 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7770 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7771 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7772 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7773 | &ArgumentChanged)) |
| 7774 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7775 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7776 | if (!getDerived().AlwaysRebuild() && |
| 7777 | T == E->getType() && |
| 7778 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7779 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7780 | // Mark the constructor as referenced. |
| 7781 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7782 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7783 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7784 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7785 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 7786 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 7787 | Constructor, E->isElidable(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7788 | Args, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 7789 | E->hadMultipleCandidates(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7790 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 7791 | E->getConstructionKind(), |
| 7792 | E->getParenRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7793 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7794 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7795 | /// \brief Transform a C++ temporary-binding expression. |
| 7796 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7797 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 7798 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7799 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7800 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7801 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7802 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7803 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7804 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7805 | /// \brief Transform a C++ expression that contains cleanups that should |
| 7806 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7807 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7808 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7809 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7810 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7811 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7812 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7813 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7814 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7815 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7816 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7817 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7818 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7819 | CXXTemporaryObjectExpr *E) { |
| 7820 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7821 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7822 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7823 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7824 | CXXConstructorDecl *Constructor |
| 7825 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7826 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7827 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7828 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7829 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7830 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7831 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7832 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7833 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7834 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7835 | &ArgumentChanged)) |
| 7836 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7837 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7838 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7839 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7840 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7841 | !ArgumentChanged) { |
| 7842 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7843 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7844 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7845 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7846 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7847 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 7848 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7849 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7850 | E->getLocEnd()); |
| 7851 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7852 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7853 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7854 | ExprResult |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 7855 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7856 | // Transform the type of the lambda parameters and start the definition of |
| 7857 | // the lambda itself. |
| 7858 | TypeSourceInfo *MethodTy |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7859 | = TransformType(E->getCallOperator()->getTypeSourceInfo()); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7860 | if (!MethodTy) |
| 7861 | return ExprError(); |
| 7862 | |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 7863 | // Create the local class that will describe the lambda. |
| 7864 | CXXRecordDecl *Class |
| 7865 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| 7866 | MethodTy, |
| 7867 | /*KnownDependent=*/false); |
| 7868 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 7869 | |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 7870 | // Transform lambda parameters. |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 7871 | llvm::SmallVector<QualType, 4> ParamTypes; |
| 7872 | llvm::SmallVector<ParmVarDecl *, 4> Params; |
| 7873 | if (getDerived().TransformFunctionTypeParams(E->getLocStart(), |
| 7874 | E->getCallOperator()->param_begin(), |
| 7875 | E->getCallOperator()->param_size(), |
| 7876 | 0, ParamTypes, &Params)) |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 7877 | return ExprError(); |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 7878 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7879 | // Build the call operator. |
| 7880 | CXXMethodDecl *CallOperator |
| 7881 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 7882 | MethodTy, |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 7883 | E->getCallOperator()->getLocEnd(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 7884 | Params); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7885 | getDerived().transformAttrs(E->getCallOperator(), CallOperator); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 7886 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 7887 | return getDerived().TransformLambdaScope(E, CallOperator); |
| 7888 | } |
| 7889 | |
| 7890 | template<typename Derived> |
| 7891 | ExprResult |
| 7892 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
| 7893 | CXXMethodDecl *CallOperator) { |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 7894 | // Introduce the context of the call operator. |
| 7895 | Sema::ContextRAII SavedContext(getSema(), CallOperator); |
| 7896 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7897 | // Enter the scope of the lambda. |
| 7898 | sema::LambdaScopeInfo *LSI |
| 7899 | = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(), |
| 7900 | E->getCaptureDefault(), |
| 7901 | E->hasExplicitParameters(), |
| 7902 | E->hasExplicitResultType(), |
| 7903 | E->isMutable()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7904 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7905 | // Transform captures. |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 7906 | bool Invalid = false; |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7907 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7908 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7909 | CEnd = E->capture_end(); |
| 7910 | C != CEnd; ++C) { |
| 7911 | // When we hit the first implicit capture, tell Sema that we've finished |
| 7912 | // the list of explicit captures. |
| 7913 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 7914 | getSema().finishLambdaExplicitCaptures(LSI); |
| 7915 | FinishedExplicitCaptures = true; |
| 7916 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7917 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7918 | // Capturing 'this' is trivial. |
| 7919 | if (C->capturesThis()) { |
| 7920 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 7921 | continue; |
| 7922 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7923 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7924 | // Determine the capture kind for Sema. |
| 7925 | Sema::TryCaptureKind Kind |
| 7926 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 7927 | : C->getCaptureKind() == LCK_ByCopy |
| 7928 | ? Sema::TryCapture_ExplicitByVal |
| 7929 | : Sema::TryCapture_ExplicitByRef; |
| 7930 | SourceLocation EllipsisLoc; |
| 7931 | if (C->isPackExpansion()) { |
| 7932 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 7933 | bool ShouldExpand = false; |
| 7934 | bool RetainExpansion = false; |
| 7935 | llvm::Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7936 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 7937 | C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7938 | Unexpanded, |
| 7939 | ShouldExpand, RetainExpansion, |
| 7940 | NumExpansions)) |
| 7941 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7942 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7943 | if (ShouldExpand) { |
| 7944 | // The transform has determined that we should perform an expansion; |
| 7945 | // transform and capture each of the arguments. |
| 7946 | // expansion of the pattern. Do so. |
| 7947 | VarDecl *Pack = C->getCapturedVar(); |
| 7948 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7949 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 7950 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7951 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7952 | Pack)); |
| 7953 | if (!CapturedVar) { |
| 7954 | Invalid = true; |
| 7955 | continue; |
| 7956 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7957 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7958 | // Capture the transformed variable. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7959 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 7960 | } |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7961 | continue; |
| 7962 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7963 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 7964 | EllipsisLoc = C->getEllipsisLoc(); |
| 7965 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7966 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7967 | // Transform the captured variable. |
| 7968 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7969 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7970 | C->getCapturedVar())); |
| 7971 | if (!CapturedVar) { |
| 7972 | Invalid = true; |
| 7973 | continue; |
| 7974 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7975 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7976 | // Capture the transformed variable. |
Douglas Gregor | 999713e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 7977 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7978 | } |
| 7979 | if (!FinishedExplicitCaptures) |
| 7980 | getSema().finishLambdaExplicitCaptures(LSI); |
| 7981 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7982 | |
| 7983 | // Enter a new evaluation context to insulate the lambda from any |
| 7984 | // cleanups from the enclosing full-expression. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7985 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7986 | |
| 7987 | if (Invalid) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7988 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 7989 | /*IsInstantiation=*/true); |
| 7990 | return ExprError(); |
| 7991 | } |
| 7992 | |
| 7993 | // Instantiate the body of the lambda expression. |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 7994 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 7995 | if (Body.isInvalid()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7996 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 7997 | /*IsInstantiation=*/true); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7998 | return ExprError(); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 7999 | } |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 8000 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8001 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 8002 | /*CurScope=*/0, /*IsInstantiation=*/true); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8003 | } |
| 8004 | |
| 8005 | template<typename Derived> |
| 8006 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8007 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8008 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8009 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8010 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8011 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8012 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8013 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8014 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8015 | Args.reserve(E->arg_size()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8016 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8017 | &ArgumentChanged)) |
| 8018 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8019 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8020 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8021 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8022 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8023 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8024 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8025 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8026 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8027 | E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8028 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8029 | E->getRParenLoc()); |
| 8030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8032 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8033 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8034 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8035 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8036 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8037 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8038 | Expr *OldBase; |
| 8039 | QualType BaseType; |
| 8040 | QualType ObjectType; |
| 8041 | if (!E->isImplicitAccess()) { |
| 8042 | OldBase = E->getBase(); |
| 8043 | Base = getDerived().TransformExpr(OldBase); |
| 8044 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8045 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8046 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8047 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8048 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8049 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8050 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8051 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8052 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8053 | ObjectTy, |
| 8054 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8055 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8056 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8057 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8058 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8059 | BaseType = ((Expr*) Base.get())->getType(); |
| 8060 | } else { |
| 8061 | OldBase = 0; |
| 8062 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 8063 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 8064 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8065 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8066 | // Transform the first part of the nested-name-specifier that qualifies |
| 8067 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 8068 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8069 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8070 | E->getFirstQualifierFoundInScope(), |
| 8071 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8072 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8073 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8074 | if (E->getQualifier()) { |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8075 | QualifierLoc |
| 8076 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 8077 | ObjectType, |
| 8078 | FirstQualifierInScope); |
| 8079 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8080 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8081 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8082 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8083 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 8084 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8085 | // TODO: If this is a conversion-function-id, verify that the |
| 8086 | // destination type name (if present) resolves the same way after |
| 8087 | // instantiation as it did in the local scope. |
| 8088 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8089 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8090 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8091 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8092 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8093 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8094 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8095 | // This is a reference to a member without an explicitly-specified |
| 8096 | // template argument list. Optimize for this common case. |
| 8097 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8098 | Base.get() == OldBase && |
| 8099 | BaseType == E->getBaseType() && |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8100 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8101 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8102 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8103 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8104 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8105 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8106 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8107 | E->isArrow(), |
| 8108 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8109 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8110 | TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8111 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8112 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8113 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8114 | } |
| 8115 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8116 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8117 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8118 | E->getNumTemplateArgs(), |
| 8119 | TransArgs)) |
| 8120 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8121 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8122 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8123 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8124 | E->isArrow(), |
| 8125 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8126 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8127 | TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8128 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8129 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8130 | &TransArgs); |
| 8131 | } |
| 8132 | |
| 8133 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8134 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8135 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8136 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8137 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8138 | QualType BaseType; |
| 8139 | if (!Old->isImplicitAccess()) { |
| 8140 | Base = getDerived().TransformExpr(Old->getBase()); |
| 8141 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8142 | return ExprError(); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 8143 | Base = getSema().PerformMemberExprBaseConversion(Base.take(), |
| 8144 | Old->isArrow()); |
| 8145 | if (Base.isInvalid()) |
| 8146 | return ExprError(); |
| 8147 | BaseType = Base.get()->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8148 | } else { |
| 8149 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 8150 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8151 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8152 | NestedNameSpecifierLoc QualifierLoc; |
| 8153 | if (Old->getQualifierLoc()) { |
| 8154 | QualifierLoc |
| 8155 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8156 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8157 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8158 | } |
| 8159 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8160 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8161 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8162 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8163 | Sema::LookupOrdinaryName); |
| 8164 | |
| 8165 | // Transform all the decls. |
| 8166 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 8167 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8168 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8169 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 8170 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8171 | if (!InstD) { |
| 8172 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8173 | // This can happen because of dependent hiding. |
| 8174 | if (isa<UsingShadowDecl>(*I)) |
| 8175 | continue; |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8176 | else { |
| 8177 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8178 | return ExprError(); |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8179 | } |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8180 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8181 | |
| 8182 | // Expand using declarations. |
| 8183 | if (isa<UsingDecl>(InstD)) { |
| 8184 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 8185 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 8186 | E = UD->shadow_end(); I != E; ++I) |
| 8187 | R.addDecl(*I); |
| 8188 | continue; |
| 8189 | } |
| 8190 | |
| 8191 | R.addDecl(InstD); |
| 8192 | } |
| 8193 | |
| 8194 | R.resolveKind(); |
| 8195 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8196 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 8197 | if (Old->getNamingClass()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8198 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8199 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8200 | Old->getMemberLoc(), |
| 8201 | Old->getNamingClass())); |
| 8202 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8203 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8204 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8205 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8206 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8207 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8208 | TemplateArgumentListInfo TransArgs; |
| 8209 | if (Old->hasExplicitTemplateArgs()) { |
| 8210 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 8211 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8212 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 8213 | Old->getNumTemplateArgs(), |
| 8214 | TransArgs)) |
| 8215 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8216 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8217 | |
| 8218 | // FIXME: to do this check properly, we will need to preserve the |
| 8219 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8220 | // base (and therefore couldn't do the check) and a |
| 8221 | // nested-name-qualifier (and therefore could do the lookup). |
| 8222 | NamedDecl *FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8223 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8224 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8225 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8226 | Old->getOperatorLoc(), |
| 8227 | Old->isArrow(), |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8228 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8229 | TemplateKWLoc, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8230 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8231 | R, |
| 8232 | (Old->hasExplicitTemplateArgs() |
| 8233 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8234 | } |
| 8235 | |
| 8236 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8237 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8238 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Sean Hunt | eea06c6 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 8239 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8240 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 8241 | if (SubExpr.isInvalid()) |
| 8242 | return ExprError(); |
| 8243 | |
| 8244 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8245 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8246 | |
| 8247 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 8248 | } |
| 8249 | |
| 8250 | template<typename Derived> |
| 8251 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8252 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8253 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 8254 | if (Pattern.isInvalid()) |
| 8255 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8256 | |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8257 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 8258 | return SemaRef.Owned(E); |
| 8259 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 8260 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 8261 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8262 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8263 | |
| 8264 | template<typename Derived> |
| 8265 | ExprResult |
| 8266 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 8267 | // If E is not value-dependent, then nothing will change when we transform it. |
| 8268 | // Note: This is an instantiation-centric view. |
| 8269 | if (!E->isValueDependent()) |
| 8270 | return SemaRef.Owned(E); |
| 8271 | |
| 8272 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 8273 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8274 | // so |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8275 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 8276 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8277 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 8278 | llvm::Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8279 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 8280 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8281 | ShouldExpand, RetainExpansion, |
| 8282 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8283 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8284 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8285 | if (RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8286 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8287 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8288 | NamedDecl *Pack = E->getPack(); |
| 8289 | if (!ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8290 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8291 | Pack)); |
| 8292 | if (!Pack) |
| 8293 | return ExprError(); |
| 8294 | } |
| 8295 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8296 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8297 | // We now know the length of the parameter pack, so build a new expression |
| 8298 | // that stores that length. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8299 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 8300 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8301 | NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8302 | } |
| 8303 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8304 | template<typename Derived> |
| 8305 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 8306 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 8307 | SubstNonTypeTemplateParmPackExpr *E) { |
| 8308 | // Default behavior is to do nothing with this transformation. |
| 8309 | return SemaRef.Owned(E); |
| 8310 | } |
| 8311 | |
| 8312 | template<typename Derived> |
| 8313 | ExprResult |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 8314 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 8315 | SubstNonTypeTemplateParmExpr *E) { |
| 8316 | // Default behavior is to do nothing with this transformation. |
| 8317 | return SemaRef.Owned(E); |
| 8318 | } |
| 8319 | |
| 8320 | template<typename Derived> |
| 8321 | ExprResult |
Richard Smith | 9a4db03 | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 8322 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 8323 | // Default behavior is to do nothing with this transformation. |
| 8324 | return SemaRef.Owned(E); |
| 8325 | } |
| 8326 | |
| 8327 | template<typename Derived> |
| 8328 | ExprResult |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8329 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 8330 | MaterializeTemporaryExpr *E) { |
| 8331 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 8332 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8333 | |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8334 | template<typename Derived> |
| 8335 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8336 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8337 | return SemaRef.MaybeBindToTemporary(E); |
| 8338 | } |
| 8339 | |
| 8340 | template<typename Derived> |
| 8341 | ExprResult |
| 8342 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Jordy Rose | d8b5ca1 | 2012-03-12 17:53:02 +0000 | [diff] [blame] | 8343 | return SemaRef.Owned(E); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8344 | } |
| 8345 | |
| 8346 | template<typename Derived> |
| 8347 | ExprResult |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 8348 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 8349 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 8350 | if (SubExpr.isInvalid()) |
| 8351 | return ExprError(); |
| 8352 | |
| 8353 | if (!getDerived().AlwaysRebuild() && |
| 8354 | SubExpr.get() == E->getSubExpr()) |
| 8355 | return SemaRef.Owned(E); |
| 8356 | |
| 8357 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8358 | } |
| 8359 | |
| 8360 | template<typename Derived> |
| 8361 | ExprResult |
| 8362 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 8363 | // Transform each of the elements. |
| 8364 | llvm::SmallVector<Expr *, 8> Elements; |
| 8365 | bool ArgChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8366 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8367 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 8368 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8369 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8370 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8371 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8372 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8373 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 8374 | Elements.data(), |
| 8375 | Elements.size()); |
| 8376 | } |
| 8377 | |
| 8378 | template<typename Derived> |
| 8379 | ExprResult |
| 8380 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8381 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8382 | // Transform each of the elements. |
| 8383 | llvm::SmallVector<ObjCDictionaryElement, 8> Elements; |
| 8384 | bool ArgChanged = false; |
| 8385 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 8386 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8387 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8388 | if (OrigElement.isPackExpansion()) { |
| 8389 | // This key/value element is a pack expansion. |
| 8390 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8391 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 8392 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 8393 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 8394 | |
| 8395 | // Determine whether the set of unexpanded parameter packs can |
| 8396 | // and should be expanded. |
| 8397 | bool Expand = true; |
| 8398 | bool RetainExpansion = false; |
| 8399 | llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 8400 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 8401 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 8402 | OrigElement.Value->getLocEnd()); |
| 8403 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 8404 | PatternRange, |
| 8405 | Unexpanded, |
| 8406 | Expand, RetainExpansion, |
| 8407 | NumExpansions)) |
| 8408 | return ExprError(); |
| 8409 | |
| 8410 | if (!Expand) { |
| 8411 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8412 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8413 | // expansion. |
| 8414 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 8415 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8416 | if (Key.isInvalid()) |
| 8417 | return ExprError(); |
| 8418 | |
| 8419 | if (Key.get() != OrigElement.Key) |
| 8420 | ArgChanged = true; |
| 8421 | |
| 8422 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8423 | if (Value.isInvalid()) |
| 8424 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8425 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8426 | if (Value.get() != OrigElement.Value) |
| 8427 | ArgChanged = true; |
| 8428 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8429 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8430 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 8431 | }; |
| 8432 | Elements.push_back(Expansion); |
| 8433 | continue; |
| 8434 | } |
| 8435 | |
| 8436 | // Record right away that the argument was changed. This needs |
| 8437 | // to happen even if the array expands to nothing. |
| 8438 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8439 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8440 | // The transform has determined that we should perform an elementwise |
| 8441 | // expansion of the pattern. Do so. |
| 8442 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8443 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8444 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8445 | if (Key.isInvalid()) |
| 8446 | return ExprError(); |
| 8447 | |
| 8448 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8449 | if (Value.isInvalid()) |
| 8450 | return ExprError(); |
| 8451 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8452 | ObjCDictionaryElement Element = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8453 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 8454 | }; |
| 8455 | |
| 8456 | // If any unexpanded parameter packs remain, we still have a |
| 8457 | // pack expansion. |
| 8458 | if (Key.get()->containsUnexpandedParameterPack() || |
| 8459 | Value.get()->containsUnexpandedParameterPack()) |
| 8460 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8461 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8462 | Elements.push_back(Element); |
| 8463 | } |
| 8464 | |
| 8465 | // We've finished with this pack expansion. |
| 8466 | continue; |
| 8467 | } |
| 8468 | |
| 8469 | // Transform and check key. |
| 8470 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8471 | if (Key.isInvalid()) |
| 8472 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8473 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8474 | if (Key.get() != OrigElement.Key) |
| 8475 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8476 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8477 | // Transform and check value. |
| 8478 | ExprResult Value |
| 8479 | = getDerived().TransformExpr(OrigElement.Value); |
| 8480 | if (Value.isInvalid()) |
| 8481 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8482 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8483 | if (Value.get() != OrigElement.Value) |
| 8484 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8485 | |
| 8486 | ObjCDictionaryElement Element = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8487 | Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>() |
| 8488 | }; |
| 8489 | Elements.push_back(Element); |
| 8490 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8491 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8492 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8493 | return SemaRef.MaybeBindToTemporary(E); |
| 8494 | |
| 8495 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 8496 | Elements.data(), |
| 8497 | Elements.size()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8498 | } |
| 8499 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8500 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8501 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8502 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8503 | TypeSourceInfo *EncodedTypeInfo |
| 8504 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 8505 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8506 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8507 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8508 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8509 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8510 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8511 | |
| 8512 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8513 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8514 | E->getRParenLoc()); |
| 8515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8516 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8517 | template<typename Derived> |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8518 | ExprResult TreeTransform<Derived>:: |
| 8519 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| 8520 | ExprResult result = getDerived().TransformExpr(E->getSubExpr()); |
| 8521 | if (result.isInvalid()) return ExprError(); |
| 8522 | Expr *subExpr = result.take(); |
| 8523 | |
| 8524 | if (!getDerived().AlwaysRebuild() && |
| 8525 | subExpr == E->getSubExpr()) |
| 8526 | return SemaRef.Owned(E); |
| 8527 | |
| 8528 | return SemaRef.Owned(new(SemaRef.Context) |
| 8529 | ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); |
| 8530 | } |
| 8531 | |
| 8532 | template<typename Derived> |
| 8533 | ExprResult TreeTransform<Derived>:: |
| 8534 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8535 | TypeSourceInfo *TSInfo |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8536 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8537 | if (!TSInfo) |
| 8538 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8539 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8540 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8541 | if (Result.isInvalid()) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8542 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8543 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8544 | if (!getDerived().AlwaysRebuild() && |
| 8545 | TSInfo == E->getTypeInfoAsWritten() && |
| 8546 | Result.get() == E->getSubExpr()) |
| 8547 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8548 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8549 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8550 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8551 | Result.get()); |
| 8552 | } |
| 8553 | |
| 8554 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8555 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8556 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8557 | // Transform arguments. |
| 8558 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8559 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8560 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8561 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8562 | &ArgChanged)) |
| 8563 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8564 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8565 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 8566 | // Class message: transform the receiver type. |
| 8567 | TypeSourceInfo *ReceiverTypeInfo |
| 8568 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 8569 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8570 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8571 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8572 | // If nothing changed, just retain the existing message send. |
| 8573 | if (!getDerived().AlwaysRebuild() && |
| 8574 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8575 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8576 | |
| 8577 | // Build a new class message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8578 | SmallVector<SourceLocation, 16> SelLocs; |
| 8579 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8580 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 8581 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8582 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8583 | E->getMethodDecl(), |
| 8584 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8585 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8586 | E->getRightLoc()); |
| 8587 | } |
| 8588 | |
| 8589 | // Instance message: transform the receiver |
| 8590 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 8591 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8592 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8593 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 8594 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8595 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8596 | |
| 8597 | // If nothing changed, just retain the existing message send. |
| 8598 | if (!getDerived().AlwaysRebuild() && |
| 8599 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8600 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8601 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8602 | // Build a new instance message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8603 | SmallVector<SourceLocation, 16> SelLocs; |
| 8604 | E->getSelectorLocs(SelLocs); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8605 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8606 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8607 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8608 | E->getMethodDecl(), |
| 8609 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8610 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8611 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8612 | } |
| 8613 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8614 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8615 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8616 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8617 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8618 | } |
| 8619 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8620 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8621 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8622 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8623 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8624 | } |
| 8625 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8626 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8627 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8628 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8629 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8630 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8631 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8632 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8633 | |
| 8634 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8635 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8636 | // If nothing changed, just retain the existing expression. |
| 8637 | if (!getDerived().AlwaysRebuild() && |
| 8638 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8639 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8640 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8641 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8642 | E->getLocation(), |
| 8643 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8644 | } |
| 8645 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8646 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8647 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8648 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8649 | // 'super' and types never change. Property never changes. Just |
| 8650 | // retain the existing expression. |
| 8651 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8652 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8653 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8654 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8655 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8656 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8657 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8658 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8659 | // We don't need to transform the property; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8660 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 8661 | // If nothing changed, just retain the existing expression. |
| 8662 | if (!getDerived().AlwaysRebuild() && |
| 8663 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8664 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8665 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8666 | if (E->isExplicitProperty()) |
| 8667 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 8668 | E->getExplicitProperty(), |
| 8669 | E->getLocation()); |
| 8670 | |
| 8671 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 8672 | SemaRef.Context.PseudoObjectTy, |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 8673 | E->getImplicitPropertyGetter(), |
| 8674 | E->getImplicitPropertySetter(), |
| 8675 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8676 | } |
| 8677 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8678 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8679 | ExprResult |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8680 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 8681 | // Transform the base expression. |
| 8682 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 8683 | if (Base.isInvalid()) |
| 8684 | return ExprError(); |
| 8685 | |
| 8686 | // Transform the key expression. |
| 8687 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 8688 | if (Key.isInvalid()) |
| 8689 | return ExprError(); |
| 8690 | |
| 8691 | // If nothing changed, just retain the existing expression. |
| 8692 | if (!getDerived().AlwaysRebuild() && |
| 8693 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 8694 | return SemaRef.Owned(E); |
| 8695 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8696 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8697 | Base.get(), Key.get(), |
| 8698 | E->getAtIndexMethodDecl(), |
| 8699 | E->setAtIndexMethodDecl()); |
| 8700 | } |
| 8701 | |
| 8702 | template<typename Derived> |
| 8703 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8704 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8705 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8706 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8707 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8708 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8709 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8710 | // If nothing changed, just retain the existing expression. |
| 8711 | if (!getDerived().AlwaysRebuild() && |
| 8712 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8713 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8714 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8715 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 8716 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8717 | } |
| 8718 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8719 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8720 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8721 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8722 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8723 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8724 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8725 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8726 | SubExprs, &ArgumentChanged)) |
| 8727 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8728 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8729 | if (!getDerived().AlwaysRebuild() && |
| 8730 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8731 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8732 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8733 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8734 | SubExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8735 | E->getRParenLoc()); |
| 8736 | } |
| 8737 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8738 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8739 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8740 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8741 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8742 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8743 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 8744 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 8745 | |
| 8746 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 0586520 | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 8747 | blockScope->TheDecl->setBlockMissingReturnType( |
| 8748 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8749 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 8750 | SmallVector<ParmVarDecl*, 4> params; |
| 8751 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8752 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8753 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8754 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 8755 | oldBlock->param_begin(), |
| 8756 | oldBlock->param_size(), |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8757 | 0, paramTypes, ¶ms)) { |
| 8758 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8759 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8760 | } |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8761 | |
| 8762 | const FunctionType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8763 | QualType exprResultType = |
| 8764 | getDerived().TransformType(exprFunctionType->getResultType()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8765 | |
| 8766 | // Don't allow returning a objc interface by value. |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8767 | if (exprResultType->isObjCObjectType()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8768 | getSema().Diag(E->getCaretLocation(), |
| 8769 | diag::err_object_cannot_be_passed_returned_by_value) |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8770 | << 0 << exprResultType; |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8771 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 8772 | return ExprError(); |
| 8773 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8774 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8775 | QualType functionType = getDerived().RebuildFunctionProtoType( |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8776 | exprResultType, |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8777 | paramTypes.data(), |
| 8778 | paramTypes.size(), |
| 8779 | oldBlock->isVariadic(), |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 8780 | false, 0, RQ_None, |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8781 | exprFunctionType->getExtInfo()); |
| 8782 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8783 | |
| 8784 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8785 | if (!params.empty()) |
David Blaikie | 4278c65 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 8786 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 8787 | |
| 8788 | if (!oldBlock->blockMissingReturnType()) { |
| 8789 | blockScope->HasImplicitReturnType = false; |
| 8790 | blockScope->ReturnType = exprResultType; |
| 8791 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8792 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8793 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8794 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8795 | if (body.isInvalid()) { |
| 8796 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8797 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 8798 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 8799 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8800 | #ifndef NDEBUG |
| 8801 | // In builds with assertions, make sure that we captured everything we |
| 8802 | // captured before. |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8803 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 8804 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 8805 | e = oldBlock->capture_end(); i != e; ++i) { |
| 8806 | VarDecl *oldCapture = i->getVariable(); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8807 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8808 | // Ignore parameter packs. |
| 8809 | if (isa<ParmVarDecl>(oldCapture) && |
| 8810 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 8811 | continue; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8812 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8813 | VarDecl *newCapture = |
| 8814 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 8815 | oldCapture)); |
| 8816 | assert(blockScope->CaptureMap.count(newCapture)); |
| 8817 | } |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 8818 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8819 | } |
| 8820 | #endif |
| 8821 | |
| 8822 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 8823 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8824 | } |
| 8825 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8826 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8827 | ExprResult |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8828 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 8829 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8830 | } |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 8831 | |
| 8832 | template<typename Derived> |
| 8833 | ExprResult |
| 8834 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 8835 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 8836 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8837 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 8838 | SubExprs.reserve(E->getNumSubExprs()); |
| 8839 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 8840 | SubExprs, &ArgumentChanged)) |
| 8841 | return ExprError(); |
| 8842 | |
| 8843 | if (!getDerived().AlwaysRebuild() && |
| 8844 | !ArgumentChanged) |
| 8845 | return SemaRef.Owned(E); |
| 8846 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8847 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 8848 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 8849 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8850 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8851 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8852 | // Type reconstruction |
| 8853 | //===----------------------------------------------------------------------===// |
| 8854 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8855 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8856 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 8857 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8858 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8859 | getDerived().getBaseEntity()); |
| 8860 | } |
| 8861 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8862 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8863 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 8864 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8865 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8866 | getDerived().getBaseEntity()); |
| 8867 | } |
| 8868 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8869 | template<typename Derived> |
| 8870 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8871 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 8872 | bool WrittenAsLValue, |
| 8873 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8874 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8875 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8876 | } |
| 8877 | |
| 8878 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8879 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8880 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 8881 | QualType ClassType, |
| 8882 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8883 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8884 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8885 | } |
| 8886 | |
| 8887 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8888 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8889 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 8890 | ArrayType::ArraySizeModifier SizeMod, |
| 8891 | const llvm::APInt *Size, |
| 8892 | Expr *SizeExpr, |
| 8893 | unsigned IndexTypeQuals, |
| 8894 | SourceRange BracketsRange) { |
| 8895 | if (SizeExpr || !Size) |
| 8896 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 8897 | IndexTypeQuals, BracketsRange, |
| 8898 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8899 | |
| 8900 | QualType Types[] = { |
| 8901 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 8902 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 8903 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8904 | }; |
| 8905 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 8906 | QualType SizeType; |
| 8907 | for (unsigned I = 0; I != NumTypes; ++I) |
| 8908 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 8909 | SizeType = Types[I]; |
| 8910 | break; |
| 8911 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8912 | |
Eli Friedman | 01f276d | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 8913 | // Note that we can return a VariableArrayType here in the case where |
| 8914 | // the element type was a dependent VariableArrayType. |
| 8915 | IntegerLiteral *ArraySize |
| 8916 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 8917 | /*FIXME*/BracketsRange.getBegin()); |
| 8918 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8919 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8920 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8921 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8922 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8923 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8924 | QualType |
| 8925 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8926 | ArrayType::ArraySizeModifier SizeMod, |
| 8927 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8928 | unsigned IndexTypeQuals, |
| 8929 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8930 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8931 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8932 | } |
| 8933 | |
| 8934 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8935 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8936 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8937 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8938 | unsigned IndexTypeQuals, |
| 8939 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8940 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8941 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8942 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8943 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8944 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8945 | QualType |
| 8946 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8947 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8948 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8949 | unsigned IndexTypeQuals, |
| 8950 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8951 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8952 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8953 | IndexTypeQuals, BracketsRange); |
| 8954 | } |
| 8955 | |
| 8956 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8957 | QualType |
| 8958 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8959 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8960 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8961 | unsigned IndexTypeQuals, |
| 8962 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8963 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8964 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8965 | IndexTypeQuals, BracketsRange); |
| 8966 | } |
| 8967 | |
| 8968 | template<typename Derived> |
| 8969 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 8970 | unsigned NumElements, |
| 8971 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8972 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 8973 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8974 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8975 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8976 | template<typename Derived> |
| 8977 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 8978 | unsigned NumElements, |
| 8979 | SourceLocation AttributeLoc) { |
| 8980 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 8981 | NumElements, true); |
| 8982 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 8983 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 8984 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8985 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8986 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8987 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8988 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8989 | QualType |
| 8990 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8991 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8992 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8993 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8994 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8995 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8996 | template<typename Derived> |
| 8997 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8998 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8999 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9000 | bool Variadic, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 9001 | bool HasTrailingReturn, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9002 | unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 9003 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9004 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9005 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 9006 | HasTrailingReturn, Quals, RefQualifier, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9007 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9008 | getDerived().getBaseEntity(), |
| 9009 | Info); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9010 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9011 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9012 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 9013 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 9014 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 9015 | } |
| 9016 | |
| 9017 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9018 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 9019 | assert(D && "no decl found"); |
| 9020 | if (D->isInvalidDecl()) return QualType(); |
| 9021 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9022 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9023 | TypeDecl *Ty; |
| 9024 | if (isa<UsingDecl>(D)) { |
| 9025 | UsingDecl *Using = cast<UsingDecl>(D); |
| 9026 | assert(Using->isTypeName() && |
| 9027 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 9028 | |
| 9029 | // A valid resolved using typename decl points to exactly one type decl. |
| 9030 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 9031 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9032 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9033 | } else { |
| 9034 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 9035 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 9036 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 9037 | } |
| 9038 | |
| 9039 | return SemaRef.Context.getTypeDeclType(Ty); |
| 9040 | } |
| 9041 | |
| 9042 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9043 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 9044 | SourceLocation Loc) { |
| 9045 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9046 | } |
| 9047 | |
| 9048 | template<typename Derived> |
| 9049 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 9050 | return SemaRef.Context.getTypeOfType(Underlying); |
| 9051 | } |
| 9052 | |
| 9053 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9054 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 9055 | SourceLocation Loc) { |
| 9056 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9057 | } |
| 9058 | |
| 9059 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 9060 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 9061 | UnaryTransformType::UTTKind UKind, |
| 9062 | SourceLocation Loc) { |
| 9063 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 9064 | } |
| 9065 | |
| 9066 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9067 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 9068 | TemplateName Template, |
| 9069 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 9070 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9071 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9072 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9073 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 9074 | template<typename Derived> |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 9075 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 9076 | SourceLocation KWLoc) { |
| 9077 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 9078 | } |
| 9079 | |
| 9080 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9081 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9082 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9083 | bool TemplateKW, |
| 9084 | TemplateDecl *Template) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9085 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9086 | Template); |
| 9087 | } |
| 9088 | |
| 9089 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9090 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9091 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 9092 | const IdentifierInfo &Name, |
| 9093 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9094 | QualType ObjectType, |
| 9095 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9096 | UnqualifiedId TemplateName; |
| 9097 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9098 | Sema::TemplateTy Template; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9099 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9100 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9101 | SS, TemplateKWLoc, TemplateName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9102 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9103 | /*EnteringContext=*/false, |
| 9104 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9105 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9106 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9107 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9108 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9109 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9110 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9111 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9112 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9113 | QualType ObjectType) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9114 | UnqualifiedId Name; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9115 | // FIXME: Bogus location information. |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9116 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9117 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9118 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9119 | Sema::TemplateTy Template; |
| 9120 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9121 | SS, TemplateKWLoc, Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9122 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9123 | /*EnteringContext=*/false, |
| 9124 | Template); |
| 9125 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9126 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9127 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9128 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9129 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9130 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 9131 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9132 | Expr *OrigCallee, |
| 9133 | Expr *First, |
| 9134 | Expr *Second) { |
| 9135 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 9136 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9137 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9138 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9139 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9140 | if (!First->getType()->isOverloadableType() && |
| 9141 | !Second->getType()->isOverloadableType()) |
| 9142 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 9143 | Callee->getLocStart(), |
| 9144 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 9145 | } else if (Op == OO_Arrow) { |
| 9146 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9147 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 9148 | } else if (Second == 0 || isPostIncDec) { |
| 9149 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9150 | // The argument is not of overloadable type, so try to create a |
| 9151 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9152 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9153 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9154 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9155 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9156 | } |
| 9157 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9158 | if (!First->getType()->isOverloadableType() && |
| 9159 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9160 | // Neither of the arguments is an overloadable type, so try to |
| 9161 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9162 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9163 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9164 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9165 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9166 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9167 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9168 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9169 | } |
| 9170 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9171 | |
| 9172 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9173 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9174 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9175 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9176 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9177 | assert(ULE->requiresADL()); |
| 9178 | |
| 9179 | // FIXME: Do we have to check |
| 9180 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9181 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9182 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9183 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9186 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9187 | Expr *Args[2] = { First, Second }; |
| 9188 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9189 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9190 | // Create the overloaded operator invocation for unary operators. |
| 9191 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9192 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9193 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9194 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9195 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9196 | |
Douglas Gregor | 5b8968c | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 9197 | if (Op == OO_Subscript) { |
| 9198 | SourceLocation LBrace; |
| 9199 | SourceLocation RBrace; |
| 9200 | |
| 9201 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 9202 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 9203 | LBrace = SourceLocation::getFromRawEncoding( |
| 9204 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 9205 | RBrace = SourceLocation::getFromRawEncoding( |
| 9206 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 9207 | } else { |
| 9208 | LBrace = Callee->getLocStart(); |
| 9209 | RBrace = OpLoc; |
| 9210 | } |
| 9211 | |
| 9212 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 9213 | First, Second); |
| 9214 | } |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9215 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9216 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9217 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9218 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9219 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 9220 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9221 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9222 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9223 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9225 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9226 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9227 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9228 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9229 | SourceLocation OperatorLoc, |
| 9230 | bool isArrow, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9231 | CXXScopeSpec &SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9232 | TypeSourceInfo *ScopeType, |
| 9233 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9234 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9235 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9236 | QualType BaseType = Base->getType(); |
| 9237 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9238 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9239 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 9240 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 9241 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9242 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9243 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9244 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9245 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9246 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9247 | /*FIXME?*/true); |
| 9248 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9249 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9250 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9251 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 9252 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 9253 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 9254 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 9255 | |
Richard Smith | 6314db9 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 9256 | // The scope type is now known to be a valid nested name specifier |
| 9257 | // component. Tack it on to the end of the nested name specifier. |
| 9258 | if (ScopeType) |
| 9259 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 9260 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9261 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9262 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9263 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9264 | OperatorLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9265 | SS, TemplateKWLoc, |
| 9266 | /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9267 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9268 | /*TemplateArgs*/ 0); |
| 9269 | } |
| 9270 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9271 | } // end namespace clang |
| 9272 | |
| 9273 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |